com php-src: Improved fix for bug #70944: Zend/tests/bug70944.phpt Zend/zend_exceptions.c
| From: | Xinchen Hui | Date: | Sat, 21 Nov 2015 08:27:56 +0000 |
| Subject: | com php-src: Improved fix for bug #70944: Zend/tests/bug70944.phpt Zend/zend_exceptions.c | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-89946@lists.php.net to get a copy of this message | ||
Commit: 7b195c9875efa53204a302ad8aae54af4bb6158e
Author: Xinchen Hui <laruence@gmail.com> Sat, 21 Nov 2015 00:27:56 -0800
Parents: a1c887964e34c0531b238e33a6b85e9925731194
Branches: PHP-5.6
Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=7b195c9875efa53204a302ad8aae54af4bb6158e
Log:
Improved fix for bug #70944
Bugs:
https://bugs.php.net/70944
Changed paths:
M Zend/tests/bug70944.phpt
M Zend/zend_exceptions.c
Diff:
diff --git a/Zend/tests/bug70944.phpt b/Zend/tests/bug70944.phpt
index d189d9e..7584384 100644
--- a/Zend/tests/bug70944.phpt
+++ b/Zend/tests/bug70944.phpt
@@ -2,15 +2,28 @@
Bug #70944 (try{ } finally{} can create infinite chains of exceptions)
--FILE--
<?php
-$e = new Exception("Bar");
try {
- throw new Exception("Foo", 0, $e);
-} finally {
- throw $e;
+ $e = new Exception("Foo");
+ try {
+ throw new Exception("Bar", 0, $e);
+ } finally {
+ throw $e;
+ }
+} catch (Exception $e) {
+ var_dump($e->getMessage());
+}
+
+try {
+ $e = new Exception("Foo");
+ try {
+ throw new Exception("Bar", 0, $e);
+ } finally {
+ throw new Exception("Dummy", 0, $e);
+ }
+} catch (Exception $e) {
+ var_dump($e->getMessage());
}
?>
---EXPECTF--
-Fatal error: Uncaught exception 'Exception' with message 'Bar' in
%sbug70944.php:%d
-Stack trace:
-#0 {main}
- thrown in %sbug70944.php on line %d
+--EXPECT--
+string(3) "Foo"
+string(5) "Dummy"
diff --git a/Zend/zend_exceptions.c b/Zend/zend_exceptions.c
index d1aa6fe..4b38829 100644
--- a/Zend/zend_exceptions.c
+++ b/Zend/zend_exceptions.c
@@ -45,14 +45,15 @@ void zend_exception_set_previous(zval *exception, zval *add_previous TSRMLS_DC)
zend_error(E_ERROR, "Cannot set non exception as previous exception");
return;
}
- ancestor = zend_read_property(default_exception_ce, add_previous, "previous",
sizeof("previous")-1, 1 TSRMLS_CC);
- while (Z_TYPE_P(ancestor) == IS_OBJECT) {
- if (Z_OBJ_HANDLE_P(ancestor) == Z_OBJ_HANDLE_P(exception)) {
- return;
- }
- ancestor = zend_read_property(default_exception_ce, ancestor, "previous",
sizeof("previous")-1, 1 TSRMLS_CC);
- }
while (exception && exception != add_previous && Z_OBJ_HANDLE_P(exception) !=
Z_OBJ_HANDLE_P(add_previous)) {
+ ancestor = zend_read_property(default_exception_ce, add_previous, "previous",
sizeof("previous")-1, 1 TSRMLS_CC);
+ while (Z_TYPE_P(ancestor) == IS_OBJECT) {
+ if (Z_OBJ_HANDLE_P(ancestor) == Z_OBJ_HANDLE_P(exception)) {
+ zval_ptr_dtor(&add_previous);
+ return;
+ }
+ ancestor = zend_read_property(default_exception_ce, ancestor, "previous",
sizeof("previous")-1, 1 TSRMLS_CC);
+ }
previous = zend_read_property(default_exception_ce, exception, "previous",
sizeof("previous")-1, 1 TSRMLS_CC);
if (Z_TYPE_P(previous) == IS_NULL) {
zend_update_property(default_exception_ce, exception, "previous",
sizeof("previous")-1, add_previous TSRMLS_CC);