]> git.ipfire.org Git - thirdparty/grub.git/commitdiff
lib/legacy_parse: Add missing grub_malloc() failure check
authorAvnish Chouhan <avnish@linux.ibm.com>
Tue, 28 Oct 2025 16:32:02 +0000 (22:02 +0530)
committerDaniel Kiper <daniel.kiper@oracle.com>
Thu, 6 Nov 2025 16:21:18 +0000 (17:21 +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/lib/legacy_parse.c

index fa0131a1ea1cf60ab704249db167084c7c7c6ee1..8995309448418ac63b871b77a01fc0a9e4cefc07 100644 (file)
@@ -508,6 +508,9 @@ grub_legacy_parse (const char *buf, char **entryname, char **suffix)
       char *ret;
       int len = grub_strlen (buf);
       ret = grub_malloc (len + 2);
+      if (ret == NULL)
+        return NULL;
+
       grub_memcpy (ret, buf, len);
       if (len && ret[len - 1] == '\n')
        ret[len] = 0;