Skip to content

Commit 9c5717d

Browse files
committed
Fixed bug #74673 (Segfault when cast Reflection object to string with undefined constant)
1 parent 77cbf8a commit 9c5717d

File tree

3 files changed

+34
-2
lines changed

3 files changed

+34
-2
lines changed

NEWS

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,10 @@ PHP NEWS
1515
. Fixed bug #74663 (Segfault with opcache.memory_protect and
1616
validate_timestamp). (Laruence)
1717

18+
- Reflection:
19+
. Fixed bug #74673 (Segfault when cast Reflection object to string with
20+
undefined constant). (Laruence)
21+
1822
- SPL:
1923
. Fixed bug #74478 (null coalescing operator failing with SplFixedArray).
2024
(jhdxr)

ext/reflection/php_reflection.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -462,7 +462,9 @@ static void _class_string(string *str, zend_class_entry *ce, zval *obj, char *in
462462
zval *value;
463463

464464
ZEND_HASH_FOREACH_STR_KEY_VAL(&ce->constants_table, key, value) {
465-
zval_update_constant_ex(value, 1, NULL);
465+
if (UNEXPECTED(zval_update_constant_ex(value, 1, NULL) == FAILURE)) {
466+
return;
467+
}
466468
_const_string(str, ZSTR_VAL(key), value, indent);
467469
} ZEND_HASH_FOREACH_END();
468470
}
@@ -708,7 +710,11 @@ static void _parameter_string(string *str, zend_function *fptr, struct _zend_arg
708710
ZVAL_DUP(&zv, RT_CONSTANT(&fptr->op_array, precv->op2));
709711
old_scope = EG(scope);
710712
EG(scope) = fptr->common.scope;
711-
zval_update_constant_ex(&zv, 1, NULL);
713+
if (UNEXPECTED(zval_update_constant_ex(&zv, 1, NULL) == FAILURE)) {
714+
EG(scope) = old_scope;
715+
zval_ptr_dtor(&zv);
716+
return;
717+
}
712718
EG(scope) = old_scope;
713719
if (Z_TYPE(zv) == IS_TRUE) {
714720
string_write(str, "true", sizeof("true")-1);

ext/reflection/tests/bug74673.phpt

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
--TEST--
2+
Bug #74673 (Segfault when cast Reflection object to string with undefined constant)
3+
--FILE--
4+
<?php
5+
6+
set_error_handler(function() {
7+
throw new Exception();
8+
});
9+
10+
class A
11+
{
12+
public function method($test = PHP_SELF + 1)
13+
{
14+
}
15+
}
16+
17+
$class = new ReflectionClass('A');
18+
19+
echo $class;
20+
?>
21+
--EXPECTF--
22+
Fatal error: Method ReflectionClass::__toString() must not throw an exception, caught Exception: in %sbug74673.php on line %d

0 commit comments

Comments
 (0)