]> git.ipfire.org Git - thirdparty/grub.git/commitdiff
normal/completion: Add missing grub_malloc() failure check
authorAvnish Chouhan <avnish@linux.ibm.com>
Tue, 28 Oct 2025 16:31:59 +0000 (22:01 +0530)
committerDaniel Kiper <daniel.kiper@oracle.com>
Thu, 6 Nov 2025 14:37:40 +0000 (15:37 +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/normal/completion.c

index 18cadfa8543054741475ac9a684fe50b1f2bd0bf..4058e0a6269cf370a8e3c4472970bba903baccf9 100644 (file)
@@ -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++)
        {