mirror of
https://github.com/nspcc-dev/neo-go.git
synced 2024-12-23 03:41:34 +00:00
vm: properly clear try stack in CALL
Signed-off-by: Evgeniy Stratonikov <evgeniy@nspcc.ru>
This commit is contained in:
parent
01022c78e4
commit
10d006195a
2 changed files with 19 additions and 0 deletions
|
@ -1594,6 +1594,9 @@ func (v *VM) call(ctx *Context, offset int) {
|
|||
newCtx.retCount = -1
|
||||
newCtx.local = nil
|
||||
newCtx.arguments = nil
|
||||
// If memory for `elems` is reused, we can end up
|
||||
// with incorrect exception context state in the caller.
|
||||
newCtx.tryStack.elems = nil
|
||||
initStack(&newCtx.tryStack, "exception", nil)
|
||||
newCtx.NEF = ctx.NEF
|
||||
v.istack.PushItem(newCtx)
|
||||
|
|
|
@ -1027,6 +1027,22 @@ func TestTRY(t *testing.T) {
|
|||
// add 5 to the exception, mul to the result of inner finally (2)
|
||||
getTRYTestFunc(47, inner, append(add5, byte(opcode.MUL)), add9)(t)
|
||||
})
|
||||
t.Run("nested, in throw and catch in call", func(t *testing.T) {
|
||||
catchP := []byte{byte(opcode.PUSH10), byte(opcode.ADD)}
|
||||
inner := getTRYProgram(throw, catchP, []byte{byte(opcode.PUSH2)})
|
||||
outer := getTRYProgram([]byte{byte(opcode.CALL), 0}, []byte{byte(opcode.PUSH3)}, []byte{byte(opcode.PUSH4)})
|
||||
outer = append(outer, byte(opcode.RET))
|
||||
outer[4] = byte(len(outer) - 3) // CALL argument at 3 (TRY) + 1 (CALL opcode)
|
||||
outer = append(outer, inner...)
|
||||
outer = append(outer, byte(opcode.RET))
|
||||
|
||||
v := load(outer)
|
||||
runVM(t, v)
|
||||
require.Equal(t, 3, v.Estack().Len())
|
||||
require.Equal(t, big.NewInt(4), v.Estack().Pop().Value()) // outer FINALLY
|
||||
require.Equal(t, big.NewInt(2), v.Estack().Pop().Value()) // inner FINALLY
|
||||
require.Equal(t, big.NewInt(23), v.Estack().Pop().Value()) // inner THROW + CATCH
|
||||
})
|
||||
}
|
||||
|
||||
func TestMEMCPY(t *testing.T) {
|
||||
|
|
Loading…
Reference in a new issue