From: Andrei Borzenkov Date: Sat, 9 Jan 2016 15:15:27 +0000 (+0300) Subject: rescue_parser: restructure code to avoid Coverity false positive X-Git-Tag: 2.02-beta3~99 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=bd60f5a207f9d8e594520d32f909aafdb4f5fffb;p=thirdparty%2Fgrub.git rescue_parser: restructure code to avoid Coverity false positive If line contains single word, line and argv[0] are aliases, so no NULL dereference is possible, but Coverity does not know it. Change code to avoid ambiguity and also remove redundant call to grub_strchr. CID: 86725 --- diff --git a/grub-core/kern/rescue_parser.c b/grub-core/kern/rescue_parser.c index ab3d04160..633836699 100644 --- a/grub-core/kern/rescue_parser.c +++ b/grub-core/kern/rescue_parser.c @@ -43,13 +43,17 @@ grub_rescue_parse_line (char *line, /* In case of an assignment set the environment accordingly instead of calling a function. */ - if (n == 1 && grub_strchr (line, '=')) + if (n == 1) { char *val = grub_strchr (args[0], '='); - val[0] = 0; - grub_env_set (args[0], val + 1); - val[0] = '='; - goto quit; + + if (val) + { + val[0] = 0; + grub_env_set (args[0], val + 1); + val[0] = '='; + goto quit; + } } /* Get the command name. */ @@ -72,6 +76,7 @@ grub_rescue_parse_line (char *line, } quit: + /* Arguments are returned in single memory chunk separated by zeroes */ grub_free (args[0]); grub_free (args);