1From 0a05f88e2bb33ed2a0cfd93f481f471efb7791aa Mon Sep 17 00:00:00 2001 2From: Daniel Axtens <dja@axtens.net> 3Date: Fri, 22 Jan 2021 16:18:26 +1100 4Subject: [PATCH] script/execute: Don't crash on a "for" loop with no items 5 6The following crashes the parser: 7 8 for x in; do 9 0 10 done 11 12This is because grub_script_arglist_to_argv() doesn't consider the 13possibility that arglist is NULL. Catch that explicitly. 14 15This avoids a NULL pointer dereference. 16 17Signed-off-by: Daniel Axtens <dja@axtens.net> 18Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com> 19Signed-off-by: Stefan Sørensen <stefan.sorensen@spectralink.com> 20--- 21 grub-core/script/execute.c | 3 +++ 22 1 file changed, 3 insertions(+) 23 24diff --git a/grub-core/script/execute.c b/grub-core/script/execute.c 25index 23d34bd..31dac25 100644 26--- a/grub-core/script/execute.c 27+++ b/grub-core/script/execute.c 28@@ -624,6 +624,9 @@ grub_script_arglist_to_argv (struct grub_script_arglist *arglist, 29 struct grub_script_arg *arg = 0; 30 struct grub_script_argv result = { 0, 0, 0 }; 31 32+ if (arglist == NULL) 33+ return 1; 34+ 35 for (; arglist && arglist->arg; arglist = arglist->next) 36 { 37 if (grub_script_argv_next (&result)) 38-- 392.14.2 40 41