grub-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH] ofdisk: allocate space for vscsi table


From: Paulo Flabiano Smorigo
Subject: [PATCH] ofdisk: allocate space for vscsi table
Date: Sun, 8 Nov 2015 23:33:09 -0200

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/address@hidden/address@hidden
+       *  /vdevice/address@hidden/address@hidden
+       *  /vdevice/address@hidden/address@hidden  */
+
       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




reply via email to

[Prev in Thread] Current Thread [Next in Thread]