From 70b2aa7fb858670687bcfd35f8cc2649294d52e9 Mon Sep 17 00:00:00 2001 From: Nikita Popov Date: Thu, 28 May 2020 14:19:47 +0200 Subject: [PATCH] Ensure Exception::getFile/getLine return type is correct These return an untyped protected property, so we can't rely on the type being correct. Also add return types to the interface -- normally this would be a no-go, but Throwable is a special interface that can only be implemented internally, so we control all implementations. --- Zend/zend_exceptions.c | 6 ++-- Zend/zend_exceptions.stub.php | 18 ++++------ Zend/zend_exceptions_arginfo.h | 60 +++++++++++++++++----------------- 3 files changed, 38 insertions(+), 46 deletions(-) diff --git a/Zend/zend_exceptions.c b/Zend/zend_exceptions.c index 6262685c47..a2bdbdad74 100644 --- a/Zend/zend_exceptions.c +++ b/Zend/zend_exceptions.c @@ -380,8 +380,7 @@ ZEND_METHOD(Exception, getFile) ZEND_PARSE_PARAMETERS_NONE(); prop = GET_PROPERTY(ZEND_THIS, ZEND_STR_FILE); - ZVAL_DEREF(prop); - ZVAL_COPY(return_value, prop); + RETURN_STR(zval_get_string(prop)); } /* }}} */ @@ -394,8 +393,7 @@ ZEND_METHOD(Exception, getLine) ZEND_PARSE_PARAMETERS_NONE(); prop = GET_PROPERTY(ZEND_THIS, ZEND_STR_LINE); - ZVAL_DEREF(prop); - ZVAL_COPY(return_value, prop); + RETURN_LONG(zval_get_long(prop)); } /* }}} */ diff --git a/Zend/zend_exceptions.stub.php b/Zend/zend_exceptions.stub.php index c467f36ecb..9cf55fd384 100644 --- a/Zend/zend_exceptions.stub.php +++ b/Zend/zend_exceptions.stub.php @@ -4,26 +4,20 @@ interface Throwable extends Stringable { - /** @return string */ - public function getMessage(); + public function getMessage(): string; /** @return int */ public function getCode(); - /** @return string */ - public function getFile(); + public function getFile(): string; - /** @return int */ - public function getLine(); + public function getLine(): int; - /** @return array */ - public function getTrace(); + public function getTrace(): array; - /** @return ?Throwable */ - public function getPrevious(); + public function getPrevious(): ?Throwable; - /** @return string */ - public function getTraceAsString(); + public function getTraceAsString(): string; } class Exception implements Throwable diff --git a/Zend/zend_exceptions_arginfo.h b/Zend/zend_exceptions_arginfo.h index 3f8ceb833b..db114fbeaa 100644 --- a/Zend/zend_exceptions_arginfo.h +++ b/Zend/zend_exceptions_arginfo.h @@ -1,21 +1,25 @@ /* This is a generated file, edit the .stub.php file instead. */ -ZEND_BEGIN_ARG_INFO_EX(arginfo_class_Throwable_getMessage, 0, 0, 0) +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_class_Throwable_getMessage, 0, 0, IS_STRING, 0) ZEND_END_ARG_INFO() -#define arginfo_class_Throwable_getCode arginfo_class_Throwable_getMessage +ZEND_BEGIN_ARG_INFO_EX(arginfo_class_Throwable_getCode, 0, 0, 0) +ZEND_END_ARG_INFO() #define arginfo_class_Throwable_getFile arginfo_class_Throwable_getMessage -#define arginfo_class_Throwable_getLine arginfo_class_Throwable_getMessage +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_class_Throwable_getLine, 0, 0, IS_LONG, 0) +ZEND_END_ARG_INFO() -#define arginfo_class_Throwable_getTrace arginfo_class_Throwable_getMessage +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_class_Throwable_getTrace, 0, 0, IS_ARRAY, 0) +ZEND_END_ARG_INFO() -#define arginfo_class_Throwable_getPrevious arginfo_class_Throwable_getMessage +ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(arginfo_class_Throwable_getPrevious, 0, 0, Throwable, 1) +ZEND_END_ARG_INFO() #define arginfo_class_Throwable_getTraceAsString arginfo_class_Throwable_getMessage -#define arginfo_class_Exception___clone arginfo_class_Throwable_getMessage +#define arginfo_class_Exception___clone arginfo_class_Throwable_getCode ZEND_BEGIN_ARG_INFO_EX(arginfo_class_Exception___construct, 0, 0, 0) ZEND_ARG_TYPE_INFO(0, message, IS_STRING, 0) @@ -23,27 +27,23 @@ ZEND_BEGIN_ARG_INFO_EX(arginfo_class_Exception___construct, 0, 0, 0) ZEND_ARG_OBJ_INFO_WITH_DEFAULT_VALUE(0, previous, Throwable, 1, "null") ZEND_END_ARG_INFO() -#define arginfo_class_Exception___wakeup arginfo_class_Throwable_getMessage +#define arginfo_class_Exception___wakeup arginfo_class_Throwable_getCode -ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_class_Exception_getMessage, 0, 0, IS_STRING, 0) -ZEND_END_ARG_INFO() +#define arginfo_class_Exception_getMessage arginfo_class_Throwable_getMessage -#define arginfo_class_Exception_getCode arginfo_class_Throwable_getMessage +#define arginfo_class_Exception_getCode arginfo_class_Throwable_getCode -#define arginfo_class_Exception_getFile arginfo_class_Exception_getMessage +#define arginfo_class_Exception_getFile arginfo_class_Throwable_getMessage -ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_class_Exception_getLine, 0, 0, IS_LONG, 0) -ZEND_END_ARG_INFO() +#define arginfo_class_Exception_getLine arginfo_class_Throwable_getLine -ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_class_Exception_getTrace, 0, 0, IS_ARRAY, 0) -ZEND_END_ARG_INFO() +#define arginfo_class_Exception_getTrace arginfo_class_Throwable_getTrace -ZEND_BEGIN_ARG_WITH_RETURN_OBJ_INFO_EX(arginfo_class_Exception_getPrevious, 0, 0, Throwable, 1) -ZEND_END_ARG_INFO() +#define arginfo_class_Exception_getPrevious arginfo_class_Throwable_getPrevious -#define arginfo_class_Exception_getTraceAsString arginfo_class_Exception_getMessage +#define arginfo_class_Exception_getTraceAsString arginfo_class_Throwable_getMessage -#define arginfo_class_Exception___toString arginfo_class_Exception_getMessage +#define arginfo_class_Exception___toString arginfo_class_Throwable_getMessage ZEND_BEGIN_ARG_INFO_EX(arginfo_class_ErrorException___construct, 0, 0, 0) ZEND_ARG_TYPE_INFO(0, message, IS_STRING, 0) @@ -54,29 +54,29 @@ ZEND_BEGIN_ARG_INFO_EX(arginfo_class_ErrorException___construct, 0, 0, 0) ZEND_ARG_OBJ_INFO_WITH_DEFAULT_VALUE(0, previous, Throwable, 1, "null") ZEND_END_ARG_INFO() -#define arginfo_class_ErrorException_getSeverity arginfo_class_Exception_getLine +#define arginfo_class_ErrorException_getSeverity arginfo_class_Throwable_getLine -#define arginfo_class_Error___clone arginfo_class_Throwable_getMessage +#define arginfo_class_Error___clone arginfo_class_Throwable_getCode #define arginfo_class_Error___construct arginfo_class_Exception___construct -#define arginfo_class_Error___wakeup arginfo_class_Throwable_getMessage +#define arginfo_class_Error___wakeup arginfo_class_Throwable_getCode -#define arginfo_class_Error_getMessage arginfo_class_Exception_getMessage +#define arginfo_class_Error_getMessage arginfo_class_Throwable_getMessage -#define arginfo_class_Error_getCode arginfo_class_Throwable_getMessage +#define arginfo_class_Error_getCode arginfo_class_Throwable_getCode -#define arginfo_class_Error_getFile arginfo_class_Exception_getMessage +#define arginfo_class_Error_getFile arginfo_class_Throwable_getMessage -#define arginfo_class_Error_getLine arginfo_class_Exception_getLine +#define arginfo_class_Error_getLine arginfo_class_Throwable_getLine -#define arginfo_class_Error_getTrace arginfo_class_Exception_getTrace +#define arginfo_class_Error_getTrace arginfo_class_Throwable_getTrace -#define arginfo_class_Error_getPrevious arginfo_class_Exception_getPrevious +#define arginfo_class_Error_getPrevious arginfo_class_Throwable_getPrevious -#define arginfo_class_Error_getTraceAsString arginfo_class_Exception_getMessage +#define arginfo_class_Error_getTraceAsString arginfo_class_Throwable_getMessage -#define arginfo_class_Error___toString arginfo_class_Exception_getMessage +#define arginfo_class_Error___toString arginfo_class_Throwable_getMessage ZEND_METHOD(Exception, __clone); -- 2.40.0