Skip to content

Commit ad62706

Browse files
Fixed integer overflow issue
1 parent 41de21a commit ad62706

File tree

3 files changed

+24
-20
lines changed

3 files changed

+24
-20
lines changed

apps/st2-actions/actions-details.component.js

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,16 @@ export default class ActionsDetails extends React.Component {
199199
if(value < 0 || value > 2492000){
200200
return true
201201
}
202+
}
202203

204+
isValidInt(value){
205+
for (var n = 0; n < value.length; n++) {
206+
var digit = (value.charCodeAt(n) >= 48 && value.charCodeAt(n) <= 57) || value.charCodeAt(n) == 8;
207+
if(!digit){
208+
return true
209+
}
210+
}
211+
return false
203212
}
204213

205214
handleSection(section) {
@@ -228,7 +237,6 @@ export default class ActionsDetails extends React.Component {
228237
}
229238
handleRun(e, ...args) {
230239
e.preventDefault();
231-
232240
return this.props.handleRun(...args);
233241
}
234242

@@ -262,8 +270,10 @@ export default class ActionsDetails extends React.Component {
262270
<DetailsToolbar key="toolbar">
263271
<Button disabled={
264272
(this.state.runValue && this.state.runValue.timeout && this.minMax(this.state.runValue.timeout)) ||
265-
(this.state.runValue && this.state.runValue.limit && this.minMax(this.state.runValue.limit))
266-
}
273+
(this.state.runValue && this.state.runValue.limit && this.minMax(this.state.runValue.limit)) ||
274+
(this.state.runValue && this.state.runValue.timeout && this.isValidInt(this.state.runValue.timeout)) ||
275+
(this.state.runValue && this.state.runValue.limit && this.isValidInt(this.state.runValue.limit))
276+
}
267277
value="Run" data-test="run_submit" onClick={(e) => this.handleRun(e, action.ref, this.state.runValue, this.state.runTrace || undefined)} />
268278
<Button flat value="Preview" onClick={() => this.handleToggleRunPreview()} />
269279
<DetailsToolbarSeparator />

modules/st2-auto-form/fields/base.js

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -89,19 +89,6 @@ export class BaseTextField extends React.Component {
8989
const invalid = this.validate(value, this.props.spec);
9090

9191
if(this.props.name === "timeout" || this.props.name === "limit"){
92-
var status = true;
93-
if(invalid) {
94-
status = false
95-
}
96-
for (var n = 0; n < value.length; n++) {
97-
var digit = (value.charCodeAt(n) >= 48 && value.charCodeAt(n) <= 57) || value.charCodeAt(n) == 8;
98-
if(!digit){
99-
value = value.replace(/\D/g, "");
100-
}else{
101-
102-
value = value
103-
}
104-
}
10592
this.setState({ value, invalid }, this.props.onChange ? this.emitChange : undefined);
10693
} else{
10794
this.setState({ value, invalid }, this.props.onChange && !invalid ? this.emitChange : undefined);

modules/st2-auto-form/fields/integer.js

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,11 @@ export default class IntegerField extends BaseTextField {
2424
return v;
2525
}
2626

27-
return v !== '' ? validator.toInt(v, 10) : void 0;
27+
if(this.props.name === 'timeout' || this.props.name === "limit"){
28+
return v
29+
}else{
30+
return v !== '' ? validator.toInt(v, 10) : void 0;
31+
}
2832
}
2933

3034
toStateValue(v) {
@@ -43,12 +47,15 @@ export default class IntegerField extends BaseTextField {
4347

4448
if(spec._name === "timeout" || spec._name === "limit"){
4549
for (var n = 0; n < v.length; n++) {
46-
var digit = (v.charCodeAt(n) >= 48 && v.charCodeAt(n) <= 57) || v.charCodeAt(n) == 8;
50+
var digit = (v.charCodeAt(n) >= 48 && v.charCodeAt(n) <= 57) || v.charCodeAt(n) == 45 || v.charCodeAt(n) == 8;
4751
if(!digit){
4852
return `'${v}'is non integer value`
4953
}else{
50-
if(v > 2492000){
51-
return `Entered value is not in valid range`
54+
if(v < 0){
55+
return `Entered value should be Min 0`
56+
}
57+
else if(v > 2492000){
58+
return `Entered value should be Max 2492000`
5259
}else{
5360
v = v
5461
}

0 commit comments

Comments
 (0)