]> git.ipfire.org Git - thirdparty/grub.git/commitdiff
hfsplus: Check that the volume name length is valid
authorDarren Kenny <darren.kenny@oracle.com>
Fri, 23 Oct 2020 17:09:31 +0000 (17:09 +0000)
committerDaniel Kiper <daniel.kiper@oracle.com>
Tue, 2 Mar 2021 14:54:16 +0000 (15:54 +0100)
HFS+ documentation suggests that the maximum filename and volume name is
255 Unicode characters in length.

So, when converting from big-endian to little-endian, we should ensure
that the name of the volume has a length that is between 0 and 255,
inclusive.

Fixes: CID 73641
Signed-off-by: Darren Kenny <darren.kenny@oracle.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
grub-core/fs/hfsplus.c

index 9c4e4c88c99378a746c5003ee33e6b173efb5a02..8fe7c12ed8073742f46c543a558a0bdddf90fa81 100644 (file)
@@ -1012,6 +1012,15 @@ grub_hfsplus_label (grub_device_t device, char **label)
     grub_hfsplus_btree_recptr (&data->catalog_tree, node, ptr);
 
   label_len = grub_be_to_cpu16 (catkey->namelen);
+
+  /* Ensure that the length is >= 0. */
+  if (label_len < 0)
+    label_len = 0;
+
+  /* Ensure label length is at most 255 Unicode characters. */
+  if (label_len > 255)
+    label_len = 255;
+
   label_name = grub_calloc (label_len, sizeof (*label_name));
   if (!label_name)
     {