Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 3 commits into from

Conversation

Girgias
Copy link
Member

@Girgias Girgias commented Oct 17, 2024

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 nielsdos October 17, 2024 11:11
Copy link
Member

@arnaud-lb arnaud-lb left a comment

Choose a reason for hiding this comment

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

LGTM!

Copy link
Member

@iluuu1994 iluuu1994 left a comment

Choose a reason for hiding this comment

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

LGTM

&use_include_path, &intern->u.file.zcontext) == FAILURE) {
intern->u.file.open_mode = NULL;
intern->file_name = NULL;
if (zend_parse_parameters(ZEND_NUM_ARGS(), "P|Sbr!", &intern->file_name, &open_mode, &use_include_path, &intern->u.file.zcontext) == FAILURE) {
Copy link
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
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.

Copy link
Member

@nielsdos nielsdos left a comment

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

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