dcavalca / rpms / grub2

Forked from rpms/grub2 3 years ago
Clone

Blame SOURCES/0388-net-net-Fix-possible-dereference-to-of-a-NULL-pointe.patch

468bd4
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
468bd4
From: Darren Kenny <darren.kenny@oracle.com>
468bd4
Date: Fri, 27 Nov 2020 15:10:26 +0000
468bd4
Subject: [PATCH] net/net: Fix possible dereference to of a NULL pointer
468bd4
468bd4
It is always possible that grub_zalloc() could fail, so we should check for
468bd4
a NULL return. Otherwise we run the risk of dereferencing a NULL pointer.
468bd4
468bd4
Fixes: CID 296221
468bd4
468bd4
Signed-off-by: Darren Kenny <darren.kenny@oracle.com>
468bd4
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
468bd4
---
468bd4
 grub-core/net/net.c | 9 +++++++--
468bd4
 1 file changed, 7 insertions(+), 2 deletions(-)
468bd4
468bd4
diff --git a/grub-core/net/net.c b/grub-core/net/net.c
468bd4
index 1fd104aeaf2..a27c53eee1c 100644
468bd4
--- a/grub-core/net/net.c
468bd4
+++ b/grub-core/net/net.c
468bd4
@@ -89,8 +89,13 @@ grub_net_link_layer_add_address (struct grub_net_card *card,
468bd4
 
468bd4
   /* Add sender to cache table.  */
468bd4
   if (card->link_layer_table == NULL)
468bd4
-    card->link_layer_table = grub_zalloc (LINK_LAYER_CACHE_SIZE
468bd4
-					  * sizeof (card->link_layer_table[0]));
468bd4
+    {
468bd4
+      card->link_layer_table = grub_zalloc (LINK_LAYER_CACHE_SIZE
468bd4
+					    * sizeof (card->link_layer_table[0]));
468bd4
+      if (card->link_layer_table == NULL)
468bd4
+	return;
468bd4
+    }
468bd4
+
468bd4
   entry = &(card->link_layer_table[card->new_ll_entry]);
468bd4
   entry->avail = 1;
468bd4
   grub_memcpy (&entry->ll_address, ll, sizeof (entry->ll_address));