Skip to content

Commit ad750c3

Browse files
committed
Fix handling of exception if valid() during yield from
Fixes oss-fuzz #25296.
1 parent 376bbbd commit ad750c3

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
--TEST--
2+
Exception from valid() during yield from
3+
--FILE--
4+
<?php
5+
6+
class FooBar implements Iterator {
7+
function rewind() {}
8+
function current() {}
9+
function key() {}
10+
function next() {}
11+
function valid() {
12+
throw new Exception("Exception from valid()");
13+
}
14+
}
15+
16+
function gen() {
17+
try {
18+
yield from new FooBar;
19+
} catch (Exception $e) {
20+
echo $e->getMessage(), "\n";
21+
}
22+
}
23+
24+
$x = gen();
25+
$x->current();
26+
27+
?>
28+
--EXPECT--
29+
Exception from valid()

Zend/zend_generators.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -709,6 +709,9 @@ static int zend_generator_get_next_delegated_value(zend_generator *generator) /*
709709
}
710710

711711
if (iter->funcs->valid(iter) == FAILURE) {
712+
if (UNEXPECTED(EG(exception) != NULL)) {
713+
goto exception;
714+
}
712715
/* reached end of iteration */
713716
goto failure;
714717
}

0 commit comments

Comments
 (0)