Skip to content

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

Closed
iliaal wants to merge 1 commit into
php:PHP-8.4from
iliaal:fix/reflection-createfrommethodname-abstract
Closed

Check object_init_ex() in ReflectionMethod::createFromMethodName()#22978
iliaal wants to merge 1 commit into
php:PHP-8.4from
iliaal:fix/reflection-createfrommethodname-abstract

Conversation

@iliaal

@iliaal iliaal commented Jul 31, 2026

Copy link
Copy Markdown
Contributor

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 #22968, which touches the same helper but does not cause this.

@iliaal
iliaal requested a review from DanielEScherzer as a code owner July 31, 2026 16:04
iliaal added a commit to iliaal/php-src that referenced this pull request Jul 31, 2026
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 force-pushed the fix/reflection-createfrommethodname-abstract branch from da9a6ff to 16dfbeb Compare July 31, 2026 16:04
Comment thread ext/reflection/php_reflection.c Outdated
object_init_ex(return_value, execute_data->This.value.ce ? execute_data->This.value.ce : reflection_method_ptr);
zend_class_entry *called_ce = execute_data->This.value.ce ? execute_data->This.value.ce : reflection_method_ptr;
if (UNEXPECTED(object_init_ex(return_value, called_ce) != SUCCESS)) {
return;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should this use RETURN_THROWS()?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Matched the three other object_init_ex() call sites in this file, which all use a plain return. Want me to switch all four to RETURN_THROWS()?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no need to switch them all for a bugfix branch, but would be helpful to add it for just this one

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added in 9e5e100.

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 phpGH-22978
@iliaal
iliaal force-pushed the fix/reflection-createfrommethodname-abstract branch from 16dfbeb to 9e5e100 Compare July 31, 2026 16:36

@DanielEScherzer DanielEScherzer left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks, LGTM once CI passes

@iliaal iliaal closed this in b80ef09 Jul 31, 2026
@DanielEScherzer

DanielEScherzer commented Aug 1, 2026

Copy link
Copy Markdown
Member

@iliaal I think this needs to be included in NEWS for 8.4, 8.5, and master

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants