Blame SOURCES/0404-hfsplus-Check-that-the-volume-name-length-is-valid.patch

468bd4
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
468bd4
From: Darren Kenny <darren.kenny@oracle.com>
468bd4
Date: Fri, 23 Oct 2020 17:09:31 +0000
468bd4
Subject: [PATCH] hfsplus: Check that the volume name length is valid
468bd4
468bd4
HFS+ documentation suggests that the maximum filename and volume name is
468bd4
255 Unicode characters in length.
468bd4
468bd4
So, when converting from big-endian to little-endian, we should ensure
468bd4
that the name of the volume has a length that is between 0 and 255,
468bd4
inclusive.
468bd4
468bd4
Fixes: CID 73641
468bd4
468bd4
Signed-off-by: Darren Kenny <darren.kenny@oracle.com>
468bd4
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
468bd4
---
468bd4
 grub-core/fs/hfsplus.c | 9 +++++++++
468bd4
 1 file changed, 9 insertions(+)
468bd4
468bd4
diff --git a/grub-core/fs/hfsplus.c b/grub-core/fs/hfsplus.c
030dc3
index e06bcbb9ba3..03a33ea2477 100644
468bd4
--- a/grub-core/fs/hfsplus.c
468bd4
+++ b/grub-core/fs/hfsplus.c
468bd4
@@ -1012,6 +1012,15 @@ grub_hfsplus_label (grub_device_t device, char **label)
468bd4
     grub_hfsplus_btree_recptr (&data->catalog_tree, node, ptr);
468bd4
 
468bd4
   label_len = grub_be_to_cpu16 (catkey->namelen);
468bd4
+
468bd4
+  /* Ensure that the length is >= 0. */
468bd4
+  if (label_len < 0)
468bd4
+    label_len = 0;
468bd4
+
468bd4
+  /* Ensure label length is at most 255 Unicode characters. */
468bd4
+  if (label_len > 255)
468bd4
+    label_len = 255;
468bd4
+
468bd4
   label_name = grub_calloc (label_len, sizeof (*label_name));
468bd4
   if (!label_name)
468bd4
     {