From 55dd3945fb32cf35e0385febc0114a0036d50190 Mon Sep 17 00:00:00 2001 From: Nikita Popov Date: Mon, 25 May 2020 12:10:41 +0200 Subject: Convert Exception::getMessage() result to string We specify that the return type of Exception::getMessage() is a string. However, we don't currently ensure this, because Exception::$message is a protected member that can be set to any type. Fix this by performing an explicit type-cast. This also requires a temporary refcount increment in the __toString() object handler, because there is no additional owner of the object, and it may get released prematurely as part of the __toString() call. --- Zend/zend_exceptions.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'Zend/zend_exceptions.c') diff --git a/Zend/zend_exceptions.c b/Zend/zend_exceptions.c index a039d18668..31738b6a86 100644 --- a/Zend/zend_exceptions.c +++ b/Zend/zend_exceptions.c @@ -414,8 +414,7 @@ ZEND_METHOD(Exception, getMessage) ZEND_PARSE_PARAMETERS_NONE(); prop = GET_PROPERTY(ZEND_THIS, ZEND_STR_MESSAGE); - ZVAL_DEREF(prop); - ZVAL_COPY(return_value, prop); + RETURN_STR(zval_get_string(prop)); } /* }}} */ -- cgit v1.2.1