0096-script-execute-Don-t-crash-on-a-for-loop-with-no-ite.patch 1.2 KB

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