]> git.ipfire.org Git - thirdparty/grub.git/commitdiff
script/execute: Don't crash on a "for" loop with no items
authorDaniel Axtens <dja@axtens.net>
Fri, 22 Jan 2021 05:18:26 +0000 (16:18 +1100)
committerDaniel Kiper <daniel.kiper@oracle.com>
Tue, 2 Mar 2021 14:54:17 +0000 (15:54 +0100)
The following crashes the parser:

  for x in; do
  0
  done

This is because grub_script_arglist_to_argv() doesn't consider the
possibility that arglist is NULL. Catch that explicitly.

This avoids a NULL pointer dereference.

Signed-off-by: Daniel Axtens <dja@axtens.net>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
grub-core/script/execute.c

index b88765f1df7ff92c248797a613a3537c4c0bbd09..25158407dd82cca7be467b918cdfb17620ef8b02 100644 (file)
@@ -624,6 +624,9 @@ grub_script_arglist_to_argv (struct grub_script_arglist *arglist,
   struct grub_script_arg *arg = 0;
   struct grub_script_argv result = { 0, 0, 0 };
 
+  if (arglist == NULL)
+    return 1;
+
   for (; arglist && arglist->arg; arglist = arglist->next)
     {
       if (grub_script_argv_next (&result))