Skip to content

Fix GH-16477 (Segmentation fault when calling __debugInfo() after failed SplFileObject::__constructor) - #16480

Closed
Girgias wants to merge 3 commits into
php:PHP-8.2from
Girgias:8.2-spldirectory
Closed

Girgias wants to merge 3 commits into
php:PHP-8.2from
Girgias:8.2-spldirectory

Conversation

@Girgias

@Girgias Girgias commented Oct 17, 2024 •

Copy link
Copy Markdown
Member

Also fix a memory leak when reinitializing SplFileTemp

@Girgias Girgias linked an issue Oct 17, 2024 that may be closed by this pull request
@Girgias
Girgias requested a review from ndossche October 17, 2024 11:11

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

LGTM!

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

LGTM

Comment thread ext/spl/spl_directory.c Outdated

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.

intern->file_name could be left with a dangling pointer if a later parameter fails to parse. This isn't currently an issue because new will destroy the object, and ReflectionClass::newInstanceWithoutConstructor() doesn't actually allow calling __construct (prevented by spl_filesystem_object_get_method_check()). Nonetheless, it might be preferable to store it to a variable and copy it to intern when parsing is successful.

&intern->u.file.zcontext doesn't really apply, since it's the last parameter, but for consistency it might still make sense.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I've rewritten it so that it takes dedicated stack variables. However, the fact that intern->file_name is not working on a copy seems quite dubious.

Comment thread ext/spl/spl_directory.c Resolved

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

Ok for me apart from the TODO that Ilija explained and my remark

Comment thread ext/spl/spl_directory.c Resolved
Girgias added a commit that referenced this pull request Oct 25, 2024
@Girgias Girgias closed this in 9f5b5e3 Oct 25, 2024
Girgias added a commit that referenced this pull request Oct 25, 2024
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.

Segmentation fault in ext/spl/spl_directory.c

4 participants