Fix handling of exception if valid() during yield from

Fixes oss-fuzz #25296.
This commit is contained in:
Nikita Popov 2020-08-31 10:51:00 +02:00
parent 376bbbdf3b
commit ad750c3bb6
2 changed files with 32 additions and 0 deletions

View File

@ -0,0 +1,29 @@
--TEST--
Exception from valid() during yield from
--FILE--
<?php
class FooBar implements Iterator {
function rewind() {}
function current() {}
function key() {}
function next() {}
function valid() {
throw new Exception("Exception from valid()");
}
}
function gen() {
try {
yield from new FooBar;
} catch (Exception $e) {
echo $e->getMessage(), "\n";
}
}
$x = gen();
$x->current();
?>
--EXPECT--
Exception from valid()

View File

@ -709,6 +709,9 @@ static int zend_generator_get_next_delegated_value(zend_generator *generator) /*
}
if (iter->funcs->valid(iter) == FAILURE) {
if (UNEXPECTED(EG(exception) != NULL)) {
goto exception;
}
/* reached end of iteration */
goto failure;
}