]> git.ipfire.org Git - thirdparty/grub.git/commitdiff
kern/command,commands/extcmd: Perform explicit NULL check in both the unregister...
authorSrish Srinivasan <ssrish@linux.ibm.com>
Mon, 22 Sep 2025 06:02:46 +0000 (11:32 +0530)
committerDaniel Kiper <daniel.kiper@oracle.com>
Sat, 11 Oct 2025 13:36:54 +0000 (15:36 +0200)
During command registration, grub_register_command_prio() returns
a 0 when there is a failure in memory allocation. In such a situation,
calls to grub_unregister_{command(), extcmd()} during command
unregistration will result in dereferencing a NULL pointer.

Perform explicit NULL check in both unregister helpers to prevent
undefined behaviour due to a NULL pointer dereference.

Signed-off-by: Srish Srinivasan <ssrish@linux.ibm.com>
Reviewed-by: Sudhakar Kuppusamy <sudhakar@linux.ibm.com>
Reviewed-by: Stefan Berger <stefanb@linux.ibm.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
grub-core/commands/extcmd.c
grub-core/kern/command.c

index c236be13af7c1d2430dd8550e93e7346fad40c51..7f8cb3f676b8a05dac455e3eb5d7073818fbbd77 100644 (file)
@@ -139,6 +139,9 @@ grub_register_extcmd_lockdown (const char *name, grub_extcmd_func_t func,
 void
 grub_unregister_extcmd (grub_extcmd_t ext)
 {
+  if (ext == NULL)
+    return;
+
   grub_unregister_command (ext->cmd);
   grub_free (ext);
 }
index 5812e131cf46320ca7e4ff33572aeb01ee50a609..a1b4c81a9c3dca35665ceafc9c28862d0ced7505 100644 (file)
@@ -104,6 +104,9 @@ grub_register_command_lockdown (const char *name,
 void
 grub_unregister_command (grub_command_t cmd)
 {
+  if (cmd == NULL)
+    return;
+
   if ((cmd->prio & GRUB_COMMAND_FLAG_ACTIVE) && (cmd->next))
     cmd->next->prio |= GRUB_COMMAND_FLAG_ACTIVE;
   grub_list_remove (GRUB_AS_LIST (cmd));