]> granicus.if.org Git - php/commitdiff
Fixed bug #73350 (Exception::__toString() cause circular references)
authorXinchen Hui <laruence@gmail.com>
Sat, 22 Oct 2016 06:50:21 +0000 (14:50 +0800)
committerXinchen Hui <laruence@gmail.com>
Sat, 22 Oct 2016 06:50:21 +0000 (14:50 +0800)
NEWS
Zend/tests/bug73156.phpt
Zend/tests/bug73350.phpt [new file with mode: 0644]
Zend/zend_exceptions.c

diff --git a/NEWS b/NEWS
index f5a2424753903c48a00d766a0d9d71cd2e944332..c1f142af817ac04b968babe5d75c58812ca6a069 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -3,6 +3,8 @@ PHP                                                                        NEWS
 ?? ??? 2016 PHP 7.0.13
 
 - Core:
+  . Fixed bug #73350 (Exception::__toString() cause circular references).
+    (Laruence)
   . Fixed bug #73181 (parse_str() without a second argument leads to crash).
     (Nikita)
   . Fixed bug #66773 (Autoload with Opcache allows importing conflicting class
index b5092514a03fdf8e272bd8b1cf3bae3e1dda5bc8..327ad9e4310cda837833c771bd8a791841219e36 100644 (file)
@@ -1,5 +1,5 @@
 --TEST--
-iBug #73156 (segfault on undefined function)
+Bug #73156 (segfault on undefined function)
 --FILE--
 <?php
 class A {
diff --git a/Zend/tests/bug73350.phpt b/Zend/tests/bug73350.phpt
new file mode 100644 (file)
index 0000000..7505884
--- /dev/null
@@ -0,0 +1,27 @@
+--TEST--
+Bug #73350 (Exception::__toString() cause circular references)
+--FILE--
+<?php
+$e = new Exception();
+
+// This line cause problem :(
+// Comment it to see the difference.
+(string) $e;
+
+// This line show the clue (PHP Warning: ...).
+var_export($e);
+?>
+--EXPECTF--
+Exception::__set_state(array(
+   'message' => '',
+   'string' => 'Exception in %sbug73350.php:%d
+Stack trace:
+#0 {main}',
+   'code' => 0,
+   'file' => '%sbug73350.php',
+   'line' => %d,
+   'trace' => 
+  array (
+  ),
+   'previous' => NULL,
+))
index 89c94eb56f3e844212169e25547fe9429e16a5ac..e0aa370bfe02f54d7223ceca56b709035d3be7ba 100644 (file)
@@ -776,14 +776,15 @@ ZEND_METHOD(exception, __toString)
                Z_OBJPROP_P(exception)->u.v.nApplyCount++;
                exception = GET_PROPERTY(exception, "previous");
                if (exception && Z_TYPE_P(exception) == IS_OBJECT && Z_OBJPROP_P(exception)->u.v.nApplyCount > 0) {
-                       exception = NULL;
+                       break;
                }
        }
        zval_dtor(&fname);
 
+       exception = getThis();
        /* Reset apply counts */
        while (exception && Z_TYPE_P(exception) == IS_OBJECT && (base_ce = i_get_exception_base(exception)) && instanceof_function(Z_OBJCE_P(exception), base_ce)) {
-               if(Z_OBJPROP_P(exception)->u.v.nApplyCount) {
+               if (Z_OBJPROP_P(exception)->u.v.nApplyCount) {
                        Z_OBJPROP_P(exception)->u.v.nApplyCount--;
                } else {
                        break;