Skip to content

Commit

Permalink
Fix assertion in Exception::getMessage() if $message is a ref
Browse files Browse the repository at this point in the history
And same for other properties. Encountered in Symfony.
  • Loading branch information
nikic committed Feb 25, 2019
1 parent 1c22ace commit af37d58
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 12 deletions.
30 changes: 30 additions & 0 deletions Zend/tests/exception_getters_with_ref_props.phpt
Original file line number Diff line number Diff line change
@@ -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)
36 changes: 24 additions & 12 deletions Zend/zend_exceptions.c
Original file line number Diff line number Diff line change
Expand Up @@ -401,71 +401,83 @@ 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);
}
/* }}} */

/* {{{ proto int Exception|Error::getLine()
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);
}
/* }}} */

/* {{{ proto string Exception|Error::getMessage()
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);
}
/* }}} */

/* {{{ proto int Exception|Error::getCode()
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);
}
/* }}} */

/* {{{ proto array Exception|Error::getTrace()
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);
}
/* }}} */

/* {{{ proto int ErrorException::getSeverity()
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);
}
/* }}} */

Expand Down

0 comments on commit af37d58

Please sign in to comment.