1*4882a593SmuzhiyunFrom 5d5391b0a05abe76e04c1eb68dcc6cbef5326c4a Mon Sep 17 00:00:00 2001 2*4882a593SmuzhiyunFrom: Darren Kenny <darren.kenny@oracle.com> 3*4882a593SmuzhiyunDate: Tue, 8 Dec 2020 21:47:13 +0000 4*4882a593SmuzhiyunSubject: [PATCH] loader/bsd: Check for NULL arg up-front 5*4882a593Smuzhiyun 6*4882a593SmuzhiyunThe code in the next block suggests that it is possible for .set to be 7*4882a593Smuzhiyuntrue but .arg may still be NULL. 8*4882a593Smuzhiyun 9*4882a593SmuzhiyunThis code assumes that it is never NULL, yet later is testing if it is 10*4882a593SmuzhiyunNULL - that is inconsistent. 11*4882a593Smuzhiyun 12*4882a593SmuzhiyunSo we should check first if .arg is not NULL, and remove this check that 13*4882a593Smuzhiyunis being flagged by Coverity since it is no longer required. 14*4882a593Smuzhiyun 15*4882a593SmuzhiyunFixes: CID 292471 16*4882a593Smuzhiyun 17*4882a593SmuzhiyunSigned-off-by: Darren Kenny <darren.kenny@oracle.com> 18*4882a593SmuzhiyunReviewed-by: Daniel Kiper <daniel.kiper@oracle.com> 19*4882a593SmuzhiyunSigned-off-by: Stefan Sørensen <stefan.sorensen@spectralink.com> 20*4882a593Smuzhiyun--- 21*4882a593Smuzhiyun grub-core/loader/i386/bsd.c | 4 ++-- 22*4882a593Smuzhiyun 1 file changed, 2 insertions(+), 2 deletions(-) 23*4882a593Smuzhiyun 24*4882a593Smuzhiyundiff --git a/grub-core/loader/i386/bsd.c b/grub-core/loader/i386/bsd.c 25*4882a593Smuzhiyunindex b92cbe9..8432283 100644 26*4882a593Smuzhiyun--- a/grub-core/loader/i386/bsd.c 27*4882a593Smuzhiyun+++ b/grub-core/loader/i386/bsd.c 28*4882a593Smuzhiyun@@ -1605,7 +1605,7 @@ grub_cmd_openbsd (grub_extcmd_context_t ctxt, int argc, char *argv[]) 29*4882a593Smuzhiyun kernel_type = KERNEL_TYPE_OPENBSD; 30*4882a593Smuzhiyun bootflags = grub_bsd_parse_flags (ctxt->state, openbsd_flags); 31*4882a593Smuzhiyun 32*4882a593Smuzhiyun- if (ctxt->state[OPENBSD_ROOT_ARG].set) 33*4882a593Smuzhiyun+ if (ctxt->state[OPENBSD_ROOT_ARG].set && ctxt->state[OPENBSD_ROOT_ARG].arg != NULL) 34*4882a593Smuzhiyun { 35*4882a593Smuzhiyun const char *arg = ctxt->state[OPENBSD_ROOT_ARG].arg; 36*4882a593Smuzhiyun unsigned type, unit, part; 37*4882a593Smuzhiyun@@ -1622,7 +1622,7 @@ grub_cmd_openbsd (grub_extcmd_context_t ctxt, int argc, char *argv[]) 38*4882a593Smuzhiyun "unknown disk type name"); 39*4882a593Smuzhiyun 40*4882a593Smuzhiyun unit = grub_strtoul (arg, (char **) &arg, 10); 41*4882a593Smuzhiyun- if (! (arg && *arg >= 'a' && *arg <= 'z')) 42*4882a593Smuzhiyun+ if (! (*arg >= 'a' && *arg <= 'z')) 43*4882a593Smuzhiyun return grub_error (GRUB_ERR_BAD_ARGUMENT, 44*4882a593Smuzhiyun "only device specifications of form " 45*4882a593Smuzhiyun "<type><number><lowercase letter> are supported"); 46*4882a593Smuzhiyun-- 47*4882a593Smuzhiyun2.14.2 48*4882a593Smuzhiyun 49