From: Darren Kenny Date: Fri, 23 Oct 2020 17:09:31 +0000 (+0000) Subject: hfsplus: Check that the volume name length is valid X-Git-Tag: grub-2.06-rc1~108 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=2298f6e0d951251bb9ca97d891d1bc8b74515f8c;p=thirdparty%2Fgrub.git hfsplus: Check that the volume name length is valid HFS+ documentation suggests that the maximum filename and volume name is 255 Unicode characters in length. So, when converting from big-endian to little-endian, we should ensure that the name of the volume has a length that is between 0 and 255, inclusive. Fixes: CID 73641 Signed-off-by: Darren Kenny Reviewed-by: Daniel Kiper --- diff --git a/grub-core/fs/hfsplus.c b/grub-core/fs/hfsplus.c index 9c4e4c88c..8fe7c12ed 100644 --- a/grub-core/fs/hfsplus.c +++ b/grub-core/fs/hfsplus.c @@ -1012,6 +1012,15 @@ grub_hfsplus_label (grub_device_t device, char **label) grub_hfsplus_btree_recptr (&data->catalog_tree, node, ptr); label_len = grub_be_to_cpu16 (catkey->namelen); + + /* Ensure that the length is >= 0. */ + if (label_len < 0) + label_len = 0; + + /* Ensure label length is at most 255 Unicode characters. */ + if (label_len > 255) + label_len = 255; + label_name = grub_calloc (label_len, sizeof (*label_name)); if (!label_name) {