nalika / rpms / grub2

Forked from rpms/grub2 2 years ago
Clone

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

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