0094-script-execute-Avoid-crash-when-using-outside-a-func.patch 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. From fe0586347ee46f927ae27bb9673532da9f5dead5 Mon Sep 17 00:00:00 2001
  2. From: Daniel Axtens <dja@axtens.net>
  3. Date: Mon, 11 Jan 2021 17:30:42 +1100
  4. Subject: [PATCH] script/execute: Avoid crash when using "$#" outside a
  5. function scope
  6. "$#" represents the number of arguments to a function. It is only
  7. defined in a function scope, where "scope" is non-NULL. Currently,
  8. if we attempt to evaluate "$#" outside a function scope, "scope" will
  9. be NULL and we will crash with a NULL pointer dereference.
  10. Do not attempt to count arguments for "$#" if "scope" is NULL. This
  11. will result in "$#" being interpreted as an empty string if evaluated
  12. outside a function scope.
  13. Signed-off-by: Daniel Axtens <dja@axtens.net>
  14. Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
  15. Signed-off-by: Stefan Sørensen <stefan.sorensen@spectralink.com>
  16. ---
  17. grub-core/script/execute.c | 2 +-
  18. 1 file changed, 1 insertion(+), 1 deletion(-)
  19. diff --git a/grub-core/script/execute.c b/grub-core/script/execute.c
  20. index 5ea2aef..23d34bd 100644
  21. --- a/grub-core/script/execute.c
  22. +++ b/grub-core/script/execute.c
  23. @@ -485,7 +485,7 @@ gettext_putvar (const char *str, grub_size_t len,
  24. return 0;
  25. /* Enough for any number. */
  26. - if (len == 1 && str[0] == '#')
  27. + if (len == 1 && str[0] == '#' && scope != NULL)
  28. {
  29. grub_snprintf (*ptr, 30, "%u", scope->argv.argc);
  30. *ptr += grub_strlen (*ptr);
  31. --
  32. 2.14.2