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

Avnish Chouhan <[email protected]>
Newsgroups org.gnu.grub-devel
Message-ID <[email protected]>
Adding a failure check after calling grub_malloc() as it 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/lib/legacy_parse.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/grub-core/lib/legacy_parse.c b/grub-core/lib/legacy_parse.c
index fa0131a..8995309 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;
-- 
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.