Skip to content

Commit 9064dca

Browse files
committed
Merge branch 'PHP-7.0' into PHP-7.1
* PHP-7.0: Fixed bug #74673 (Segfault when cast Reflection object to string with undefined constant) Conflicts: ext/reflection/php_reflection.c
2 parents 316aaca + 9c5717d commit 9064dca

File tree

2 files changed

+29
-1
lines changed

2 files changed

+29
-1
lines changed

ext/reflection/php_reflection.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -468,6 +468,9 @@ static void _class_string(string *str, zend_class_entry *ce, zval *obj, char *in
468468

469469
ZEND_HASH_FOREACH_STR_KEY_PTR(&ce->constants_table, key, c) {
470470
_class_const_string(str, ZSTR_VAL(key), c, ZSTR_VAL(sub_indent.buf));
471+
if (UNEXPECTED(EG(exception))) {
472+
return;
473+
}
471474
} ZEND_HASH_FOREACH_END();
472475
}
473476
string_printf(str, "%s }\n", indent);
@@ -732,7 +735,10 @@ static void _parameter_string(string *str, zend_function *fptr, struct _zend_arg
732735

733736
string_write(str, " = ", sizeof(" = ")-1);
734737
ZVAL_DUP(&zv, RT_CONSTANT(&fptr->op_array, precv->op2));
735-
zval_update_constant_ex(&zv, fptr->common.scope);
738+
if (UNEXPECTED(zval_update_constant_ex(&zv, fptr->common.scope) == FAILURE)) {
739+
zval_ptr_dtor(&zv);
740+
return;
741+
}
736742
if (Z_TYPE(zv) == IS_TRUE) {
737743
string_write(str, "true", sizeof("true")-1);
738744
} else if (Z_TYPE(zv) == IS_FALSE) {

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)