diff --git a/NEWS b/NEWS index b14555b348b..62b82f32fdd 100644 --- a/NEWS +++ b/NEWS @@ -5,6 +5,8 @@ PHP NEWS - Core: . Fixed bug GH-9655 (Pure intersection types cannot be implicitly nullable) (Girgias) + . Fixed bug GH-9589 (dl() segfaults when module is already loaded). (cmb, + Arnaud) - Streams: . Fixed bug GH-9590 (stream_select does not abort upon exception or empty diff --git a/ext/standard/dl.c b/ext/standard/dl.c index aae09963845..7b47c4726d1 100644 --- a/ext/standard/dl.c +++ b/ext/standard/dl.c @@ -205,6 +205,11 @@ 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))) { + DL_UNLOAD(handle); + 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" diff --git a/ext/standard/tests/general_functions/gh9589.phpt b/ext/standard/tests/general_functions/gh9589.phpt new file mode 100644 index 00000000000..a26f052debe --- /dev/null +++ b/ext/standard/tests/general_functions/gh9589.phpt @@ -0,0 +1,10 @@ +--TEST-- +dl() segfaults when module is already loaded +--EXTENSIONS-- +dl_test +--FILE-- + +--EXPECT-- +Warning: Module "dl_test" is already loaded in Unknown on line 0