Skip to content

Commit 41a249f

Browse files
committed
Fix bug #68775
1 parent 32f761d commit 41a249f

File tree

2 files changed

+22
-3
lines changed

2 files changed

+22
-3
lines changed

Zend/tests/bug68775.phpt

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
--TEST--
2+
Bug #68775: yield in a function argument crashes or loops indefinitely
3+
--FILE--
4+
<?php
5+
6+
function a($x) {
7+
var_dump($x);
8+
}
9+
10+
function gen() {
11+
a(yield);
12+
}
13+
14+
$g = gen();
15+
$g->send(1);
16+
17+
?>
18+
--EXPECT--
19+
int(1)

Zend/zend_generators.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -303,8 +303,8 @@ ZEND_API void zend_generator_resume(zend_generator *generator) /* {{{ */
303303
zend_execute_data *original_execute_data = EG(current_execute_data);
304304
zend_class_entry *original_scope = EG(scope);
305305
zend_vm_stack original_stack = EG(vm_stack);
306-
307306
original_stack->top = EG(vm_stack_top);
307+
308308
/* Set executor globals */
309309
EG(current_execute_data) = generator->execute_data;
310310
EG(scope) = generator->execute_data->func->common.scope;
@@ -314,8 +314,7 @@ ZEND_API void zend_generator_resume(zend_generator *generator) /* {{{ */
314314

315315
/* We want the backtrace to look as if the generator function was
316316
* called from whatever method we are current running (e.g. next()).
317-
* So we have to link generator call frame with caller call frames */
318-
317+
* So we have to link generator call frame with caller call frame. */
319318
generator->execute_data->prev_execute_data = original_execute_data;
320319

321320
/* Resume execution */
@@ -329,6 +328,7 @@ ZEND_API void zend_generator_resume(zend_generator *generator) /* {{{ */
329328
}
330329

331330
/* Restore executor globals */
331+
generator->stack->top = EG(vm_stack_top);
332332
EG(current_execute_data) = original_execute_data;
333333
EG(scope) = original_scope;
334334
EG(vm_stack_top) = original_stack->top;

0 commit comments

Comments
 (0)