qemu-devel
[Top][All Lists]
Advanced

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

[Qemu-devel] [PATCH] qga: Fix possible freed memory accessing


From: zhanghailiang
Subject: [Qemu-devel] [PATCH] qga: Fix possible freed memory accessing
Date: Thu, 18 Sep 2014 11:33:42 +0800

If readdir_r fails, error_setg_errno will reference the freed
pointer *dirpath*.

Signed-off-by: zhanghailiang <address@hidden>
---
 qga/commands-posix.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/qga/commands-posix.c b/qga/commands-posix.c
index 7eed7f4..3082eae 100644
--- a/qga/commands-posix.c
+++ b/qga/commands-posix.c
@@ -965,7 +965,6 @@ static void build_guest_fsinfo_for_virtual_device(char 
const *syspath,
         g_free(dirpath);
         return;
     }
-    g_free(dirpath);
 
     for (;;) {
         if (readdir_r(dir, &entry, &result) != 0) {
@@ -977,10 +976,12 @@ static void build_guest_fsinfo_for_virtual_device(char 
const *syspath,
         }
 
         if (entry.d_type == DT_LNK) {
+            char *path;
+
             g_debug(" slave device '%s'", entry.d_name);
-            dirpath = g_strdup_printf("%s/slaves/%s", syspath, entry.d_name);
-            build_guest_fsinfo_for_device(dirpath, fs, errp);
-            g_free(dirpath);
+            path = g_strdup_printf("%s/slaves/%s", syspath, entry.d_name);
+            build_guest_fsinfo_for_device(path, fs, errp);
+            g_free(path);
 
             if (*errp) {
                 break;
@@ -988,6 +989,7 @@ static void build_guest_fsinfo_for_virtual_device(char 
const *syspath,
         }
     }
 
+    g_free(dirpath);
     closedir(dir);
 }
 
-- 
1.7.12.4





reply via email to

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