]> git.ipfire.org Git - thirdparty/grub.git/commitdiff
partmap/msdos: Add missing grub_malloc() failure check
authorAvnish Chouhan <avnish@linux.ibm.com>
Tue, 28 Oct 2025 16:32:00 +0000 (22:02 +0530)
committerDaniel Kiper <daniel.kiper@oracle.com>
Thu, 6 Nov 2025 15:25:53 +0000 (16:25 +0100)
This patch adds a NULL check after grub_malloc() call. Missing a failure
check after calling grub_malloc() can lead to undefined behavior. If the
allocation fails and returns NULL subsequent dereferencing or writing to
the pointer will likely result in a runtime error such as a segmentation
fault.

Signed-off-by: Avnish Chouhan <avnish@linux.ibm.com>
Reviewed-by: Sudhakar Kuppusamy <sudhakar@linux.ibm.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
grub-core/partmap/msdos.c

index c85bb74be2bd5a722c74d6ffd3881db0a609de13..bf926175e382dba767d74bc7e10b8abdaa9b4e05 100644 (file)
@@ -348,6 +348,9 @@ pc_partition_map_embed (struct grub_disk *disk, unsigned int *nsectors,
        * area.
        */
       embed_signature_check = grub_malloc (GRUB_DISK_SECTOR_SIZE);
+      if (embed_signature_check == NULL)
+        return grub_errno;
+
       for (i = 0; i < *nsectors; i++)
        {
          if (grub_disk_read (disk, (*sectors)[i], 0, GRUB_DISK_SECTOR_SIZE,