]> git.ipfire.org Git - thirdparty/grub.git/commitdiff
mmap/mmap: Add missing grub_malloc() failure check
authorAvnish Chouhan <avnish@linux.ibm.com>
Tue, 28 Oct 2025 16:32:01 +0000 (22:02 +0530)
committerDaniel Kiper <daniel.kiper@oracle.com>
Thu, 6 Nov 2025 15:56:06 +0000 (16:56 +0100)
This patch adds a NULL check after grub_malloc() call. Missing a failure
check after calling grub_malloc() can lead to undefined behavior. If the
allocation fails and returns NULL subsequent dereferencing or writing to
the pointer will likely result in a runtime error such as a segmentation
fault.

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/mmap/mmap.c

index c8c8312c56f2651db2cdd05f19d7f079d5dccc99..8f03b7765330cf3a2919665f5af5a53719d90398 100644 (file)
@@ -242,6 +242,9 @@ grub_mmap_iterate (grub_memory_hook_t hook, void *hook_data)
          else
            {
              struct mm_list *n = grub_malloc (sizeof (*n));
+              if (n == NULL)
+                return grub_errno;
+
              n->val = ctx.scanline_events[i].memtype;
              n->present = 1;
              n->next = present[ctx.scanline_events[i].priority].next;