Skip to content

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

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions ext/standard/dl.c
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,10 @@ PHPAPI int php_load_extension(const char *filename, int type, int start_now)
return FAILURE;
}
module_entry = get_module();
if (zend_hash_str_exists(&module_registry, module_entry->name, strlen(module_entry->name))) {
zend_error(E_CORE_WARNING, "Module \"%s\" is already loaded", module_entry->name);
return FAILURE;
}
if (module_entry->zend_api != ZEND_MODULE_API_NO) {
php_error_docref(NULL, error_type,
"%s: Unable to initialize module\n"
Expand Down
10 changes: 10 additions & 0 deletions ext/standard/tests/general_functions/gh9589.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
--TEST--
dl() segfaults when module is already loaded
--EXTENSIONS--
dl_test
Copy link
Member Author

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.

--FILE--
<?php
dl("dl_test");
?>
--EXPECT--
Warning: Module "dl_test" is already loaded in Unknown on line 0