]> granicus.if.org Git - php/commitdiff
Fixed bug #65665 (Exception not properly caught when opcache enabled)
authorXinchen Hui <laruence@php.net>
Mon, 16 Sep 2013 06:43:01 +0000 (14:43 +0800)
committerXinchen Hui <laruence@php.net>
Mon, 16 Sep 2013 06:43:01 +0000 (14:43 +0800)
NEWS
ext/opcache/Optimizer/block_pass.c
ext/opcache/tests/bug65665.phpt [new file with mode: 0644]

diff --git a/NEWS b/NEWS
index 5ec672eeda0e49f1fb99b1be7c042587eace10a6..37db7e6c40857db90fc69fe9c79dcf1893fde93a 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -17,6 +17,8 @@ PHP                                                                        NEWS
     scaling methods. (Pierre)
 
 - OPcache:
+  . Fixed bug #65665 (Exception not properly caught when opcache enabled).
+    (Laruence)
   . Fixed bug #65510 (5.5.2 crashes in _get_zval_ptr_ptr_var). (Dmitry)
 
 - SPL:
index 43ae30419fee99e43bcbc2b06626b4e0fc9d3e16..1c34cffbf76e7a7d553153c8291fe4b85d2a5c7a 100644 (file)
@@ -1283,11 +1283,15 @@ static void assemble_code_blocks(zend_cfg *cfg, zend_op_array *op_array)
 
        /* adjust exception jump targets */
        if (op_array->last_try_catch) {
-               int i;
-               for (i = 0; i< op_array->last_try_catch; i++) {
-                       op_array->try_catch_array[i].try_op = cfg->try[i]->start_opline - new_opcodes;
-                       op_array->try_catch_array[i].catch_op = cfg->catch[i]->start_opline - new_opcodes;
+               int i, j;
+               for (i = 0, j = 0; i< op_array->last_try_catch; i++) {
+                       if (cfg->try[i]->access) {
+                               op_array->try_catch_array[j].try_op = cfg->try[i]->start_opline - new_opcodes;
+                               op_array->try_catch_array[j].catch_op = cfg->catch[i]->start_opline - new_opcodes;
+                               j++;
+                       }
                }
+               op_array->last_try_catch = j;
                efree(cfg->try);
                efree(cfg->catch);
        }
diff --git a/ext/opcache/tests/bug65665.phpt b/ext/opcache/tests/bug65665.phpt
new file mode 100644 (file)
index 0000000..ac5c18d
--- /dev/null
@@ -0,0 +1,118 @@
+--TEST--
+Bug #65665 (Exception not properly caught when opcache enabled)
+--INI--
+opcache.enable=1
+opcache.enable_cli=1
+--SKIPIF--
+<?php require_once('skipif.inc'); ?>
+--FILE--
+<?php
+function foo() {
+       try
+       {
+               switch (1)
+               {
+               case 0:
+                       try
+                       {
+
+                       }
+                       catch (Exception $e)
+                       {
+
+                       }
+
+                       break;
+
+               case 1:
+                       try
+                       {
+                               throw new Exception('aaa');
+                       }
+                       catch (Exception $e)
+                       {
+                               echo "correct\n";
+                       }
+
+                       break;
+               }
+       }
+       catch (Exception $e)
+       {
+               echo "wrong\n";
+       }
+       return;
+}
+
+function foo1() {
+       try
+       {
+               switch (1)
+               {
+               case 0:
+                       try
+                       {
+
+                       }
+                       catch (Exception $e)
+                       {
+dummy:
+                               echo "ect\n";
+                       }
+
+                       break;
+
+               case 1:
+                       try
+                       {
+                               throw new Exception('aaa');
+                       }
+                       catch (Exception $e)
+                       {
+                               echo "corr";
+                               goto dummy;
+                       }
+                       break;
+               }
+       }
+       catch (Exception $e)
+       {
+               echo "wrong\n";
+       }
+       return;
+}
+
+function foo2() {
+       try
+       {
+               switch (1)
+               {
+               case 0:
+                       try
+                       {
+dummy:
+                               throw new Exception('aaa');
+                       }
+                       catch (Exception $e)
+                       {
+                               echo "correct\n";
+                       }
+
+                       break;
+
+               case 1:
+                       goto dummy;
+                       break;
+               }
+       }
+       catch (Exception $e)
+       {
+               echo "wrong\n";
+       }
+       return;
+}
+foo();foo1();foo2();
+--EXPECT--
+correct
+correct
+correct