Skip to content

Commit

Permalink
Fix handling of exception if valid() during yield from
Browse files Browse the repository at this point in the history
Fixes oss-fuzz #25296.
  • Loading branch information
nikic committed Aug 31, 2020
1 parent 376bbbd commit ad750c3
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
29 changes: 29 additions & 0 deletions Zend/tests/generators/yield_from_valid_exception.phpt
Original file line number Diff line number Diff line change
@@ -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()
3 changes: 3 additions & 0 deletions Zend/zend_generators.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down

0 comments on commit ad750c3

Please sign in to comment.