Skip to content

Commit 0f36224

Browse files
committed
Don't try to clean up generator stack on unclean shutdown
This fixes bugs #65035 and #65161. In one of the bugs the issue is that function_state.arguments is NULL, but the arg count is pushed to the stack and the code tries to free it. In the other bug the stack of the generator is freed twice, once in generator_close and later during shutdown. It's rather hard (if at all possible) to do a proper stack cleanup on an unclean shutdown, so I'm just disabling it in this case.
1 parent 5904da9 commit 0f36224

File tree

4 files changed

+48
-0
lines changed

4 files changed

+48
-0
lines changed

NEWS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ PHP NEWS
77
(Adam)
88
. Fixed bug #65108 (is_callable() triggers Fatal Error).
99
(David Soria Parra, Laruence)
10+
. Fixed bug #65035 (yield / exit segfault). (Nikita)
11+
. Fixed bug #65161 (Generator + autoload + syntax error = segfault). (Nikita)
1012

1113
- OPcache
1214
. Fixed bug #64827 (Segfault in zval_mark_grey (zend_gc.c)). (Laruence)

Zend/tests/generators/bug65035.phpt

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
--TEST--
2+
Bug #65035: yield / exit segfault
3+
--FILE--
4+
<?php
5+
6+
function gen() {
7+
fn();
8+
yield;
9+
}
10+
11+
function fn() {
12+
exit('Done');
13+
}
14+
15+
$gen = gen();
16+
$gen->current();
17+
18+
?>
19+
--EXPECT--
20+
Done

Zend/tests/generators/bug65161.phpt

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
--TEST--
2+
Bug #65161: Generator + autoload + syntax error = segfault
3+
--FILE--
4+
<?php
5+
6+
function autoload() {
7+
foo();
8+
}
9+
spl_autoload_register('autoload');
10+
11+
function testGenerator() {
12+
new SyntaxError('param');
13+
yield;
14+
}
15+
16+
foreach (testGenerator() as $i);
17+
18+
?>
19+
--EXPECTF--
20+
Fatal error: Call to undefined function foo() in %s on line %d

Zend/zend_generators.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,12 @@ ZEND_API void zend_generator_close(zend_generator *generator, zend_bool finished
5555
zval_ptr_dtor(&execute_data->current_this);
5656
}
5757

58+
/* A fatal error / die occured during the generator execution. Trying to clean
59+
* up the stack may not be safe in this case. */
60+
if (CG(unclean_shutdown)) {
61+
return;
62+
}
63+
5864
/* If the generator is closed before it can finish execution (reach
5965
* a return statement) we have to free loop variables manually, as
6066
* we don't know whether the SWITCH_FREE / FREE opcodes have run */

0 commit comments

Comments
 (0)