vm: fail if XTUCK argument is 0

This commit is contained in:
Evgenii Stratonikov 2019-09-12 10:39:54 +03:00
parent b21a220712
commit d257044298
2 changed files with 10 additions and 1 deletions

View file

@ -375,7 +375,7 @@ func (v *VM) execute(ctx *Context, op Instruction) {
case XTUCK:
n := int(v.estack.Pop().BigInt().Int64())
if n < 0 {
if n <= 0 {
panic("XTUCK: invalid length")
}
a := v.estack.Dup(0)

View file

@ -658,6 +658,15 @@ func TestXTUCKbadNegative(t *testing.T) {
assert.Equal(t, true, vm.state.HasFlag(faultState))
}
func TestXTUCKbadZero(t *testing.T) {
prog := makeProgram(XTUCK)
vm := load(prog)
vm.estack.PushVal(1)
vm.estack.PushVal(0)
vm.Run()
assert.Equal(t, true, vm.state.HasFlag(faultState))
}
func TestXTUCKgood(t *testing.T) {
prog := makeProgram(XTUCK)
topelement := 5