[PATCH 2/4] Adding a grub_malloc failure check in msdos.c

Avnish Chouhan <[email protected]>
Newsgroups org.gnu.grub-devel
Message-ID <[email protected]>
Adding a NULL check in grub_malloc(). 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 <[email protected]>
---
 grub-core/partmap/msdos.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/grub-core/partmap/msdos.c b/grub-core/partmap/msdos.c
index c85bb74..bf92617 100644
--- a/grub-core/partmap/msdos.c
+++ b/grub-core/partmap/msdos.c
@@ -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,
-- 
2.47.1


_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.