[PATCH 1/4] normal: Adding a grub_malloc failure check in completion.c

Avnish Chouhan <[email protected]>
Newsgroups org.gnu.grub-devel
Message-ID <[email protected]>
This patch adds 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/normal/completion.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/grub-core/normal/completion.c b/grub-core/normal/completion.c
index 18cadfa..4058e0a 100644
--- a/grub-core/normal/completion.c
+++ b/grub-core/normal/completion.c
@@ -490,6 +490,9 @@ grub_normal_do_completion (char *buf, int *restore,
 	  spaces++;
 
       ret = grub_malloc (match_len - current_len + grub_strlen (suffix) + spaces + 1);
+      if (ret == NULL)
+        goto fail;
+
       newstr = ret;
       for (escstr = match + current_len; *escstr; escstr++)
 	{
-- 
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.