From: Sudhakar Kuppusamy <sudhakar@linux.ibm.com>
To: The development of GNU GRUB <grub-devel@gnu.org>
Cc: daniel.kiper@oracle.com, Avnish Chouhan <avnish@linux.ibm.com>
Subject: Re: [PATCH 4/4] Adding a grub_malloc failure check in legacy_parse.c
Date: Sun, 2 Nov 2025 20:30:22 +0530 [thread overview]
Message-ID: <698EF5E8-D25F-41B2-87F0-DF4C4D69653B@linux.ibm.com> (raw)
In-Reply-To: <20251028163202.63905-5-avnish@linux.ibm.com>
> On 28 Oct 2025, at 10:02 PM, Avnish Chouhan <avnish@linux.ibm.com> wrote:
>
> 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 <avnish@linux.ibm.com>
Reviewed-by: Sudhakar Kuppusamy <sudhakar@linux.ibm.com>
Thanks,
Sudhakar
> ---
> 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
> Grub-devel@gnu.org
> https://lists.gnu.org/mailman/listinfo/grub-devel
_______________________________________________
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel
next prev parent reply other threads:[~2025-11-02 15:01 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-10-28 16:31 [PATCH 0/4] Adding a failure check after grub_malloc() Avnish Chouhan
2025-10-28 16:31 ` [PATCH 1/4] normal: Adding a grub_malloc failure check in completion.c Avnish Chouhan
2025-11-02 14:54 ` Sudhakar Kuppusamy
2025-10-28 16:32 ` [PATCH 2/4] Adding a grub_malloc failure check in msdos.c Avnish Chouhan
2025-11-02 14:57 ` Sudhakar Kuppusamy
2025-10-28 16:32 ` [PATCH 3/4] Adding a grub_malloc failure check in mmap.c Avnish Chouhan
2025-11-02 14:58 ` Sudhakar Kuppusamy
2025-10-28 16:32 ` [PATCH 4/4] Adding a grub_malloc failure check in legacy_parse.c Avnish Chouhan
2025-11-02 15:00 ` Sudhakar Kuppusamy [this message]
2025-11-05 19:11 ` [PATCH 0/4] Adding a failure check after grub_malloc() 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=698EF5E8-D25F-41B2-87F0-DF4C4D69653B@linux.ibm.com \
--to=sudhakar@linux.ibm.com \
--cc=avnish@linux.ibm.com \
--cc=daniel.kiper@oracle.com \
--cc=grub-devel@gnu.org \
/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;
as well as URLs for NNTP newsgroup(s).