grub-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[SECURITY PATCH 053/117] loader/bsd: Check for NULL arg up-front


From: Daniel Kiper
Subject: [SECURITY PATCH 053/117] loader/bsd: Check for NULL arg up-front
Date: Tue, 2 Mar 2021 19:01:00 +0100

From: Darren Kenny <darren.kenny@oracle.com>

The code in the next block suggests that it is possible for .set to be
true but .arg may still be NULL.

This code assumes that it is never NULL, yet later is testing if it is
NULL - that is inconsistent.

So we should check first if .arg is not NULL, and remove this check that
is being flagged by Coverity since it is no longer required.

Fixes: CID 292471

Signed-off-by: Darren Kenny <darren.kenny@oracle.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
---
 grub-core/loader/i386/bsd.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/grub-core/loader/i386/bsd.c b/grub-core/loader/i386/bsd.c
index f5bf7f89e..d89ff0a7a 100644
--- a/grub-core/loader/i386/bsd.c
+++ b/grub-core/loader/i386/bsd.c
@@ -1605,7 +1605,7 @@ grub_cmd_openbsd (grub_extcmd_context_t ctxt, int argc, 
char *argv[])
   kernel_type = KERNEL_TYPE_OPENBSD;
   bootflags = grub_bsd_parse_flags (ctxt->state, openbsd_flags);
 
-  if (ctxt->state[OPENBSD_ROOT_ARG].set)
+  if (ctxt->state[OPENBSD_ROOT_ARG].set && ctxt->state[OPENBSD_ROOT_ARG].arg 
!= NULL)
     {
       const char *arg = ctxt->state[OPENBSD_ROOT_ARG].arg;
       unsigned type, unit, part;
@@ -1622,7 +1622,7 @@ grub_cmd_openbsd (grub_extcmd_context_t ctxt, int argc, 
char *argv[])
                           "unknown disk type name");
 
       unit = grub_strtoul (arg, &arg, 10);
-      if (! (arg && *arg >= 'a' && *arg <= 'z'))
+      if (! (*arg >= 'a' && *arg <= 'z'))
        return grub_error (GRUB_ERR_BAD_ARGUMENT,
                           "only device specifications of form "
                           "<type><number><lowercase letter> are supported");
-- 
2.11.0




reply via email to

[Prev in Thread] Current Thread [Next in Thread]