From 9e9321f69ae1554de722f2a478f3fbca240f862a Mon Sep 17 00:00:00 2001 From: Jack Dockerty Date: Wed, 16 Mar 2022 16:17:56 +0000 Subject: [PATCH] add non-negative check in second parameter for subStr --- builtins.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/builtins.go b/builtins.go index 22b776f6..3e0ed36f 100644 --- a/builtins.go +++ b/builtins.go @@ -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)