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:
commit
64baa309cb
1 changed files with 3 additions and 3 deletions
|
@ -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
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue