2
1

0060-script-execute-Fix-potential-underflow-and-NULL-dere.patch 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. From 6cb70802581222ba80a37c3e2fd4b8357a859dad Mon Sep 17 00:00:00 2001
  2. From: Lidong Chen <lidong.chen@oracle.com>
  3. Date: Wed, 29 Jan 2025 06:48:37 +0000
  4. Subject: [PATCH] script/execute: Fix potential underflow and NULL dereference
  5. The result is initialized to 0 in grub_script_arglist_to_argv().
  6. If the for loop condition is not met both result.args and result.argc
  7. remain 0 causing result.argc - 1 to underflow and/or result.args NULL
  8. dereference. Fix the issues by adding relevant checks.
  9. Fixes: CID 473880
  10. Signed-off-by: Lidong Chen <lidong.chen@oracle.com>
  11. Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
  12. Upstream: d13b6e8ebd10b4eb16698a002aa40258cf6e6f0e
  13. Signed-off-by: Thomas Petazzoni <thomas.petazzoni@bootlin.com>
  14. ---
  15. grub-core/script/execute.c | 3 +++
  16. 1 file changed, 3 insertions(+)
  17. diff --git a/grub-core/script/execute.c b/grub-core/script/execute.c
  18. index e1450f45d..a86e0051f 100644
  19. --- a/grub-core/script/execute.c
  20. +++ b/grub-core/script/execute.c
  21. @@ -760,6 +760,9 @@ cleanup:
  22. }
  23. }
  24. + if (result.args == NULL || result.argc == 0)
  25. + goto fail;
  26. +
  27. if (! result.args[result.argc - 1])
  28. result.argc--;
  29. --
  30. 2.50.1