Skip to content

Check object_init_ex() in ReflectionMethod::createFromMethodName() - #211

Closed
iliaal wants to merge 2 commits into
PHP-8.4from
fix/reflection-createfrommethodname-abstract
Closed

Check object_init_ex() in ReflectionMethod::createFromMethodName()#211
iliaal wants to merge 2 commits into
PHP-8.4from
fix/reflection-createfrommethodname-abstract

Conversation

@iliaal

@iliaal iliaal commented Jul 31, 2026

Copy link
Copy Markdown
Owner

instantiate_reflection_method() ignores the result of object_init_ex(). On an uninstantiable subclass that call throws, sets the return value to NULL and reports FAILURE, and the helper then runs Z_REFLECTION_P() over the NULL zend_object, offsetting backwards out of the allocation.

class C { public function a() {} }
abstract class R extends ReflectionMethod {}
R::createFromMethodName('C::a');
// SIGSEGV in reflection_prop_name(), php_reflection.c:71

Segfaults on 8.4, 8.5 and master; 8.3 carries the same code. ReflectionClass::newInstance(), newInstanceArgs() and newInstanceWithoutConstructor() already test the result the same way. Found while reviewing php#22968, which touches the same helper but does not cause this.

ReflectionMethod::__construct() overwrote intern->ptr without releasing
the previous Closure::__invoke() trampoline, and
ReflectionClassConstant::__construct() overwrote the $name and $class
slots without dropping their previous references. ReflectionFunction,
ReflectionParameter and ReflectionProperty already release prior state
on re-entry.

Closes phpGH-22968
@iliaal
iliaal force-pushed the fix/reflection-createfrommethodname-abstract branch from de8040b to da9a6ff Compare July 31, 2026 16:04
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. Three other object_init_ex() calls in
this file already test the result.

Closes phpGH-22978
@iliaal

iliaal commented Jul 31, 2026

Copy link
Copy Markdown
Owner Author

Promoted upstream as php#22978.

@iliaal
iliaal force-pushed the fix/reflection-createfrommethodname-abstract branch from da9a6ff to 16dfbeb Compare July 31, 2026 16:04
@iliaal iliaal closed this Jul 31, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant