net: Check if returned pointer for allocated memory is NULL
authorAlec Brown <alec.r.brown@oracle.com>
Wed, 22 Jan 2025 18:04:44 +0000 (18:04 +0000)
committerFelix Zielcke <fzielcke@z-51.de>
Wed, 11 Jun 2025 15:42:34 +0000 (17:42 +0200)
When using grub_malloc(), the function can fail if we are out of memory.
After allocating memory we should check if this function returned NULL
and handle this error if it did.

Signed-off-by: Alec Brown <alec.r.brown@oracle.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
Gbp-Pq: Topic cve-2025-jan
Gbp-Pq: Name net-Check-if-returned-pointer-for-allocated-memory-is-NUL.patch

grub-core/net/net.c

index fb41d271557ebfaaa77c974c60c2506f0df8505f..7ec4823b5b42929dbf60bc80d5d709a8defce611 100644 (file)
@@ -230,6 +230,11 @@ grub_net_ipv6_get_slaac (struct grub_net_card *card,
     }
 
   slaac->name = grub_malloc (sz);
+  if (slaac->name == NULL)
+    {
+      grub_free (slaac);
+      return NULL;
+    }
   ptr = grub_stpcpy (slaac->name, card->name);
   if (grub_net_hwaddr_cmp (&card->default_address, hwaddr) != 0)
     {