Merge pull request #2396 from nspcc-dev/fuzz-script-panic

Return error on negative instruction pointer in `Context.Next`
This commit is contained in:
Roman Khimov 2022-03-17 19:13:20 +03:00 committed by GitHub
commit df3eb76aa2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 0 deletions

View file

@ -95,6 +95,9 @@ func (c *Context) Next() (opcode.Opcode, []byte, error) {
var err error
c.ip = c.nextip
if c.ip < 0 {
return 0, nil, errors.New("invalid instruction offset")
}
if c.ip >= len(c.prog) {
return opcode.RET, nil, nil
}

View file

@ -1385,6 +1385,17 @@ func TestKEYS(t *testing.T) {
t.Run("WrongType", getTestFuncForVM(prog, nil, []stackitem.Item{}))
}
func TestTry_ENDFINALLY_before_ENDTRY(t *testing.T) {
prog := makeProgram(opcode.TRY, 0, 3, opcode.ENDFINALLY)
require.NoError(t, IsScriptCorrect(prog, nil))
v := load(prog)
var err error
require.NotPanics(t, func() { err = v.Run() })
require.Error(t, err)
}
func TestVALUESMap(t *testing.T) {
prog := makeProgram(opcode.VALUES)
vm := load(prog)