1*4882a593SmuzhiyunFrom 03f2515ae0c503406f1a99a2178405049c6555db Mon Sep 17 00:00:00 2001
2*4882a593SmuzhiyunFrom: Darren Kenny <darren.kenny@oracle.com>
3*4882a593SmuzhiyunDate: Fri, 27 Nov 2020 15:10:26 +0000
4*4882a593SmuzhiyunSubject: [PATCH] net/net: Fix possible dereference to of a NULL pointer
5*4882a593Smuzhiyun
6*4882a593SmuzhiyunIt is always possible that grub_zalloc() could fail, so we should check for
7*4882a593Smuzhiyuna NULL return. Otherwise we run the risk of dereferencing a NULL pointer.
8*4882a593Smuzhiyun
9*4882a593SmuzhiyunFixes: CID 296221
10*4882a593Smuzhiyun
11*4882a593SmuzhiyunSigned-off-by: Darren Kenny <darren.kenny@oracle.com>
12*4882a593SmuzhiyunReviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
13*4882a593SmuzhiyunSigned-off-by: Stefan Sørensen <stefan.sorensen@spectralink.com>
14*4882a593Smuzhiyun---
15*4882a593Smuzhiyun grub-core/net/net.c | 9 +++++++--
16*4882a593Smuzhiyun 1 file changed, 7 insertions(+), 2 deletions(-)
17*4882a593Smuzhiyun
18*4882a593Smuzhiyundiff --git a/grub-core/net/net.c b/grub-core/net/net.c
19*4882a593Smuzhiyunindex 38f19df..7c2cdf2 100644
20*4882a593Smuzhiyun--- a/grub-core/net/net.c
21*4882a593Smuzhiyun+++ b/grub-core/net/net.c
22*4882a593Smuzhiyun@@ -86,8 +86,13 @@ grub_net_link_layer_add_address (struct grub_net_card *card,
23*4882a593Smuzhiyun
24*4882a593Smuzhiyun   /* Add sender to cache table.  */
25*4882a593Smuzhiyun   if (card->link_layer_table == NULL)
26*4882a593Smuzhiyun-    card->link_layer_table = grub_zalloc (LINK_LAYER_CACHE_SIZE
27*4882a593Smuzhiyun-					  * sizeof (card->link_layer_table[0]));
28*4882a593Smuzhiyun+    {
29*4882a593Smuzhiyun+      card->link_layer_table = grub_zalloc (LINK_LAYER_CACHE_SIZE
30*4882a593Smuzhiyun+					    * sizeof (card->link_layer_table[0]));
31*4882a593Smuzhiyun+      if (card->link_layer_table == NULL)
32*4882a593Smuzhiyun+	return;
33*4882a593Smuzhiyun+    }
34*4882a593Smuzhiyun+
35*4882a593Smuzhiyun   entry = &(card->link_layer_table[card->new_ll_entry]);
36*4882a593Smuzhiyun   entry->avail = 1;
37*4882a593Smuzhiyun   grub_memcpy (&entry->ll_address, ll, sizeof (entry->ll_address));
38*4882a593Smuzhiyun--
39*4882a593Smuzhiyun2.14.2
40*4882a593Smuzhiyun
41