]> granicus.if.org Git - php/commitdiff
Fix throwing of yield from related exceptions into generator
authorNikita Popov <nikita.ppv@gmail.com>
Wed, 2 Sep 2020 08:50:14 +0000 (10:50 +0200)
committerNikita Popov <nikita.ppv@gmail.com>
Wed, 2 Sep 2020 08:52:55 +0000 (10:52 +0200)
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 ad750c3bb6e7b48384c6265eb9d3bcf5b4000652,
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.

Zend/tests/generators/yield_from_valid_exception.phpt
Zend/zend_generators.c

index 3af35f53af66885001717621fbea29e37219fc2a..d3e054bfafb9d854de52942785a05169d9d535da 100644 (file)
@@ -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";
     }
index bb3260b11bfff164d9ef57464ae23944306d6c27..0ed92f4ca28cb870fd6bfa2c7ff361768f334058 100644 (file)
@@ -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);