summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNikita Popov <nikita.ppv@gmail.com>2020-08-31 15:10:09 +0200
committerNikita Popov <nikita.ppv@gmail.com>2020-08-31 15:10:09 +0200
commit1f6f9c70cb4e82ca9fbbf3153173e3d73a0f9170 (patch)
treed04b709216fa32168cbc5a9d53b321e0e7004e41
parent8bb2f406def958671e7719966a4c015dfe1e448b (diff)
downloadphp-git-1f6f9c70cb4e82ca9fbbf3153173e3d73a0f9170.tar.gz
Fix leak on consteval exception in ReflectionClass::__toString()
-rw-r--r--ext/reflection/php_reflection.c1
-rw-r--r--ext/reflection/tests/ReflectionClass_toString_004.phpt17
2 files changed, 18 insertions, 0 deletions
diff --git a/ext/reflection/php_reflection.c b/ext/reflection/php_reflection.c
index df00e5b4ba..620d95afa4 100644
--- a/ext/reflection/php_reflection.c
+++ b/ext/reflection/php_reflection.c
@@ -373,6 +373,7 @@ static void _class_string(smart_str *str, zend_class_entry *ce, zval *obj, char
ZEND_HASH_FOREACH_STR_KEY_PTR(&ce->constants_table, key, c) {
_class_const_string(str, ZSTR_VAL(key), c, ZSTR_VAL(sub_indent));
if (UNEXPECTED(EG(exception))) {
+ zend_string_release(sub_indent);
return;
}
} ZEND_HASH_FOREACH_END();
diff --git a/ext/reflection/tests/ReflectionClass_toString_004.phpt b/ext/reflection/tests/ReflectionClass_toString_004.phpt
new file mode 100644
index 0000000000..04b42d0792
--- /dev/null
+++ b/ext/reflection/tests/ReflectionClass_toString_004.phpt
@@ -0,0 +1,17 @@
+--TEST--
+Constant evaluation exception during ReflectionClass::__toString()
+--FILE--
+<?php
+
+class A {
+ const C = self::UNKNOWN;
+}
+try {
+ echo new ReflectionClass(A::class);
+} catch (Error $e) {
+ echo $e->getMessage(), "\n";
+}
+
+?>
+--EXPECT--
+Undefined class constant 'self::UNKNOWN'