From: Avnish Chouhan <avnish@linux.ibm.com>
To: sudhakar@linux.ibm.com
Cc: grub-devel@gnu.org, Daniel Kiper <daniel.kiper@oracle.com>
Subject: Re: [PATCH] linux/ofpath: Add missing strdup failure checks
Date: Wed, 19 Nov 2025 14:26:49 +0530 [thread overview]
Message-ID: <af4acc714c7c5a9b72f7894d06489ece@linux.ibm.com> (raw)
In-Reply-To: <mailman.57.1763485283.27328.grub-devel@gnu.org>
On 2025-11-18 22:31, grub-devel-request@gnu.org wrote:
> Message: 2
> Date: Tue, 18 Nov 2025 19:55:39 +0530
> From: Sudhakar Kuppusamy <sudhakar@linux.ibm.com>
> To: grub-devel@gnu.org
> Cc: Sudhakar Kuppusamy <sudhakar@linux.ibm.com>, ssrish@linux.ibm.com,
> sridharm@linux.ibm.com, stefanb@linux.ibm.com
> Subject: [PATCH] linux/ofpath: Add missing strdup failure checks
> Message-ID: <20251118142539.38467-1-sudhakar@linux.ibm.com>
>
> Segmentation faults or undefined behaviour may result from a null
> pointer
> dereference in strip_trailing_digits and grub_util_devname_to_ofpath if
> strdup() fails. Therefore, I added a NULL check to fix this.
>
> Signed-off-by: Sudhakar Kuppusamy <sudhakar@linux.ibm.com>
> ---
> grub-core/osdep/linux/ofpath.c | 11 +++++++++++
> 1 file changed, 11 insertions(+)
>
> diff --git a/grub-core/osdep/linux/ofpath.c
> b/grub-core/osdep/linux/ofpath.c
> index a6153d359..ade5220db 100644
> --- a/grub-core/osdep/linux/ofpath.c
> +++ b/grub-core/osdep/linux/ofpath.c
> @@ -695,6 +695,9 @@ strip_trailing_digits (const char *p)
> char *new, *end;
>
> new = strdup (p);
> + if (new == NULL)
> + return NULL;
> +
> end = new + strlen(new) - 1;
> while (end >= new)
> {
> @@ -715,7 +718,15 @@ grub_util_devname_to_ofpath (const char
> *sys_devname)
>
> device = get_basename (name_buf);
> devnode = strip_trailing_digits (name_buf);
> + if (devnode == NULL)
Hi Sudhakar,
This change will lead to a memory leak. You need to add "free
(name_buf);" here before retuning!
> + return NULL;
> +
> devicenode = strip_trailing_digits (device);
> + if (devicenode == NULL)
> + {
> + free (devnode);
And here too, "free (name_buf);"......
Thank you!
Regards,
Avnish Chouhan
_______________________________________________
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel
next parent reply other threads:[~2025-11-19 8:57 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <mailman.57.1763485283.27328.grub-devel@gnu.org>
2025-11-19 8:56 ` Avnish Chouhan [this message]
2025-11-19 9:53 ` [PATCH] linux/ofpath: Add missing strdup failure checks Sudhakar Kuppusamy
2025-11-19 12:11 ` Daniel Kiper via Grub-devel
2025-11-19 12:32 ` Sudhakar Kuppusamy
2025-11-19 20:08 ` Daniel Kiper
2025-11-18 14:25 Sudhakar Kuppusamy
2025-11-19 6:35 ` Srish Srinivasan
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=af4acc714c7c5a9b72f7894d06489ece@linux.ibm.com \
--to=avnish@linux.ibm.com \
--cc=daniel.kiper@oracle.com \
--cc=grub-devel@gnu.org \
--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