]> git.ipfire.org Git - thirdparty/grub.git/commitdiff
efiemu/loadcore: Add grub_calloc() failure check
authorAvnish Chouhan <avnish@linux.ibm.com>
Thu, 27 Nov 2025 09:02:12 +0000 (14:32 +0530)
committerDaniel Kiper <daniel.kiper@oracle.com>
Sun, 21 Dec 2025 15:41:46 +0000 (16:41 +0100)
Add a failure check after grub_calloc() call. If grub_calloc()
fails, e.g., due to memory allocation failure, it returns NULL.
Then using grub_efiemu_elfsyms, which will be NULL, later will
result in a NULL pointer dereference.

Signed-off-by: Avnish Chouhan <avnish@linux.ibm.com>
Reviewed-by: Sudhakar Kuppusamy <sudhakar@linux.ibm.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
grub-core/efiemu/loadcore.c

index 2b924623f51b50a3d70e342196ab1d0afdc26b9d..4a091bee09a27931c34f4953bdcd20037483dd1a 100644 (file)
@@ -203,6 +203,9 @@ grub_efiemu_count_symbols (const Elf_Ehdr *e)
   grub_efiemu_elfsyms = (struct grub_efiemu_elf_sym *)
     grub_calloc (grub_efiemu_nelfsyms, sizeof (struct grub_efiemu_elf_sym));
 
+  if (grub_efiemu_elfsyms == NULL)
+    return grub_errno;
+
   /* Relocators */
   for (i = 0, s = (Elf_Shdr *) ((char *) e + e->e_shoff);
        i < e->e_shnum;