From: Avnish Chouhan Date: Tue, 28 Oct 2025 16:32:01 +0000 (+0530) Subject: mmap/mmap: Add missing grub_malloc() failure check X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=77e2ceb79a240d54445355317d2f4569c0550ae2;p=thirdparty%2Fgrub.git 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 --- 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;