nalika / rpms / grub2

Forked from rpms/grub2 2 years ago
Clone

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

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