-
Notifications
You must be signed in to change notification settings - Fork 7.8k
Fix GH-9589: dl() segfaults when module is already loaded #9689
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
Conversation
As of PHP 8.2.0, `zend_module_entry` structures are no longer copied, so when a module is permanently loaded, and users try to dynamically load that module again, the structure is corrupted[1], causing a segfault on shutdown. We catch that by checking whether any dynamically loaded module is already loaded, and bailing out in that case without modifying the `zend_module_entry` structure. [1] <php#9589 (comment)>
Note that this may be applied with or without also applying PR #9648; while that duplicates a bit of code in the former case (where it is not strictly necessary), it still seems to be good practice to catch this condition early, and to fail fast. /cc @arnaud-lb, @morrisonlevi |
--TEST-- | ||
dl() segfaults when module is already loaded | ||
--EXTENSIONS-- | ||
dl_test |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's probably sensible to add a comment regarding the usage of dl_test
; actually, it doesn't matter which extension we use for the test, but it is mandatory that it is a shared module; this is always given for dl_test
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
As of PHP 8.2.0,
zend_module_entry
structures are no longer copied, so when a module is permanently loaded, and users try to dynamically load that module again, the structure is corrupted[1], causing a segfault on shutdown.We catch that by checking whether any dynamically loaded module is already loaded, and bailing out in that case without modifying the
zend_module_entry
structure.[1] #9589 (comment)