From 5e3e7819d6d54b93d656b72175f8e92c86665f2c Mon Sep 17 00:00:00 2001 From: Niels Dossche <7771979+nielsdos@users.noreply.github.com> Date: Thu, 22 Dec 2022 21:03:45 +0100 Subject: [PATCH] Fix undefined behaviour in phpdbg_load_module_or_extension If zend_register_module_ex were to return NULL, then module_entry will be set to NULL, and the if's body will load module_entry->name. Since module_entry is NULL, loading the name would cause a NULL pointer dereference. However, since a NULL pointer dereference is undefined behaviour, the compiler is free to remove the check. Fix it by using *name instead of module_entry->name. --- sapi/phpdbg/phpdbg_prompt.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sapi/phpdbg/phpdbg_prompt.c b/sapi/phpdbg/phpdbg_prompt.c index 6597f5fe42cf..4c50653ce66f 100644 --- a/sapi/phpdbg/phpdbg_prompt.c +++ b/sapi/phpdbg/phpdbg_prompt.c @@ -1321,7 +1321,7 @@ PHPDBG_API const char *phpdbg_load_module_or_extension(char **path, const char * module_entry->handle = handle; if ((module_entry = zend_register_module_ex(module_entry)) == NULL) { - phpdbg_error("Unable to register module %s", module_entry->name); + phpdbg_error("Unable to register module %s", *name); goto quit; }