]> granicus.if.org Git - php/commitdiff
Fixed bug #74606 (Segfault within try/catch/finally nesting in Generators)
authorBob Weinand <bobwei9@hotmail.com>
Wed, 17 May 2017 17:56:49 +0000 (19:56 +0200)
committerBob Weinand <bobwei9@hotmail.com>
Wed, 17 May 2017 17:58:51 +0000 (19:58 +0200)
Thanks to Nikita for pointing out the error source.

NEWS
Zend/tests/generators/bug74606.phpt [new file with mode: 0644]
Zend/zend_generators.c

diff --git a/NEWS b/NEWS
index fcc0f40bafd42ff12c68cc6df6900ace1baf7437..e5cafc9329f9057f70be45ed3dbceba582cfbbfe 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -6,6 +6,8 @@ PHP                                                                        NEWS
   . Fixed bug #74546 (SIGILL in ZEND_FETCH_CLASS_CONSTANT_SPEC_CONST_CONST).
     (Laruence)
   . Fixed bug #74589 (__DIR__ wrong for unicode character). (Anatol)
+  . Fixed bug #74606 (Segfault within try/catch/finally nesting in Generators).
+    (Bob, Nikita)
 
 - intl:
   . Fixed bug #74468 (wrong reflection on Collator::sortWithSortKeys). (villfa)
diff --git a/Zend/tests/generators/bug74606.phpt b/Zend/tests/generators/bug74606.phpt
new file mode 100644 (file)
index 0000000..cfb7f7f
--- /dev/null
@@ -0,0 +1,29 @@
+--TEST--
+Bug #74606 (Segfault within try/catch/finally nesting in Generators)
+--FILE--
+<?php
+
+function gen() {
+       $array = ["foo"];
+       $array[] = "bar";
+
+       foreach ($array as $item) {
+               try {
+                       try {
+                               yield;
+                       } finally {
+                               echo "fin $item\n";
+                       }
+               } catch (\Exception $e) {
+                       echo "catch\n";
+                       continue;
+               }
+       }
+}
+gen()->throw(new Exception);
+
+?>
+--EXPECT--
+fin foo
+catch
+fin bar
index 945c3615edc25e533a9222b07ba6907e4748f77f..99145ada717cae96cc88253727aa4885280bfa27 100644 (file)
@@ -108,7 +108,7 @@ static void zend_generator_cleanup_unfinished_execution(
                if (UNEXPECTED(generator->frozen_call_stack)) {
                        zend_generator_restore_call_stack(generator);
                }
-               zend_cleanup_unfinished_execution(execute_data, op_num, 0);
+               zend_cleanup_unfinished_execution(execute_data, op_num, catch_op_num);
        }
 }
 /* }}} */