com php-src: Fixed bug #70944 (try{ } finally{} can create infinite chains of exceptions): NEWS Zend/tests/bug70944.phpt Zend/zend_excep tions.c

From: Date: Fri, 20 Nov 2015 08:24:53 +0000
Subject: com php-src: Fixed bug #70944 (try{ } finally{} can create infinite chains of exceptions): NEWS Zend/tests/bug70944.phpt Zend/zend_excep tions.c
Groups: php.cvs 
Request: Send a blank email to php-cvs+get-89935@lists.php.net to get a copy of this message
Commit: a1c887964e34c0531b238e33a6b85e9925731194 Author: Xinchen Hui <laruence@gmail.com> Fri, 20 Nov 2015 16:24:53 +0800 Parents: b42eb16cf4ae58e8c8fbc8afc4406bc746497754 Branches: PHP-5.6 PHP-7.0 master Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=a1c887964e34c0531b238e33a6b85e9925731194 Log: Fixed bug #70944 (try{ } finally{} can create infinite chains of exceptions) Bugs: https://bugs.php.net/70944 Changed paths: M NEWS A Zend/tests/bug70944.phpt M Zend/zend_exceptions.c Diff: diff --git a/NEWS b/NEWS index 72cd4f9..189d9e0 100644 --- a/NEWS +++ b/NEWS @@ -2,6 +2,10 @@ PHP NEWS ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| ?? ??? 2015, PHP 5.6.17 +- Core: + . Fixed bug #70944 (try{ } finally{} can create infinite chains of + exceptions). (Laruence) + - Mysqlnd: . Fixed bug #68077 (LOAD DATA LOCAL INFILE / open_basedir restriction). (Laruence) diff --git a/Zend/tests/bug70944.phpt b/Zend/tests/bug70944.phpt new file mode 100644 index 0000000..d189d9e --- /dev/null +++ b/Zend/tests/bug70944.phpt @@ -0,0 +1,16 @@ +--TEST-- +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; +} +?> +--EXPECTF-- +Fatal error: Uncaught exception 'Exception' with message 'Bar' in %sbug70944.php:%d +Stack trace: +#0 {main} + thrown in %sbug70944.php on line %d diff --git a/Zend/zend_exceptions.c b/Zend/zend_exceptions.c index 40248f7..d1aa6fe 100644 --- a/Zend/zend_exceptions.c +++ b/Zend/zend_exceptions.c @@ -36,7 +36,7 @@ ZEND_API void (*zend_throw_exception_hook)(zval *ex TSRMLS_DC); void zend_exception_set_previous(zval *exception, zval *add_previous TSRMLS_DC) { - zval *previous; + zval *previous, *ancestor; if (exception == add_previous || !add_previous || !exception) { return; @@ -45,6 +45,13 @@ 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)) { previous = zend_read_property(default_exception_ce, exception, "previous", sizeof("previous")-1, 1 TSRMLS_CC); if (Z_TYPE_P(previous) == IS_NULL) {

« previous php.cvs (#89935) next »