From: zhanghailiang <zhang.zhanghailiang@huawei.com>
To: qemu-devel@nongnu.org
Cc: mdroth@linux.vnet.ibm.com, armbru@redhat.com,
luonengjun@huawei.com, peter.huangpeng@huawei.com,
qemu-stable@nongnu.org, lcapitulino@redhat.com,
zhanghailiang <zhang.zhanghailiang@huawei.com>
Subject: [Qemu-devel] [PATCH] qga: Fix possible freed memory accessing
Date: Thu, 18 Sep 2014 11:33:42 +0800 [thread overview]
Message-ID: <1411011222-5116-1-git-send-email-zhang.zhanghailiang@huawei.com> (raw)
If readdir_r fails, error_setg_errno will reference the freed
pointer *dirpath*.
Signed-off-by: zhanghailiang <zhang.zhanghailiang@huawei.com>
---
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
next reply other threads:[~2014-09-18 3:35 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-09-18 3:33 zhanghailiang [this message]
2014-09-18 7:00 ` [Qemu-devel] [PATCH] qga: Fix possible freed memory accessing Markus Armbruster
2014-09-18 12:17 ` Eric Blake
2014-09-18 12:42 ` zhanghailiang
2014-09-18 12:53 ` Eric Blake
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1411011222-5116-1-git-send-email-zhang.zhanghailiang@huawei.com \
--to=zhang.zhanghailiang@huawei.com \
--cc=armbru@redhat.com \
--cc=lcapitulino@redhat.com \
--cc=luonengjun@huawei.com \
--cc=mdroth@linux.vnet.ibm.com \
--cc=peter.huangpeng@huawei.com \
--cc=qemu-devel@nongnu.org \
--cc=qemu-stable@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).