From 2b70d44b57a4ec3b449c70e6deb547415c2623e7 Mon Sep 17 00:00:00 2001 From: Dmitry Stogov Date: Fri, 2 Dec 2016 15:13:55 +0300 Subject: [PATCH] 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 | 17 +++++++++++++++++ Zend/zend_operators.c | 11 +++++++++++ 2 files changed, 28 insertions(+) diff --git a/Zend/tests/compound_assign_failure.phpt b/Zend/tests/compound_assign_failure.phpt index f1afc783a0..f8d863106a 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-- --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 0d3c8e46e7..96571da53e 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; } } -- 2.50.1