public inbox for grub-devel@gnu.org
 help / color / mirror / Atom feed
From: Avnish Chouhan <avnish@linux.ibm.com>
To: grub-devel@gnu.org
Cc: daniel.kiper@oracle.com, phcoder@gmail.com,
	Avnish Chouhan <avnish@linux.ibm.com>,
	Sudhakar Kuppusamy <sudhakar@linux.ibm.com>
Subject: [PATCH v2] efiemu/loadcore: Add grub_calloc failure check
Date: Thu, 27 Nov 2025 14:32:12 +0530	[thread overview]
Message-ID: <20251127090212.92875-1-avnish@linux.ibm.com> (raw)

Adding a failure check in grub_calloc(). If grub_calloc fails,
(e.g., due to memory allocation failure), it returns NULL. 
Then, using grub_efiemu_elfsyms (which would be NULL)
later will result in a null pointer dereference,
and can cause an undefined behavior.

Signed-off-by: Avnish Chouhan <avnish@linux.ibm.com>
Reviewed-by: Sudhakar Kuppusamy <sudhakar@linux.ibm.com>
---
 grub-core/efiemu/loadcore.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/grub-core/efiemu/loadcore.c b/grub-core/efiemu/loadcore.c
index 2b92462..5a6d244 100644
--- a/grub-core/efiemu/loadcore.c
+++ b/grub-core/efiemu/loadcore.c
@@ -203,6 +203,9 @@ grub_efiemu_count_symbols (const Elf_Ehdr *e)
   grub_efiemu_elfsyms = (struct grub_efiemu_elf_sym *)
     grub_calloc (grub_efiemu_nelfsyms, sizeof (struct grub_efiemu_elf_sym));
 
+  if (grub_efiemu_elfsyms == NULL)
+    return grub_errno;
+
   /* Relocators */
   for (i = 0, s = (Elf_Shdr *) ((char *) e + e->e_shoff);
        i < e->e_shnum;
-- 
2.46.0


_______________________________________________
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel

             reply	other threads:[~2025-11-27  9:03 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-11-27  9:02 Avnish Chouhan [this message]
2025-12-18 17:32 ` [PATCH v2] efiemu/loadcore: Add grub_calloc failure check Daniel Kiper

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20251127090212.92875-1-avnish@linux.ibm.com \
    --to=avnish@linux.ibm.com \
    --cc=daniel.kiper@oracle.com \
    --cc=grub-devel@gnu.org \
    --cc=phcoder@gmail.com \
    --cc=sudhakar@linux.ibm.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox