Skip to content

Commit d98586b

Browse files
committed
Merge branch 'PHP-8.2' into PHP-8.3
2 parents cac4290 + be7f3aa commit d98586b

File tree

3 files changed

+38
-0
lines changed

3 files changed

+38
-0
lines changed

NEWS

+2
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ PHP NEWS
66
. Fixed bug GH-14315 (Incompatible pointer type warnings). (Peter Kokot)
77
. Fixed bug GH-12814 (max_execution_time reached too early on MacOS 14
88
when running on Apple Silicon). (Manuel Kress)
9+
. Fixed bug GH-14387 (Crash when stack walking in destructor of yielded from
10+
values during Generator->throw()). (Bob)
911

1012
- BCMatch:
1113
. Fixed bug (bcpowmod() with mod = -1 returns 1 when it must be 0). (Girgias)

Zend/tests/generators/gh14387.phpt

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
--TEST--
2+
GH-14387 (Crash when stack walking in destructor of yielded from values during Generator->throw())
3+
--FILE--
4+
<?php
5+
6+
function prime(Generator $generator) {
7+
$generator->valid();
8+
}
9+
10+
$g = (function () {
11+
yield from [null, new class {
12+
function __destruct() {
13+
// Trigger a stack walk, hitting a bad frame.
14+
throw new Exception;
15+
}
16+
}];
17+
})();
18+
19+
prime($g);
20+
21+
$g->throw(new Error);
22+
23+
?>
24+
--EXPECTF--
25+
Fatal error: Uncaught Error in %s:%d
26+
Stack trace:
27+
#0 {main}
28+
29+
Next Exception in %s:%d
30+
Stack trace:
31+
#0 %s(%d): class@anonymous->__destruct()
32+
#1 [internal function]: {%s}()
33+
#2 %s(%d): Generator->throw(Object(Error))
34+
#3 {main}
35+
thrown in %s on line %d

Zend/zend_generators.c

+1
Original file line numberDiff line numberDiff line change
@@ -458,6 +458,7 @@ static void zend_generator_throw_exception(zend_generator *generator, zval *exce
458458
* to pretend the exception happened during the YIELD opcode. */
459459
EG(current_execute_data) = generator->execute_data;
460460
generator->execute_data->opline--;
461+
generator->execute_data->prev_execute_data = original_execute_data;
461462

462463
if (exception) {
463464
zend_throw_exception_object(exception);

0 commit comments

Comments
 (0)