com php-src: Fix assertion in Exception::getMessage() if $message is a ref: Zend/tests/exception_getters_with_ref_props.phpt Ze nd/zend_exceptions.c
| From: | Nikita Popov | Date: | Mon, 25 Feb 2019 12:00:16 +0000 |
| Subject: | com php-src: Fix assertion in Exception::getMessage() if $message is a ref: Zend/tests/exception_getters_with_ref_props.phpt Ze nd/zend_exceptions.c | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-104862@lists.php.net to get a copy of this message | ||
Commit: af37d58cf7b77814b93ea97a8dcd2afb46c4424e
Author: Nikita Popov <nikita.ppv@gmail.com> Mon, 25 Feb 2019 13:00:16 +0100
Parents: 1c22ace0582fb0a2ec581237fcf1c5b9c41edd04
Branches: PHP-7.2 PHP-7.3 PHP-7.4 master
Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=af37d58cf7b77814b93ea97a8dcd2afb46c4424e
Log:
Fix assertion in Exception::getMessage() if $message is a ref
And same for other properties. Encountered in Symfony.
Changed paths:
A Zend/tests/exception_getters_with_ref_props.phpt
M Zend/zend_exceptions.c
Diff:
diff --git a/Zend/tests/exception_getters_with_ref_props.phpt
b/Zend/tests/exception_getters_with_ref_props.phpt
new file mode 100644
index 0000000..d3dcd83
--- /dev/null
+++ b/Zend/tests/exception_getters_with_ref_props.phpt
@@ -0,0 +1,30 @@
+--TEST--
+Calling exception getters when properties hold references
+--FILE--
+<?php
+
+class MyException extends Exception {
+ public function __construct(&$refMsg, &$refCode, &$refFile, &$refLine) {
+ $this->message =& $refMsg;
+ $this->code =& $refCode;
+ $this->file =& $refFile;
+ $this->line =& $refLine;
+ }
+}
+
+$refMsg = "foo";
+$refCode = 0;
+$refFile = "foobar";
+$refLine = 42;
+$ex = new MyException($refMsg, $refCode, $refFile, $refLine);
+var_dump($ex->getMessage());
+var_dump($ex->getCode());
+var_dump($ex->getFile());
+var_dump($ex->getLine());
+
+?>
+--EXPECT--
+string(3) "foo"
+int(0)
+string(6) "foobar"
+int(42)
diff --git a/Zend/zend_exceptions.c b/Zend/zend_exceptions.c
index b4deb29..486a5d3 100644
--- a/Zend/zend_exceptions.c
+++ b/Zend/zend_exceptions.c
@@ -401,11 +401,13 @@ ZEND_METHOD(error_exception, __construct)
Get the file in which the exception occurred */
ZEND_METHOD(exception, getFile)
{
- zval rv;
+ zval *prop, rv;
DEFAULT_0_PARAMS;
- ZVAL_COPY(return_value, GET_PROPERTY(getThis(), ZEND_STR_FILE));
+ prop = GET_PROPERTY(getThis(), ZEND_STR_FILE);
+ ZVAL_DEREF(prop);
+ ZVAL_COPY(return_value, prop);
}
/* }}} */
@@ -413,11 +415,13 @@ ZEND_METHOD(exception, getFile)
Get the line in which the exception occurred */
ZEND_METHOD(exception, getLine)
{
- zval rv;
+ zval *prop, rv;
DEFAULT_0_PARAMS;
- ZVAL_COPY(return_value, GET_PROPERTY(getThis(), ZEND_STR_LINE));
+ prop = GET_PROPERTY(getThis(), ZEND_STR_LINE);
+ ZVAL_DEREF(prop);
+ ZVAL_COPY(return_value, prop);
}
/* }}} */
@@ -425,11 +429,13 @@ ZEND_METHOD(exception, getLine)
Get the exception message */
ZEND_METHOD(exception, getMessage)
{
- zval rv;
+ zval *prop, rv;
DEFAULT_0_PARAMS;
- ZVAL_COPY(return_value, GET_PROPERTY(getThis(), ZEND_STR_MESSAGE));
+ prop = GET_PROPERTY(getThis(), ZEND_STR_MESSAGE);
+ ZVAL_DEREF(prop);
+ ZVAL_COPY(return_value, prop);
}
/* }}} */
@@ -437,11 +443,13 @@ ZEND_METHOD(exception, getMessage)
Get the exception code */
ZEND_METHOD(exception, getCode)
{
- zval rv;
+ zval *prop, rv;
DEFAULT_0_PARAMS;
- ZVAL_COPY(return_value, GET_PROPERTY(getThis(), ZEND_STR_CODE));
+ prop = GET_PROPERTY(getThis(), ZEND_STR_CODE);
+ ZVAL_DEREF(prop);
+ ZVAL_COPY(return_value, prop);
}
/* }}} */
@@ -449,11 +457,13 @@ ZEND_METHOD(exception, getCode)
Get the stack trace for the location in which the exception occurred */
ZEND_METHOD(exception, getTrace)
{
- zval rv;
+ zval *prop, rv;
DEFAULT_0_PARAMS;
- ZVAL_COPY(return_value, GET_PROPERTY(getThis(), ZEND_STR_TRACE));
+ prop = GET_PROPERTY(getThis(), ZEND_STR_TRACE);
+ ZVAL_DEREF(prop);
+ ZVAL_COPY(return_value, prop);
}
/* }}} */
@@ -461,11 +471,13 @@ ZEND_METHOD(exception, getTrace)
Get the exception severity */
ZEND_METHOD(error_exception, getSeverity)
{
- zval rv;
+ zval *prop, rv;
DEFAULT_0_PARAMS;
- ZVAL_COPY(return_value, GET_PROPERTY(getThis(), ZEND_STR_SEVERITY));
+ prop = GET_PROPERTY(getThis(), ZEND_STR_SEVERITY);
+ ZVAL_DEREF(prop);
+ ZVAL_COPY(return_value, prop);
}
/* }}} */