2
1

0032-commands-ls-Fix-NULL-dereference.patch 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. From 322d82364cc0db30b1ae4fc0adfdf7a43adc91ef Mon Sep 17 00:00:00 2001
  2. From: B Horn <b@horn.uk>
  3. Date: Sun, 12 May 2024 11:08:23 +0100
  4. Subject: [PATCH] commands/ls: Fix NULL dereference
  5. The grub_strrchr() may return NULL when the dirname do not contain "/".
  6. This can happen on broken filesystems.
  7. Reported-by: B Horn <b@horn.uk>
  8. Signed-off-by: B Horn <b@horn.uk>
  9. Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
  10. Upstream: 0bf56bce47489c059e50e61a3db7f682d8c44b56
  11. Signed-off-by: Thomas Petazzoni <thomas.petazzoni@bootlin.com>
  12. ---
  13. grub-core/commands/ls.c | 6 +++++-
  14. 1 file changed, 5 insertions(+), 1 deletion(-)
  15. diff --git a/grub-core/commands/ls.c b/grub-core/commands/ls.c
  16. index 6a1c7f5d3..f660946a2 100644
  17. --- a/grub-core/commands/ls.c
  18. +++ b/grub-core/commands/ls.c
  19. @@ -241,7 +241,11 @@ grub_ls_list_files (char *dirname, int longlist, int all, int human)
  20. grub_file_close (file);
  21. - p = grub_strrchr (dirname, '/') + 1;
  22. + p = grub_strrchr (dirname, '/');
  23. + if (p == NULL)
  24. + goto fail;
  25. + ++p;
  26. +
  27. ctx.dirname = grub_strndup (dirname, p - dirname);
  28. if (ctx.dirname == NULL)
  29. goto fail;
  30. --
  31. 2.50.1