Skip to content

Commit

Permalink
add non-negative check in second parameter for subStr
Browse files Browse the repository at this point in the history
  • Loading branch information
jdockerty authored and sbarzowski committed Mar 18, 2022
1 parent f0a060e commit 9e9321f
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions builtins.go
Original file line number Diff line number Diff line change
Expand Up @@ -991,6 +991,11 @@ func builtinSubstr(i *interpreter, inputStr, inputFrom, inputLen value) (value,
return nil, makeRuntimeError(msg, i.getCurrentStackTrace())
}

if fromV.value < 0 {
msg := fmt.Sprintf("substr second parameter should be greater than zero, got %f", fromV.value)
return nil, makeRuntimeError(msg, i.getCurrentStackTrace())
}

lenV, err := i.getNumber(inputLen)
if err != nil {
msg := fmt.Sprintf("substr third parameter should be a number, got %s", inputLen.getType().name)
Expand Down

0 comments on commit 9e9321f

Please sign in to comment.