vm: fail if DROP has no argument

This commit is contained in:
Evgenii Stratonikov 2019-09-12 11:05:10 +03:00
parent 729b7a0b24
commit 6e4014547d
2 changed files with 19 additions and 0 deletions

View file

@ -439,6 +439,9 @@ func (v *VM) execute(ctx *Context, op Instruction) {
}
case DROP:
if v.estack.Len() < 1 {
panic("stack is too small")
}
v.estack.Pop()
case EQUAL:

View file

@ -803,6 +803,22 @@ func TestOVERgood(t *testing.T) {
assert.Equal(t, 3, vm.estack.Len())
}
func TestDROPBadNoItem(t *testing.T) {
prog := makeProgram(DROP)
vm := load(prog)
vm.Run()
assert.Equal(t, true, vm.state.HasFlag(faultState))
}
func TestDROPGood(t *testing.T) {
prog := makeProgram(DROP)
vm := load(prog)
vm.estack.PushVal(1)
vm.Run()
assert.Equal(t, false, vm.state.HasFlag(faultState))
assert.Equal(t, 0, vm.estack.Len())
}
func TestXDROPbadNoitem(t *testing.T) {
prog := makeProgram(XDROP)
vm := load(prog)