From: Avnish Chouhan Date: Tue, 28 Oct 2025 16:32:02 +0000 (+0530) Subject: lib/legacy_parse: Add missing grub_malloc() failure check X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=d4f476f08e66aded4c8d99628280c9de14befd64;p=thirdparty%2Fgrub.git lib/legacy_parse: Add missing grub_malloc() failure check 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 Reviewed-by: Sudhakar Kuppusamy Reviewed-by: Daniel Kiper --- diff --git a/grub-core/lib/legacy_parse.c b/grub-core/lib/legacy_parse.c index fa0131a1e..899530944 100644 --- a/grub-core/lib/legacy_parse.c +++ b/grub-core/lib/legacy_parse.c @@ -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;