nalika / rpms / grub2

Forked from rpms/grub2 2 years ago
Clone

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

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