nalika / rpms / grub2

Forked from rpms/grub2 2 years ago
Clone

Blame SOURCES/0421-loader-bsd-Check-for-NULL-arg-up-front.patch

9723a8
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
9723a8
From: Darren Kenny <darren.kenny@oracle.com>
9723a8
Date: Tue, 8 Dec 2020 21:47:13 +0000
9723a8
Subject: [PATCH] loader/bsd: Check for NULL arg up-front
9723a8
9723a8
The code in the next block suggests that it is possible for .set to be
9723a8
true but .arg may still be NULL.
9723a8
9723a8
This code assumes that it is never NULL, yet later is testing if it is
9723a8
NULL - that is inconsistent.
9723a8
9723a8
So we should check first if .arg is not NULL, and remove this check that
9723a8
is being flagged by Coverity since it is no longer required.
9723a8
9723a8
Fixes: CID 292471
9723a8
9723a8
Signed-off-by: Darren Kenny <darren.kenny@oracle.com>
9723a8
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
9723a8
---
9723a8
 grub-core/loader/i386/bsd.c | 4 ++--
9723a8
 1 file changed, 2 insertions(+), 2 deletions(-)
9723a8
9723a8
diff --git a/grub-core/loader/i386/bsd.c b/grub-core/loader/i386/bsd.c
3efed6
index 45a71509956..b5ab848ee44 100644
9723a8
--- a/grub-core/loader/i386/bsd.c
9723a8
+++ b/grub-core/loader/i386/bsd.c
3efed6
@@ -1606,7 +1606,7 @@ grub_cmd_openbsd (grub_extcmd_context_t ctxt, int argc, char *argv[])
9723a8
   kernel_type = KERNEL_TYPE_OPENBSD;
9723a8
   bootflags = grub_bsd_parse_flags (ctxt->state, openbsd_flags);
9723a8
 
9723a8
-  if (ctxt->state[OPENBSD_ROOT_ARG].set)
9723a8
+  if (ctxt->state[OPENBSD_ROOT_ARG].set && ctxt->state[OPENBSD_ROOT_ARG].arg != NULL)
9723a8
     {
9723a8
       const char *arg = ctxt->state[OPENBSD_ROOT_ARG].arg;
9723a8
       unsigned type, unit, part;
3efed6
@@ -1623,7 +1623,7 @@ grub_cmd_openbsd (grub_extcmd_context_t ctxt, int argc, char *argv[])
9723a8
 			   "unknown disk type name");
9723a8
 
9723a8
       unit = grub_strtoul (arg, (char **) &arg, 10);
9723a8
-      if (! (arg && *arg >= 'a' && *arg <= 'z'))
9723a8
+      if (! (*arg >= 'a' && *arg <= 'z'))
9723a8
 	return grub_error (GRUB_ERR_BAD_ARGUMENT,
9723a8
 			   "only device specifications of form "
9723a8
 			   "<type><number><lowercase letter> are supported");