Skip to content

Commit

Permalink
Fix throwing of yield from related exceptions into generator
Browse files Browse the repository at this point in the history
Use the general zend_generator_throw_exception() helper for this.
Otherwise we don't handle the off-by-one opline correctly (should
we maybe just stop doing that?)

This is a followup to ad750c3,
which fixed a different yield from exception handling problem that
happened to show up in the same test case from oss-fuzz #25321.
Now both issues should be fixed.
  • Loading branch information
nikic committed Sep 2, 2020
1 parent a07c1f5 commit 2e9e706
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
3 changes: 2 additions & 1 deletion Zend/tests/generators/yield_from_valid_exception.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ class FooBar implements Iterator {

function gen() {
try {
yield from new FooBar;
// the fact that the yield from result is used is relevant.
var_dump(yield from new FooBar);
} catch (Exception $e) {
echo $e->getMessage(), "\n";
}
Expand Down
2 changes: 1 addition & 1 deletion Zend/zend_generators.c
Original file line number Diff line number Diff line change
Expand Up @@ -740,7 +740,7 @@ static int zend_generator_get_next_delegated_value(zend_generator *generator) /*
return SUCCESS;

exception:
zend_rethrow_exception(generator->execute_data);
zend_generator_throw_exception(generator, NULL);

failure:
zval_ptr_dtor(&generator->values);
Expand Down

0 comments on commit 2e9e706

Please sign in to comment.