dcavalca / rpms / grub2

Forked from rpms/grub2 3 years ago
Clone

Blame SOURCES/0362-kern-partition-Check-for-NULL-before-dereferencing-i.patch

b1bcb2
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
b1bcb2
From: Darren Kenny <darren.kenny@oracle.com>
b1bcb2
Date: Fri, 23 Oct 2020 09:49:59 +0000
b1bcb2
Subject: [PATCH] kern/partition: Check for NULL before dereferencing input
b1bcb2
 string
b1bcb2
b1bcb2
There is the possibility that the value of str comes from an external
b1bcb2
source and continuing to use it before ever checking its validity is
b1bcb2
wrong. So, needs fixing.
b1bcb2
b1bcb2
Additionally, drop unneeded part initialization.
b1bcb2
b1bcb2
Fixes: CID 292444
b1bcb2
b1bcb2
Signed-off-by: Darren Kenny <darren.kenny@oracle.com>
b1bcb2
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
b1bcb2
---
b1bcb2
 grub-core/kern/partition.c | 5 ++++-
b1bcb2
 1 file changed, 4 insertions(+), 1 deletion(-)
b1bcb2
b1bcb2
diff --git a/grub-core/kern/partition.c b/grub-core/kern/partition.c
b1bcb2
index e499147cbcb..b10a184e3fa 100644
b1bcb2
--- a/grub-core/kern/partition.c
b1bcb2
+++ b/grub-core/kern/partition.c
b1bcb2
@@ -109,11 +109,14 @@ grub_partition_map_probe (const grub_partition_map_t partmap,
b1bcb2
 grub_partition_t
b1bcb2
 grub_partition_probe (struct grub_disk *disk, const char *str)
b1bcb2
 {
b1bcb2
-  grub_partition_t part = 0;
b1bcb2
+  grub_partition_t part;
b1bcb2
   grub_partition_t curpart = 0;
b1bcb2
   grub_partition_t tail;
b1bcb2
   const char *ptr;
b1bcb2
 
b1bcb2
+  if (str == NULL)
b1bcb2
+    return 0;
b1bcb2
+
b1bcb2
   part = tail = disk->partition;
b1bcb2
 
b1bcb2
   for (ptr = str; *ptr;)