summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNikita Popov <nikita.ppv@gmail.com>2020-08-31 10:51:00 +0200
committerNikita Popov <nikita.ppv@gmail.com>2020-08-31 10:51:31 +0200
commitad750c3bb6e7b48384c6265eb9d3bcf5b4000652 (patch)
treea4b941ba7f558f7efd1d3e97f22ffccc705f73c1
parent376bbbdf3b6b0ec08102c3ccb31746c2a7d9bdd6 (diff)
downloadphp-git-ad750c3bb6e7b48384c6265eb9d3bcf5b4000652.tar.gz
Fix handling of exception if valid() during yield from
Fixes oss-fuzz #25296.
-rw-r--r--Zend/tests/generators/yield_from_valid_exception.phpt29
-rw-r--r--Zend/zend_generators.c3
2 files changed, 32 insertions, 0 deletions
diff --git a/Zend/tests/generators/yield_from_valid_exception.phpt b/Zend/tests/generators/yield_from_valid_exception.phpt
new file mode 100644
index 0000000000..3af35f53af
--- /dev/null
+++ b/Zend/tests/generators/yield_from_valid_exception.phpt
@@ -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()
diff --git a/Zend/zend_generators.c b/Zend/zend_generators.c
index 4ccb57907f..bb3260b11b 100644
--- a/Zend/zend_generators.c
+++ b/Zend/zend_generators.c
@@ -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;
}