com php-src: Fixed behavior of failing compound assignments (they shouldn't change the source value when exception thrown during type converion).:
Zend/tests/compound_assign_failure.phpt Zend/zend_ope rators.c

From: Date: Fri, 02 Dec 2016 12:13:55 +0000
Subject: com php-src: Fixed behavior of failing compound assignments (they shouldn't change the source value when exception thrown during type converion).:
Zend/tests/compound_assign_failure.phpt Zend/zend_ope rators.c
Groups: php.cvs 
Request: Send a blank email to php-cvs+get-96155@lists.php.net to get a copy of this message
Commit: 2b70d44b57a4ec3b449c70e6deb547415c2623e7 Author: Dmitry Stogov <dmitry@zend.com> Fri, 2 Dec 2016 15:13:55 +0300 Parents: dbf39cddd93ad06ce0353695bd02d448a5d6dac9 Branches: PHP-7.0 PHP-7.1 master Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=2b70d44b57a4ec3b449c70e6deb547415c2623e7 Log: Fixed behavior of failing compound assignments (they shouldn't change the source value when exception thrown during type converion). Changed paths: M Zend/tests/compound_assign_failure.phpt M Zend/zend_operators.c Diff: diff --git a/Zend/tests/compound_assign_failure.phpt b/Zend/tests/compound_assign_failure.phpt index f1afc78..f8d8631 100644 --- a/Zend/tests/compound_assign_failure.phpt +++ b/Zend/tests/compound_assign_failure.phpt @@ -1,5 +1,7 @@ --TEST-- Behavior of failing compound assignment +--INI-- +opcache.optimization_level=0 --FILE-- <?php @@ -17,8 +19,23 @@ try { $a = 1; $a <<= -1; } catch (Error $e) { var_dump($a); } + +set_error_handler(function() { throw new Exception; }); + +try { + $a = []; + $a .= "foo"; +} catch (Throwable $e) { var_dump($a); } + +try { + $a = "foo"; + $a .= []; +} catch (Throwable $e) { var_dump($a); } ?> --EXPECT-- int(1) int(1) int(1) +array(0) { +} +string(3) "foo" diff --git a/Zend/zend_operators.c b/Zend/zend_operators.c index 0d3c8e4..96571da 100644 --- a/Zend/zend_operators.c +++ b/Zend/zend_operators.c @@ -1628,6 +1628,10 @@ ZEND_API int ZEND_FASTCALL concat_function(zval *result, zval *op1, zval *op2) / ZEND_TRY_BINARY_OBJECT_OPERATION(ZEND_CONCAT, concat_function); use_copy1 = zend_make_printable_zval(op1, &op1_copy); if (use_copy1) { + if (UNEXPECTED(EG(exception))) { + zval_dtor(&op1_copy); + return FAILURE; + } if (result == op1) { if (UNEXPECTED(op1 == op2)) { op2 = &op1_copy; @@ -1646,6 +1650,13 @@ ZEND_API int ZEND_FASTCALL concat_function(zval *result, zval *op1, zval *op2) / ZEND_TRY_BINARY_OP2_OBJECT_OPERATION(ZEND_CONCAT); use_copy2 = zend_make_printable_zval(op2, &op2_copy); if (use_copy2) { + if (UNEXPECTED(EG(exception))) { + if (UNEXPECTED(use_copy1)) { + zval_dtor(op1); + } + zval_dtor(&op2_copy); + return FAILURE; + } op2 = &op2_copy; } }

« previous php.cvs (#96155) next »