summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorXinchen Hui <laruence@gmail.com>2016-07-20 17:00:09 +0800
committerXinchen Hui <laruence@gmail.com>2016-07-20 17:00:09 +0800
commit9254f5d5d34982801dff7cea8cd361ab20abc9de (patch)
treef75fbf444a746a563e7aa598e999cb0149e33a0e
parent07b869f367da4ffa8689d342a0d532f614b7f78e (diff)
parent97c0b133c560e81bafbedaa321216b8862e1bdfc (diff)
downloadphp-git-9254f5d5d34982801dff7cea8cd361ab20abc9de.tar.gz
Merge branch 'PHP-7.0'
* PHP-7.0: Fixed bug #72629 (Caught exception assignment to variables ignores references). Conflicts: main/php_version.h
-rw-r--r--Zend/tests/try/bug72629.phpt16
-rw-r--r--Zend/zend_vm_def.h8
-rw-r--r--Zend/zend_vm_execute.h8
-rw-r--r--ext/pgsql/tests/config.inc2
4 files changed, 29 insertions, 5 deletions
diff --git a/Zend/tests/try/bug72629.phpt b/Zend/tests/try/bug72629.phpt
new file mode 100644
index 0000000000..2d596c78f8
--- /dev/null
+++ b/Zend/tests/try/bug72629.phpt
@@ -0,0 +1,16 @@
+--TEST--
+Bug #72629 (Caught exception assignment to variables ignores references)
+--FILE--
+<?php
+
+$var = null;
+$e = &$var;
+
+try {
+ throw new Exception;
+} catch (Exception $e) { }
+
+var_dump($var === $e);
+
+--EXPECT--
+bool(true)
diff --git a/Zend/zend_vm_def.h b/Zend/zend_vm_def.h
index 161a3f53fa..52cd979f5d 100644
--- a/Zend/zend_vm_def.h
+++ b/Zend/zend_vm_def.h
@@ -4157,6 +4157,7 @@ ZEND_VM_HANDLER(107, ZEND_CATCH, CONST, CV, JMP_ADDR)
USE_OPLINE
zend_class_entry *ce, *catch_ce;
zend_object *exception;
+ zval *ex;
SAVE_OPLINE();
/* Check whether an exception has been thrown, if not, jump over code */
@@ -4191,8 +4192,11 @@ ZEND_VM_HANDLER(107, ZEND_CATCH, CONST, CV, JMP_ADDR)
}
exception = EG(exception);
- zval_ptr_dtor(EX_VAR(opline->op2.var));
- ZVAL_OBJ(EX_VAR(opline->op2.var), EG(exception));
+ ex = EX_VAR(opline->op2.var);
+ if (UNEXPECTED(Z_ISREF_P(ex))) {
+ ex = Z_REFVAL_P(ex);
+ }
+ ZVAL_OBJ(ex, EG(exception));
if (UNEXPECTED(EG(exception) != exception)) {
GC_REFCOUNT(EG(exception))++;
HANDLE_EXCEPTION();
diff --git a/Zend/zend_vm_execute.h b/Zend/zend_vm_execute.h
index 3df5217514..231f4e56b3 100644
--- a/Zend/zend_vm_execute.h
+++ b/Zend/zend_vm_execute.h
@@ -9395,6 +9395,7 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_CATCH_SPEC_CONST_CV_HANDLER(ZE
USE_OPLINE
zend_class_entry *ce, *catch_ce;
zend_object *exception;
+ zval *ex;
SAVE_OPLINE();
/* Check whether an exception has been thrown, if not, jump over code */
@@ -9429,8 +9430,11 @@ static ZEND_OPCODE_HANDLER_RET ZEND_FASTCALL ZEND_CATCH_SPEC_CONST_CV_HANDLER(ZE
}
exception = EG(exception);
- zval_ptr_dtor(EX_VAR(opline->op2.var));
- ZVAL_OBJ(EX_VAR(opline->op2.var), EG(exception));
+ ex = EX_VAR(opline->op2.var);
+ if (UNEXPECTED(Z_ISREF_P(ex))) {
+ ex = Z_REFVAL_P(ex);
+ }
+ ZVAL_OBJ(ex, EG(exception));
if (UNEXPECTED(EG(exception) != exception)) {
GC_REFCOUNT(EG(exception))++;
HANDLE_EXCEPTION();
diff --git a/ext/pgsql/tests/config.inc b/ext/pgsql/tests/config.inc
index e9944de793..7be1e242ad 100644
--- a/ext/pgsql/tests/config.inc
+++ b/ext/pgsql/tests/config.inc
@@ -5,7 +5,7 @@
// environment var PGSQL_TEST_CONNSTR
// "test" database must exist. i.e. "createdb test" before testing
-$conn_str = getenv('PGSQL_TEST_CONNSTR') ?: "host=localhost dbname=test port=5432"; // connection string
+$conn_str = getenv('PGSQL_TEST_CONNSTR') ?: "host=localhost dbname=test port=5432 user=postgres password=postgres"; // connection string
$table_name = "php_pgsql_test"; // test table that will be created
$table_name_92 = "php_pgsql_test_92"; // test table that will be created