]> git.ipfire.org Git - thirdparty/grub.git/commitdiff
rescue_parser: restructure code to avoid Coverity false positive
authorAndrei Borzenkov <arvidjaar@gmail.com>
Sat, 9 Jan 2016 15:15:27 +0000 (18:15 +0300)
committerAndrei Borzenkov <arvidjaar@gmail.com>
Sat, 9 Jan 2016 15:15:27 +0000 (18:15 +0300)
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

grub-core/kern/rescue_parser.c

index ab3d041600b8b004d214061e481c28c10816dc56..63383669977a0baa07ade8bbe25fea7323349d16 100644 (file)
@@ -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);