Skip to content

Commit f58ebb3

Browse files
committed
Load/restore VM stack before unfinished generator cleanup
1 parent ffe0f47 commit f58ebb3

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

Zend/zend_generators.c

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,23 @@ static void zend_generator_cleanup_unfinished_execution(zend_generator *generato
4242
generator->send_target = NULL;
4343
}
4444

45-
zend_cleanup_unfinished_execution(execute_data, op_num, 0);
45+
{
46+
/* There may be calls to zend_vm_stack_free_call_frame(), which modifies the VM stack
47+
* globals, so need to load/restore those. */
48+
zend_vm_stack original_stack = EG(vm_stack);
49+
original_stack->top = EG(vm_stack_top);
50+
EG(vm_stack_top) = generator->stack->top;
51+
EG(vm_stack_end) = generator->stack->end;
52+
EG(vm_stack) = generator->stack;
53+
54+
zend_cleanup_unfinished_execution(execute_data, op_num, 0);
55+
56+
generator->stack = EG(vm_stack);
57+
generator->stack->top = EG(vm_stack_top);
58+
EG(vm_stack_top) = original_stack->top;
59+
EG(vm_stack_end) = original_stack->end;
60+
EG(vm_stack) = original_stack;
61+
}
4662
}
4763
/* }}} */
4864

0 commit comments

Comments
 (0)