0067-hfsplus-Check-that-the-volume-name-length-is-valid.patch 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. From 2298f6e0d951251bb9ca97d891d1bc8b74515f8c Mon Sep 17 00:00:00 2001
  2. From: Darren Kenny <darren.kenny@oracle.com>
  3. Date: Fri, 23 Oct 2020 17:09:31 +0000
  4. Subject: [PATCH] hfsplus: Check that the volume name length is valid
  5. HFS+ documentation suggests that the maximum filename and volume name is
  6. 255 Unicode characters in length.
  7. So, when converting from big-endian to little-endian, we should ensure
  8. that the name of the volume has a length that is between 0 and 255,
  9. inclusive.
  10. Fixes: CID 73641
  11. Signed-off-by: Darren Kenny <darren.kenny@oracle.com>
  12. Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
  13. Signed-off-by: Stefan Sørensen <stefan.sorensen@spectralink.com>
  14. ---
  15. grub-core/fs/hfsplus.c | 9 +++++++++
  16. 1 file changed, 9 insertions(+)
  17. diff --git a/grub-core/fs/hfsplus.c b/grub-core/fs/hfsplus.c
  18. index 9c4e4c8..8fe7c12 100644
  19. --- a/grub-core/fs/hfsplus.c
  20. +++ b/grub-core/fs/hfsplus.c
  21. @@ -1012,6 +1012,15 @@ grub_hfsplus_label (grub_device_t device, char **label)
  22. grub_hfsplus_btree_recptr (&data->catalog_tree, node, ptr);
  23. label_len = grub_be_to_cpu16 (catkey->namelen);
  24. +
  25. + /* Ensure that the length is >= 0. */
  26. + if (label_len < 0)
  27. + label_len = 0;
  28. +
  29. + /* Ensure label length is at most 255 Unicode characters. */
  30. + if (label_len > 255)
  31. + label_len = 255;
  32. +
  33. label_name = grub_calloc (label_len, sizeof (*label_name));
  34. if (!label_name)
  35. {
  36. --
  37. 2.14.2