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

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