Skip to content

Commit ff8da0b

Browse files
committed
vm: Detect stack underflow in addition to overflow.
1 parent ae9c82d commit ff8da0b

1 file changed

Lines changed: 7 additions & 0 deletions

File tree

py/vm.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,13 @@ mp_vm_return_kind_t mp_execute_bytecode(const byte *code, const mp_obj_t *args,
158158
mp_vm_return_kind_t vm_return_kind = mp_execute_bytecode2(code, &ip, &state[n_state - 1], &sp, exc_stack, &exc_sp, MP_OBJ_NULL);
159159

160160
#if DETECT_VM_STACK_OVERFLOW
161+
if (vm_return_kind == MP_VM_RETURN_NORMAL) {
162+
if (sp != state) {
163+
printf("Stack misalign: %d\n", sp - state);
164+
assert(0);
165+
}
166+
}
167+
161168
// We can't check the case when an exception is returned in state[n_state - 1]
162169
// and there are no arguments, because in this case our detection slot may have
163170
// been overwritten by the returned exception (which is allowed).

0 commit comments

Comments
 (0)