The table must be allocated in order to avoid memory leak. Also added some
vscsi paths for illustration purpose.

---
 grub-core/disk/ieee1275/ofdisk.c | 30 +++++++++++++++++++++++++-----
 1 file changed, 25 insertions(+), 5 deletions(-)

diff --git a/grub-core/disk/ieee1275/ofdisk.c b/grub-core/disk/ieee1275/ofdisk.c
index afec9ba..4ea6089 100644
--- a/grub-core/disk/ieee1275/ofdisk.c
+++ b/grub-core/disk/ieee1275/ofdisk.c
@@ -211,6 +211,11 @@ dev_iterate (const struct grub_ieee1275_devalias *alias)
 {
   if (grub_strcmp (alias->type, "vscsi") == 0)
     {
+      /* Example of vscsi paths:
+       *  /vdevice/v-scsi@30000002/disk@8100000000000000
+       *  /vdevice/v-scsi@30000002/disk@8200000000000000
+       *  /vdevice/v-scsi@30000002/disk@8400000000000000  */
+
       static grub_ieee1275_ihandle_t ihandle;
       struct set_color_args
       {
@@ -222,27 +227,41 @@ dev_iterate (const struct grub_ieee1275_devalias *alias)
        grub_ieee1275_cell_t table;
       }
       args;
-      char *buf, *bufptr;
+      char *buf, *bufptr, *table;
       unsigned i;
+      grub_uint32_t table_size;
 
       if (grub_ieee1275_open (alias->path, &ihandle))
        return;
-    
+
+      /* 64 entries should be enough */
+      table_size = sizeof (grub_uint64_t) * 64;
+      table = grub_malloc (table_size);
+
+      if (!table)
+       return;
+
       INIT_IEEE1275_COMMON (&args.common, "call-method", 2, 3);
       args.method = (grub_ieee1275_cell_t) "vscsi-report-luns";
       args.ihandle = ihandle;
-      args.table = 0;
+      args.table = (grub_ieee1275_cell_t) table;
       args.nentries = 0;
 
       if (IEEE1275_CALL_ENTRY_FN (&args) == -1 || args.catch_result)
        {
          grub_ieee1275_close (ihandle);
-         return;
+          grub_free (table);
+          return;
        }
 
       buf = grub_malloc (grub_strlen (alias->path) + 32);
       if (!buf)
-       return;
+        {
+          grub_ieee1275_close (ihandle);
+          grub_free (table);
+          return;
+        }
+
       bufptr = grub_stpcpy (buf, alias->path);
 
       for (i = 0; i < args.nentries; i++)
@@ -257,6 +276,7 @@ dev_iterate (const struct grub_ieee1275_devalias *alias)
            }
        }
       grub_ieee1275_close (ihandle);
+      grub_free (table);
       grub_free (buf);
       return;
     }
-- 
2.1.0


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

Reply via email to