mmap/mmap: Add missing grub_malloc() failure check

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>
This commit is contained in:
Avnish Chouhan 2025-10-28 22:02:01 +05:30 committed by Daniel Kiper
parent 4cc22937e7
commit 77e2ceb79a

View 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;