Merge pull request #2475 from nspcc-dev/vm/fix-jump

vm: check instruction offset is valid before subsequent IP move
This commit is contained in:
Roman Khimov 2022-05-12 10:04:04 +03:00 committed by GitHub
commit 64baa309cb
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -85,6 +85,9 @@ func (c *Context) NextIP() int {
// Jump unconditionally moves the next instruction pointer to the specified location.
func (c *Context) Jump(pos int) {
if pos < 0 || pos > len(c.prog) {
panic("instruction offset is out of range")
}
c.nextip = pos
}
@ -95,9 +98,6 @@ 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
}