0005-fs-tar-Initialize-name-in-grub_cpio_find_file.patch 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. From 2233c409ada20d1ab4a6a00a50cdde35e5a36589 Mon Sep 17 00:00:00 2001
  2. From: B Horn <b@horn.uk>
  3. Date: Sun, 12 May 2024 02:47:54 +0100
  4. Subject: [PATCH] fs/tar: Initialize name in grub_cpio_find_file()
  5. It was possible to iterate through grub_cpio_find_file() without
  6. allocating name and not setting mode to GRUB_ARCHELP_ATTR_END, which
  7. would cause the uninitialized value for name to be used as an argument
  8. for canonicalize() in grub_archelp_dir().
  9. Reported-by: B Horn <b@horn.uk>
  10. Signed-off-by: B Horn <b@horn.uk>
  11. Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
  12. Upstream: 2c8ac08c99466c0697f704242363fc687f492a0d
  13. Signed-off-by: Thomas Petazzoni <thomas.petazzoni@bootlin.com>
  14. ---
  15. grub-core/fs/tar.c | 5 +++++
  16. 1 file changed, 5 insertions(+)
  17. diff --git a/grub-core/fs/tar.c b/grub-core/fs/tar.c
  18. index c551ed6b5..646bce5eb 100644
  19. --- a/grub-core/fs/tar.c
  20. +++ b/grub-core/fs/tar.c
  21. @@ -78,6 +78,7 @@ grub_cpio_find_file (struct grub_archelp_data *data, char **name,
  22. int reread = 0, have_longname = 0, have_longlink = 0;
  23. data->hofs = data->next_hofs;
  24. + *name = NULL;
  25. for (reread = 0; reread < 3; reread++)
  26. {
  27. @@ -202,6 +203,10 @@ grub_cpio_find_file (struct grub_archelp_data *data, char **name,
  28. }
  29. return GRUB_ERR_NONE;
  30. }
  31. +
  32. + if (*name == NULL)
  33. + return grub_error (GRUB_ERR_BAD_FS, "invalid tar archive");
  34. +
  35. return GRUB_ERR_NONE;
  36. }
  37. --
  38. 2.50.1