fs/sfs: Check if allocated memory is NULL
authorAlec Brown <alec.r.brown@oracle.com>
Tue, 28 Jan 2025 05:15:50 +0000 (05:15 +0000)
committerFelix Zielcke <fzielcke@z-51.de>
Wed, 11 Jun 2025 15:42:34 +0000 (17:42 +0200)
When using grub_zalloc(), if we are out of memory, this function can fail.
After allocating memory, we should check if grub_zalloc() returns NULL.
If so, we should handle this error.

Fixes: CID 473856
Signed-off-by: Alec Brown <alec.r.brown@oracle.com>
Reviewed-by: Ross Philipson <ross.philipson@oracle.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
Gbp-Pq: Topic cve-2025-jan
Gbp-Pq: Name fs-sfs-Check-if-allocated-memory-is-NULL.patch

grub-core/fs/sfs.c

index 88705b3a29cab98d51e3373541d2478cbdfe4d88..bad4ae8d10a59ba4d52d8efadae971787a56c1df 100644 (file)
@@ -429,6 +429,9 @@ grub_sfs_mount (grub_disk_t disk)
             - 24    /* offsetof (struct grub_sfs_objc, objects) */
             - 25);  /* offsetof (struct grub_sfs_obj, filename) */
   data->label = grub_zalloc (max_len + 1);
+  if (data->label == NULL)
+    goto fail;
+
   grub_strncpy (data->label, (char *) rootobjc->objects[0].filename, max_len);
 
   grub_free (rootobjc_data);