* Re: [PATCH v1] linux/ofpath: Add missing strdup failure checks
[not found] <mailman.8407.1763554318.1058.grub-devel@gnu.org>
@ 2025-11-19 13:48 ` Avnish Chouhan
2025-11-19 20:36 ` Daniel Kiper
0 siblings, 1 reply; 4+ messages in thread
From: Avnish Chouhan @ 2025-11-19 13:48 UTC (permalink / raw)
To: sudhakar; +Cc: grub-devel, Daniel Kiper
On 2025-11-19 17:41, grub-devel-request@gnu.org wrote:
> Message: 1
> Date: Wed, 19 Nov 2025 15:30:47 +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 v1] linux/ofpath: Add missing strdup failure checks
> Message-ID: <20251119100047.6573-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>
> Reviewed-by: Srish Srinivasan <ssrish@linux.ibm.com>
> ---
Reviewed-by: Avnish Chouhan <avnish@linux.ibm.com>
Regards,
Avnish Chouhan
> grub-core/osdep/linux/ofpath.c | 14 ++++++++++++--
> 1 file changed, 12 insertions(+), 2 deletions(-)
>
> diff --git a/grub-core/osdep/linux/ofpath.c
> b/grub-core/osdep/linux/ofpath.c
> index a6153d359..a3747b248 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)
> {
> @@ -709,13 +712,18 @@ strip_trailing_digits (const char *p)
> char *
> grub_util_devname_to_ofpath (const char *sys_devname)
> {
> - char *name_buf, *device, *devnode, *devicenode, *ofpath;
> + char *name_buf, *device, *devnode, *devicenode, *ofpath = NULL;
>
> name_buf = xrealpath (sys_devname);
>
> device = get_basename (name_buf);
> devnode = strip_trailing_digits (name_buf);
> + if (devnode == NULL)
> + goto devnode_fail;
> +
> devicenode = strip_trailing_digits (device);
> + if (devicenode == NULL)
> + goto devicenode_fail;
>
> if (device[0] == 'h' && device[1] == 'd')
> ofpath = of_path_of_ide(name_buf, device, devnode, devicenode);
> @@ -741,8 +749,10 @@ grub_util_devname_to_ofpath (const char
> *sys_devname)
> ofpath = NULL;
> }
>
> - free (devnode);
> free (devicenode);
> + devicenode_fail:
> + free (devnode);
> + devnode_fail:
> free (name_buf);
>
> return ofpath;
> --
> 2.50.1 (Apple Git-155)
_______________________________________________
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel
^ permalink raw reply [flat|nested] 4+ messages in thread* Re: [PATCH v1] linux/ofpath: Add missing strdup failure checks
2025-11-19 13:48 ` [PATCH v1] linux/ofpath: Add missing strdup failure checks Avnish Chouhan
@ 2025-11-19 20:36 ` Daniel Kiper
0 siblings, 0 replies; 4+ messages in thread
From: Daniel Kiper @ 2025-11-19 20:36 UTC (permalink / raw)
To: Avnish Chouhan; +Cc: sudhakar, grub-devel, Daniel Kiper
On Wed, Nov 19, 2025 at 07:18:52PM +0530, Avnish Chouhan wrote:
> On 2025-11-19 17:41, grub-devel-request@gnu.org wrote:
> > Message: 1
> > Date: Wed, 19 Nov 2025 15:30:47 +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 v1] linux/ofpath: Add missing strdup failure checks
> > Message-ID: <20251119100047.6573-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>
> > Reviewed-by: Srish Srinivasan <ssrish@linux.ibm.com>
> > ---
>
> Reviewed-by: Avnish Chouhan <avnish@linux.ibm.com>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
Daniel
_______________________________________________
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel
^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH v1] linux/ofpath: Add missing strdup failure checks
@ 2025-11-19 10:00 Sudhakar Kuppusamy
0 siblings, 0 replies; 4+ messages in thread
From: Sudhakar Kuppusamy @ 2025-11-19 10:00 UTC (permalink / raw)
To: grub-devel; +Cc: Sudhakar Kuppusamy, ssrish, sridharm, stefanb
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>
Reviewed-by: Srish Srinivasan <ssrish@linux.ibm.com>
---
grub-core/osdep/linux/ofpath.c | 14 ++++++++++++--
1 file changed, 12 insertions(+), 2 deletions(-)
diff --git a/grub-core/osdep/linux/ofpath.c b/grub-core/osdep/linux/ofpath.c
index a6153d359..a3747b248 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)
{
@@ -709,13 +712,18 @@ strip_trailing_digits (const char *p)
char *
grub_util_devname_to_ofpath (const char *sys_devname)
{
- char *name_buf, *device, *devnode, *devicenode, *ofpath;
+ char *name_buf, *device, *devnode, *devicenode, *ofpath = NULL;
name_buf = xrealpath (sys_devname);
device = get_basename (name_buf);
devnode = strip_trailing_digits (name_buf);
+ if (devnode == NULL)
+ goto devnode_fail;
+
devicenode = strip_trailing_digits (device);
+ if (devicenode == NULL)
+ goto devicenode_fail;
if (device[0] == 'h' && device[1] == 'd')
ofpath = of_path_of_ide(name_buf, device, devnode, devicenode);
@@ -741,8 +749,10 @@ grub_util_devname_to_ofpath (const char *sys_devname)
ofpath = NULL;
}
- free (devnode);
free (devicenode);
+ devicenode_fail:
+ free (devnode);
+ devnode_fail:
free (name_buf);
return ofpath;
--
2.50.1 (Apple Git-155)
_______________________________________________
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel
^ permalink raw reply related [flat|nested] 4+ messages in thread* [PATCH v1] linux/ofpath: Add missing strdup failure checks
@ 2025-11-19 9:59 Sudhakar Kuppusamy
0 siblings, 0 replies; 4+ messages in thread
From: Sudhakar Kuppusamy @ 2025-11-19 9:59 UTC (permalink / raw)
To: grub-devel; +Cc: Sudhakar Kuppusamy, ssrish, sridharm, stefanb
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>
Reviewed-by: Srish Srinivasan <ssrish@linux.ibm.com>
---
grub-core/osdep/linux/ofpath.c | 14 ++++++++++++--
1 file changed, 12 insertions(+), 2 deletions(-)
diff --git a/grub-core/osdep/linux/ofpath.c b/grub-core/osdep/linux/ofpath.c
index a6153d359..a3747b248 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)
{
@@ -709,13 +712,18 @@ strip_trailing_digits (const char *p)
char *
grub_util_devname_to_ofpath (const char *sys_devname)
{
- char *name_buf, *device, *devnode, *devicenode, *ofpath;
+ char *name_buf, *device, *devnode, *devicenode, *ofpath = NULL;
name_buf = xrealpath (sys_devname);
device = get_basename (name_buf);
devnode = strip_trailing_digits (name_buf);
+ if (devnode == NULL)
+ goto devnode_fail
+
devicenode = strip_trailing_digits (device);
+ if (devicenode == NULL)
+ goto devicenode_fail;
if (device[0] == 'h' && device[1] == 'd')
ofpath = of_path_of_ide(name_buf, device, devnode, devicenode);
@@ -741,8 +749,10 @@ grub_util_devname_to_ofpath (const char *sys_devname)
ofpath = NULL;
}
- free (devnode);
free (devicenode);
+ devicenode_fail:
+ free (devnode);
+ devnode_fail:
free (name_buf);
return ofpath;
--
2.50.1 (Apple Git-155)
_______________________________________________
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel
^ permalink raw reply related [flat|nested] 4+ messages in thread
end of thread, other threads:[~2025-11-19 20:36 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
[not found] <mailman.8407.1763554318.1058.grub-devel@gnu.org>
2025-11-19 13:48 ` [PATCH v1] linux/ofpath: Add missing strdup failure checks Avnish Chouhan
2025-11-19 20:36 ` Daniel Kiper
2025-11-19 10:00 Sudhakar Kuppusamy
-- strict thread matches above, loose matches on Subject: below --
2025-11-19 9:59 Sudhakar Kuppusamy
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.