Skip to content

Fix GH-26099: UAF in ReflectionParameter for a closure's __invoke - #26102

Open
lazerg wants to merge 2 commits into
php:PHP-8.4from
lazerg:fix/gh-26099
Open

lazerg wants to merge 2 commits into
php:PHP-8.4from
lazerg:fix/gh-26099

Conversation

@lazerg

@lazerg lazerg commented Dec 6, 2026

Copy link
Copy Markdown
Contributor

new ReflectionParameter([$closure, '__invoke'], ...) got the parameter from the __invoke trampoline, which shares arg_info with the closure's op_array, but it did not keep a reference to the closure. Once the closure was freed, getType() read freed memory. The constructor now holds the closure in intern->obj, like it already does when a closure is passed directly and like ReflectionMethod does for __invoke.

Fixes #26099

@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.

mostly looks good to me - can you add NEWS and fix the boolean usage? No need to adjust the other uses nearby, I already did those on newer versions, but newly added code should use proper booleans

Comment thread ext/reflection/php_reflection.c Outdated
not the closure itself */
reference = classref;
Z_ADDREF_P(reference);
is_closure = 1;

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.

Suggested change
is_closure = 1;
is_closure = true;

@lazerg

lazerg commented Dec 6, 2026

Copy link
Copy Markdown
Contributor Author

Added the NEWS entry and switched the new line to is_closure = true. Left the nearby uses alone.

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