]> git.ipfire.org Git - thirdparty/grub.git/commitdiff
net/net: Fix possible dereference to of a NULL pointer
authorDarren Kenny <darren.kenny@oracle.com>
Fri, 27 Nov 2020 15:10:26 +0000 (15:10 +0000)
committerDaniel Kiper <daniel.kiper@oracle.com>
Tue, 2 Mar 2021 14:54:15 +0000 (15:54 +0100)
It is always possible that grub_zalloc() could fail, so we should check for
a NULL return. Otherwise we run the risk of dereferencing a NULL pointer.

Fixes: CID 296221
Signed-off-by: Darren Kenny <darren.kenny@oracle.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
grub-core/net/net.c

index 04ad106827cfe50d44abe3f82a209ee4dcf1e9de..4d3eb5c1a52373693a1512b7a759746712c794d4 100644 (file)
@@ -86,8 +86,13 @@ grub_net_link_layer_add_address (struct grub_net_card *card,
 
   /* Add sender to cache table.  */
   if (card->link_layer_table == NULL)
-    card->link_layer_table = grub_zalloc (LINK_LAYER_CACHE_SIZE
-                                         * sizeof (card->link_layer_table[0]));
+    {
+      card->link_layer_table = grub_zalloc (LINK_LAYER_CACHE_SIZE
+                                           * sizeof (card->link_layer_table[0]));
+      if (card->link_layer_table == NULL)
+       return;
+    }
+
   entry = &(card->link_layer_table[card->new_ll_entry]);
   entry->avail = 1;
   grub_memcpy (&entry->ll_address, ll, sizeof (entry->ll_address));