]> git.ipfire.org Git - thirdparty/grub.git/commitdiff
fs/hfsplus: Set grub_errno to prevent NULL pointer access
authorLidong Chen <lidong.chen@oracle.com>
Wed, 3 May 2023 17:32:19 +0000 (17:32 +0000)
committerDaniel Kiper <daniel.kiper@oracle.com>
Wed, 17 May 2023 16:19:02 +0000 (18:19 +0200)
When an invalid node size is detected in grub_hfsplus_mount(), data
pointer is freed. Thus, file->data is not set. The code should also
set the grub_errno when that happens to indicate an error and to avoid
accessing the uninitialized file->data in grub_file_close().

Signed-off-by: Lidong Chen <lidong.chen@oracle.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
grub-core/fs/hfsplus.c

index a2ae9486eb9f41f3e1d6934503bb9fe198fa39be..295822f694d16b544edb795e36a4976cb8507991 100644 (file)
@@ -357,7 +357,10 @@ grub_hfsplus_mount (grub_disk_t disk)
                          (header.key_compare == GRUB_HFSPLUSX_BINARYCOMPARE));
 
   if (data->catalog_tree.nodesize < 2)
-    goto fail;
+    {
+      grub_error (GRUB_ERR_BAD_FS, "invalid catalog node size");
+      goto fail;
+    }
 
   if (grub_hfsplus_read_file (&data->extoverflow_tree.file, 0, 0,
                              sizeof (struct grub_hfsplus_btnode),
@@ -374,7 +377,10 @@ grub_hfsplus_mount (grub_disk_t disk)
   data->extoverflow_tree.nodesize = grub_be_to_cpu16 (header.nodesize);
 
   if (data->extoverflow_tree.nodesize < 2)
-    goto fail;
+    {
+      grub_error (GRUB_ERR_BAD_FS, "invalid extents overflow node size");
+      goto fail;
+    }
 
   data->extoverflow_tree_ready = 1;