]> granicus.if.org Git - php/commitdiff
Load/restore VM stack before unfinished generator cleanup
authorNikita Popov <nikic@php.net>
Sat, 20 Jun 2015 17:09:07 +0000 (19:09 +0200)
committerNikita Popov <nikic@php.net>
Sat, 20 Jun 2015 17:09:25 +0000 (19:09 +0200)
Zend/zend_generators.c

index fea3a2f50ed01069abd97169132c0365fe4db104..6a04ebd123b8fd0cf12c3f5046f2e57582956d4f 100644 (file)
@@ -42,7 +42,23 @@ static void zend_generator_cleanup_unfinished_execution(zend_generator *generato
                generator->send_target = NULL;
        }
 
-       zend_cleanup_unfinished_execution(execute_data, op_num, 0);
+       {
+               /* There may be calls to zend_vm_stack_free_call_frame(), which modifies the VM stack
+                * globals, so need to load/restore those. */
+               zend_vm_stack original_stack = EG(vm_stack);
+               original_stack->top = EG(vm_stack_top);
+               EG(vm_stack_top) = generator->stack->top;
+               EG(vm_stack_end) = generator->stack->end;
+               EG(vm_stack) = generator->stack;
+
+               zend_cleanup_unfinished_execution(execute_data, op_num, 0);
+
+               generator->stack = EG(vm_stack);
+               generator->stack->top = EG(vm_stack_top);
+               EG(vm_stack_top) = original_stack->top;
+               EG(vm_stack_end) = original_stack->end;
+               EG(vm_stack) = original_stack;
+       }
 }
 /* }}} */