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

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