dcavalca / rpms / grub2

Forked from rpms/grub2 3 years ago
Clone

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

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