From 77e2ceb79a240d54445355317d2f4569c0550ae2 Mon Sep 17 00:00:00 2001 From: Avnish Chouhan Date: Tue, 28 Oct 2025 22:02:01 +0530 Subject: [PATCH] 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 Reviewed-by: Sudhakar Kuppusamy Reviewed-by: Daniel Kiper --- grub-core/mmap/mmap.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/grub-core/mmap/mmap.c b/grub-core/mmap/mmap.c index c8c8312c5..8f03b7765 100644 --- a/grub-core/mmap/mmap.c +++ b/grub-core/mmap/mmap.c @@ -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;