[syslinux] [PULL 8/8] efi/multifs: fix misuse of static private information

Paulo Alcantara pcacjr at gmail.com
Wed Jul 22 16:27:30 PDT 2015


The get_dev_info_priv() function cannot return a reference of a static
variable since there might be multiple device handles and each one per
logical partition. A typical example of this failure is when a
configuration file contains multifs-path-syntax like, so multifs will
initialised to the first partition found (including its device handle)
and the other ones will be using the same partition to do I/O.

Cc: Gene Cumm <gene.cumm at gmail.com>
Signed-off-by: Paulo Alcantara <pcacjr at zytor.com>
---
 efi/multifs.c | 16 ++++++++++------
 1 file changed, 10 insertions(+), 6 deletions(-)

diff --git a/efi/multifs.c b/efi/multifs.c
index 418d0c2..63bf73e 100644
--- a/efi/multifs.c
+++ b/efi/multifs.c
@@ -97,11 +97,15 @@ static inline EFI_HANDLE find_device_handle(unsigned int diskno,
     return get_logical_part(partno);
 }
 
-static inline void *get_dev_info_priv(EFI_HANDLE lpart)
+static inline void *get_dev_info_priv(EFI_HANDLE handle)
 {
-    static struct efi_disk_private priv;
-    priv.dev_handle = lpart;
-    return (void *)&priv;
+    struct efi_disk_private *priv;
+
+    priv = malloc(sizeof(*priv));
+    if (!priv)
+        return NULL;
+    priv->dev_handle = handle;
+    return priv;
 }
 
 __export struct fs_info *efi_multifs_get_fs_info(const char **path)
@@ -136,11 +140,11 @@ __export struct fs_info *efi_multifs_get_fs_info(const char **path)
     ret = multifs_setup_fs_info(fsp, diskno, partno, priv);
     if (ret) {
         dprintf("%s: failed to set up fs info\n", __func__);
-        goto free_dev_info;
+        goto free_priv;
     }
     return fsp;
 
-free_dev_info:
+free_priv:
     free(priv);
 free_fsp:
     free(fsp);
-- 
2.1.0



More information about the Syslinux mailing list