Skip to content

Commit b80ef09

Browse files
committed
Check object_init_ex() in ReflectionMethod::createFromMethodName()
The result was ignored, so calling the factory on an uninstantiable subclass ran on a NULL zend_object: object_init_ex() throws, sets the return value to NULL and reports FAILURE, and Z_REFLECTION_P() then offsets backwards from that NULL. Other object_init_ex() calls in this file already test the result. Closes GH-22978
1 parent 841fe26 commit b80ef09

2 files changed

Lines changed: 27 additions & 1 deletion

File tree

ext/reflection/php_reflection.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3401,7 +3401,10 @@ static void instantiate_reflection_method(INTERNAL_FUNCTION_PARAMETERS, bool is_
34013401
if (is_constructor) {
34023402
object = ZEND_THIS;
34033403
} else {
3404-
object_init_ex(return_value, execute_data->This.value.ce ? execute_data->This.value.ce : reflection_method_ptr);
3404+
zend_class_entry *called_ce = execute_data->This.value.ce ? execute_data->This.value.ce : reflection_method_ptr;
3405+
if (UNEXPECTED(object_init_ex(return_value, called_ce) != SUCCESS)) {
3406+
RETURN_THROWS();
3407+
}
34053408
object = return_value;
34063409
}
34073410
intern = Z_REFLECTION_P(object);
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
--TEST--
2+
ReflectionMethod::createFromMethodName() called on an abstract subclass
3+
--FILE--
4+
<?php
5+
6+
class C {
7+
public function a() {}
8+
}
9+
10+
abstract class R extends ReflectionMethod {}
11+
12+
try {
13+
R::createFromMethodName('C::a');
14+
} catch (Throwable $e) {
15+
echo $e::class, ": ", $e->getMessage(), PHP_EOL;
16+
}
17+
18+
var_dump(ReflectionMethod::createFromMethodName('C::a')->name);
19+
20+
?>
21+
--EXPECT--
22+
Error: Cannot instantiate abstract class R
23+
string(1) "a"

0 commit comments

Comments
 (0)