From 8bb2f406def958671e7719966a4c015dfe1e448b Mon Sep 17 00:00:00 2001 From: Nikita Popov Date: Mon, 31 Aug 2020 14:49:16 +0200 Subject: [PATCH] Check update constant failure in ReflectionClassConstant::__toString() --- ext/reflection/php_reflection.c | 5 ++++- ...ReflectionClassConstant_toString_error.phpt | 18 ++++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) create mode 100644 ext/reflection/tests/ReflectionClassConstant_toString_error.phpt diff --git a/ext/reflection/php_reflection.c b/ext/reflection/php_reflection.c index f62dd15e1c9..df00e5b4ba2 100644 --- a/ext/reflection/php_reflection.c +++ b/ext/reflection/php_reflection.c @@ -547,7 +547,10 @@ static void _class_const_string(smart_str *str, char *name, zend_class_constant char *visibility = zend_visibility_string(Z_ACCESS_FLAGS(c->value)); char *type; - zval_update_constant_ex(&c->value, c->ce); + if (zval_update_constant_ex(&c->value, c->ce) == FAILURE) { + return; + } + type = zend_zval_type_name(&c->value); if (Z_TYPE(c->value) == IS_ARRAY) { diff --git a/ext/reflection/tests/ReflectionClassConstant_toString_error.phpt b/ext/reflection/tests/ReflectionClassConstant_toString_error.phpt new file mode 100644 index 00000000000..cd4dfa3765c --- /dev/null +++ b/ext/reflection/tests/ReflectionClassConstant_toString_error.phpt @@ -0,0 +1,18 @@ +--TEST-- +Exception thrown while converting ReflectionClassConstant to string +--FILE-- +getMessage(), "\n"; +} + +?> +--EXPECT-- +Undefined class constant 'self::UNKNOWN'