vm: restrict max invocation stack size

This commit is contained in:
Evgenii Stratonikov 2019-10-29 11:01:06 +03:00
parent 0ea7568caa
commit c7f0b7bd68
2 changed files with 42 additions and 2 deletions

View file

@ -197,6 +197,27 @@ func TestPushData4Good(t *testing.T) {
assert.Equal(t, []byte{1, 2, 3}, vm.estack.Pop().Bytes())
}
func callNTimes(n uint16) []byte {
return makeProgram(
PUSHBYTES2, Instruction(n), Instruction(n>>8), // little-endian
TOALTSTACK, DUPFROMALTSTACK,
JMPIF, 0x4, 0, RET,
FROMALTSTACK, DEC,
CALL, 0xF8, 0xFF) // -8 -> JMP to TOALTSTACK)
}
func TestInvocationLimitGood(t *testing.T) {
prog := callNTimes(MaxInvocationStackSize - 1)
v := load(prog)
runVM(t, v)
}
func TestInvocationLimitBad(t *testing.T) {
prog := callNTimes(MaxInvocationStackSize)
v := load(prog)
checkVMFailed(t, v)
}
func TestNOTNoArgument(t *testing.T) {
prog := makeProgram(NOT)
vm := load(prog)