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

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