From: Alec Brown Date: Wed, 22 Jan 2025 18:04:44 +0000 (+0000) Subject: net: Check if returned pointer for allocated memory is NULL X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=1c06ec900591d1fab6fbacf80dc010541d0a5ec8;p=thirdparty%2Fgrub.git 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 Reviewed-by: Daniel Kiper --- diff --git a/grub-core/net/net.c b/grub-core/net/net.c index 1abdc097f..6ea33d1cd 100644 --- a/grub-core/net/net.c +++ b/grub-core/net/net.c @@ -227,6 +227,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) {