Skip to content

Fix GH-12215: Module entry being overwritten causes type errors in ext/dom #12219

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 1 commit into from
Closed
Changes from all commits
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
17 changes: 16 additions & 1 deletion ext/standard/dl.c
Original file line number Diff line number Diff line change
Expand Up @@ -225,15 +225,30 @@ PHPAPI int php_load_extension(const char *filename, int type, int start_now)
DL_UNLOAD(handle);
return FAILURE;
}

int old_type = module_entry->type;
int old_module_number = module_entry->module_number;
void *old_handle = module_entry->handle;

module_entry->type = type;
module_entry->module_number = zend_next_free_module();
module_entry->handle = handle;

if ((module_entry = zend_register_module_ex(module_entry)) == NULL) {
zend_module_entry *added_module_entry;
if ((added_module_entry = zend_register_module_ex(module_entry)) == NULL) {
/* Module loading failed, potentially because the module was already loaded.
* It is especially important in that case to restore the old type, module_number, and handle.
* Overwriting the values for an already-loaded module causes problem when these fields are used
* to uniquely identify module boundaries (e.g. in dom and reflection). */
module_entry->type = old_type;
module_entry->module_number = old_module_number;
module_entry->handle = old_handle;
DL_UNLOAD(handle);
return FAILURE;
}

module_entry = added_module_entry;

if ((type == MODULE_TEMPORARY || start_now) && zend_startup_module_ex(module_entry) == FAILURE) {
DL_UNLOAD(handle);
return FAILURE;
Expand Down