Skip to content

Commit

Permalink
Fix leak on consteval exception in ReflectionClass::__toString()
Browse files Browse the repository at this point in the history
  • Loading branch information
nikic committed Aug 31, 2020
1 parent 8bb2f40 commit 1f6f9c7
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
1 change: 1 addition & 0 deletions ext/reflection/php_reflection.c
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
17 changes: 17 additions & 0 deletions ext/reflection/tests/ReflectionClass_toString_004.phpt
Original file line number Diff line number Diff line change
@@ -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'

0 comments on commit 1f6f9c7

Please sign in to comment.