Merge pull request #17043 from minamijoyo/check-substr-offset

Fix panic with substr interpolation function by invalid offset
This commit is contained in:
James Bardin 2018-01-05 12:25:44 -05:00 committed by GitHub
commit b002b4303b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 6 additions and 1 deletions

View File

@ -1577,7 +1577,7 @@ func interpolationFuncSubstr() ast.Function {
return nil, fmt.Errorf("length should be a non-negative integer")
}
if offset > len(str) {
if offset > len(str) || offset < 0 {
return nil, fmt.Errorf("offset cannot be larger than the length of the string")
}

View File

@ -2568,6 +2568,11 @@ func TestInterpolateFuncSubstr(t *testing.T) {
nil,
true,
},
{
`${substr("foo", -4, -1)}`,
nil,
true,
},
// invalid length
{