Skip to contentSkip to conversation

disk/ieee1275 : Add a fix for memory leaks in ofdisk

PATCH In review Avnish Chouhan 4 participants 4 messages Dec 1, 2025 – Dec 19, 2025

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 disk/ieee1275 : Add a fix for memory leaks in ofdisk

Adding a fix for memory leaks. In case of overflow check fails, not freeing 'p' and 'p->grub_devpath' will result in memory leaks.

---
 grub-core/disk/ieee1275/ofdisk.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
grub-core/disk/ieee1275/ofdisk.c +5 -2
index dbc0f1a..3a90a71 100644
@@ -93,6 +93,7 @@ ofdisk_hash_add_real (char *devpath)
       grub_add (sz, sizeof ("ieee1275/"), &sz))
     {
       grub_error (GRUB_ERR_OUT_OF_RANGE, N_("overflow detected while obtaining size of device path"));
+      grub_free (p);
       return NULL;
     }
 
@@ -108,8 +109,10 @@ ofdisk_hash_add_real (char *devpath)
     {
       if (grub_add (grub_strlen (p->devpath), 3, &sz))
 	{
-	  grub_error (GRUB_ERR_OUT_OF_RANGE, N_("overflow detected while obtaining size of an open path"));
-	  return NULL;
+          grub_error (GRUB_ERR_OUT_OF_RANGE, N_("overflow detected while obtaining size of an open path"));
+          grub_free (p->grub_devpath);
+          grub_free (p);
+          return NULL;
 	}
 
       p->open_path = grub_malloc (sz);
Signature · 7 lines
2.52.0


_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel
Reviewed-by Alec Brown on v1 1/1
#1 lore raw
Quoted 35 lines · Avnish Chouhan

Adding a fix for memory leaks. In case of overflow check fails, not freeing 'p' and 'p-

Quoted 1 line

grub_devpath' will result in memory leaks.

---
 grub-core/disk/ieee1275/ofdisk.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
grub-core/disk/ieee1275/ofdisk.c +5 -2
index dbc0f1a..3a90a71 100644
@@ -93,6 +93,7 @@ ofdisk_hash_add_real (char *devpath)
       grub_add (sz, sizeof ("ieee1275/"), &sz))
     {
       grub_error (GRUB_ERR_OUT_OF_RANGE, N_("overflow detected while obtaining size of device
 path"));
+      grub_free (p);
       return NULL;
     }
@@ -108,8 +109,10 @@ ofdisk_hash_add_real (char *devpath)
     {
       if (grub_add (grub_strlen (p->devpath), 3, &sz))
 	{
-	  grub_error (GRUB_ERR_OUT_OF_RANGE, N_("overflow detected while obtaining size of an open
 path"));
-	  return NULL;
+          grub_error (GRUB_ERR_OUT_OF_RANGE, N_("overflow detected while obtaining size of an
 open path"));
+          grub_free (p->grub_devpath);
+          grub_free (p);
+          return NULL;
 	}
Quoted 3 lines
       p->open_path = grub_malloc (sz);

--
2.52.0

LGTM! Thanks!

Alec Brown

_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel

Reviewed-by
#2 lore raw
Quoted 36 lines · Alec Brown via Grub-devel
Quoted 35 lines · Avnish Chouhan

Adding a fix for memory leaks. In case of overflow check fails, not freeing 'p' and 'p-

Quoted 1 line

grub_devpath' will result in memory leaks.

---
 grub-core/disk/ieee1275/ofdisk.c | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
grub-core/disk/ieee1275/ofdisk.c +5 -2
index dbc0f1a..3a90a71 100644
@@ -93,6 +93,7 @@ ofdisk_hash_add_real (char *devpath)
       grub_add (sz, sizeof ("ieee1275/"), &sz))
     {
       grub_error (GRUB_ERR_OUT_OF_RANGE, N_("overflow detected while obtaining size of device
 path"));
+      grub_free (p);
       return NULL;
     }
@@ -108,8 +109,10 @@ ofdisk_hash_add_real (char *devpath)
     {
       if (grub_add (grub_strlen (p->devpath), 3, &sz))
 	{
-	  grub_error (GRUB_ERR_OUT_OF_RANGE, N_("overflow detected while obtaining size of an open
 path"));
-	  return NULL;
+          grub_error (GRUB_ERR_OUT_OF_RANGE, N_("overflow detected while obtaining size of an
 open path"));
+          grub_free (p->grub_devpath);
+          grub_free (p);
+          return NULL;
 	}
Quoted 7 lines
Quoted 3 lines
       p->open_path = grub_malloc (sz);

--
2.52.0

LGTM! Thanks!

Daniel

_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel

Reviewed-by on v1 1/1
#3 lore raw
In reply to Avnish Chouhan
Quoted 8 lines · Avnish Chouhan

Adding a fix for memory leaks. In case of overflow check fails, not freeing 'p' and 'p->grub_devpath' will result in memory leaks.

Thanks,
Sudhakar

Quoted 37 lines

---
grub-core/disk/ieee1275/ofdisk.c | 7 +++++--

1 file changed, 5 insertions(+), 2 deletions(-)
grub-core/disk/ieee1275/ofdisk.c +5 -2
index dbc0f1a..3a90a71 100644
@@ -93,6 +93,7 @@ ofdisk_hash_add_real (char *devpath)
      grub_add (sz, sizeof ("ieee1275/"), &sz))
    {
      grub_error (GRUB_ERR_OUT_OF_RANGE, N_("overflow detected while obtaining size of device path"));
+      grub_free (p);
      return NULL;
    }
 
@@ -108,8 +109,10 @@ ofdisk_hash_add_real (char *devpath)
    {
      if (grub_add (grub_strlen (p->devpath), 3, &sz))
 {
-  grub_error (GRUB_ERR_OUT_OF_RANGE, N_("overflow detected while obtaining size of an open path"));
-  return NULL;
+          grub_error (GRUB_ERR_OUT_OF_RANGE, N_("overflow detected while obtaining size of an open path"));
+          grub_free (p->grub_devpath);
+          grub_free (p);
+          return NULL;
 }
 
      p->open_path = grub_malloc (sz);
Signature · 7 lines
2.52.0


_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel

_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel