net: Check if returned pointer for allocated memory is NULL

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>
This commit is contained in:
Alec Brown authored and Daniel Kiper committed 2025-02-13 15:45:57 +01:00
1 parent dee2c14fd6
commit 1c06ec9005
1 file changed
+5
+5
View File
@@ -227,6 +227,11 @@ grub_net_ipv6_get_slaac (struct grub_net_card *card,
} }
slaac->name = grub_malloc (sz); slaac->name = grub_malloc (sz);
if (slaac->name == NULL)
{
grub_free (slaac);
return NULL;
}
ptr = grub_stpcpy (slaac->name, card->name); ptr = grub_stpcpy (slaac->name, card->name);
if (grub_net_hwaddr_cmp (&card->default_address, hwaddr) != 0) if (grub_net_hwaddr_cmp (&card->default_address, hwaddr) != 0)
{ {