From 681ae4d5d612982a1daea8dab49d84082a96e56c Mon Sep 17 00:00:00 2001 From: Roman Khimov Date: Mon, 24 Aug 2020 16:20:57 +0300 Subject: [PATCH] vm: fix TRY offsets check TRY can have an offset != 0 and still it can't have both parameters set to zero. --- pkg/vm/vm.go | 2 +- pkg/vm/vm_test.go | 6 +++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/pkg/vm/vm.go b/pkg/vm/vm.go index 284b05f3d..6b838752f 100644 --- a/pkg/vm/vm.go +++ b/pkg/vm/vm.go @@ -1370,7 +1370,7 @@ func (v *VM) execute(ctx *Context, op opcode.Opcode, parameter []byte) (err erro } cOffset := v.getJumpOffset(ctx, catchP) fOffset := v.getJumpOffset(ctx, finallyP) - if cOffset == 0 && fOffset == 0 { + if cOffset == ctx.ip && fOffset == ctx.ip { panic("invalid offset for TRY*") } else if cOffset == ctx.ip { cOffset = -1 diff --git a/pkg/vm/vm_test.go b/pkg/vm/vm_test.go index f6403d09c..24e0a3150 100644 --- a/pkg/vm/vm_test.go +++ b/pkg/vm/vm_test.go @@ -1296,7 +1296,11 @@ func TestTRY(t *testing.T) { add5 := []byte{byte(opcode.PUSH5), byte(opcode.ADD)} add9 := []byte{byte(opcode.PUSH9), byte(opcode.ADD)} t.Run("NoCatch", func(t *testing.T) { - t.Run("NoFinally", getTRYTestFunc(nil, push1, nil, nil)) + t.Run("NoFinally", func(t *testing.T) { + prog := getTRYProgram(push1, nil, nil) + vm := load(prog) + checkVMFailed(t, vm) + }) t.Run("WithFinally", getTRYTestFunc(10, push1, nil, add9)) t.Run("Throw", getTRYTestFunc(nil, throw, nil, add9)) })