From: Daniel Axtens Date: Fri, 22 Jan 2021 05:18:26 +0000 (+1100) Subject: script/execute: Don't crash on a "for" loop with no items X-Git-Tag: grub-2.06-rc1~79 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=0a05f88e2bb33ed2a0cfd93f481f471efb7791aa;p=thirdparty%2Fgrub.git script/execute: Don't crash on a "for" loop with no items 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 Reviewed-by: Daniel Kiper --- diff --git a/grub-core/script/execute.c b/grub-core/script/execute.c index b88765f1d..25158407d 100644 --- a/grub-core/script/execute.c +++ b/grub-core/script/execute.c @@ -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))