1From 2298f6e0d951251bb9ca97d891d1bc8b74515f8c Mon Sep 17 00:00:00 2001 2From: Darren Kenny <darren.kenny@oracle.com> 3Date: Fri, 23 Oct 2020 17:09:31 +0000 4Subject: [PATCH] hfsplus: Check that the volume name length is valid 5 6HFS+ documentation suggests that the maximum filename and volume name is 7255 Unicode characters in length. 8 9So, when converting from big-endian to little-endian, we should ensure 10that the name of the volume has a length that is between 0 and 255, 11inclusive. 12 13Fixes: CID 73641 14 15Signed-off-by: Darren Kenny <darren.kenny@oracle.com> 16Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com> 17Signed-off-by: Stefan Sørensen <stefan.sorensen@spectralink.com> 18--- 19 grub-core/fs/hfsplus.c | 9 +++++++++ 20 1 file changed, 9 insertions(+) 21 22diff --git a/grub-core/fs/hfsplus.c b/grub-core/fs/hfsplus.c 23index 9c4e4c8..8fe7c12 100644 24--- a/grub-core/fs/hfsplus.c 25+++ b/grub-core/fs/hfsplus.c 26@@ -1012,6 +1012,15 @@ grub_hfsplus_label (grub_device_t device, char **label) 27 grub_hfsplus_btree_recptr (&data->catalog_tree, node, ptr); 28 29 label_len = grub_be_to_cpu16 (catkey->namelen); 30+ 31+ /* Ensure that the length is >= 0. */ 32+ if (label_len < 0) 33+ label_len = 0; 34+ 35+ /* Ensure label length is at most 255 Unicode characters. */ 36+ if (label_len > 255) 37+ label_len = 255; 38+ 39 label_name = grub_calloc (label_len, sizeof (*label_name)); 40 if (!label_name) 41 { 42-- 432.14.2 44 45