qga: remove readdir_r usage and fix use-after-free
Signed-off-by: Michael Roth <mdroth@linux.vnet.ibm.com> -----BEGIN PGP SIGNATURE----- Version: GnuPG v1 iQEcBAABAgAGBQJUR6lzAAoJEDNTyc7xCLWE/iYH/jtAEpHxB3dBjq1h1Q3P29qm 2tKa9FBtZyqzS1epLevQL4lI+TzQCDFtdwh9T61H58kVbLqOEZYDThUNXya58tLw 3dLqA3bgOyZzaMtxp8K65UMS5Dgq2fi5nY+qmC/vWpoo27fijOEocLCQK49xi/t9 +YiwA0lNIXV8FggYSn0sfJF9zkeV2gdu5Map98B+JrD3S6+ITaFD4qkyOLtAioAK I7IceAFygh9a/mmb4ngZtCLtekyr2UOB9b8Q4m0uitgtH/Qe/wO0Hb2eIaioM4Xj O9vpbElKSD/sRAX2zY/DHN+QFeU6EXsrE5kR4qKRMIEjgPyLt3HVP8ZkYmVzL7Q= =ksu6 -----END PGP SIGNATURE----- Merge remote-tracking branch 'remotes/mdroth/tags/qga-pull-2014-10-22-tag' into staging qga: remove readdir_r usage and fix use-after-free Signed-off-by: Michael Roth <mdroth@linux.vnet.ibm.com> # gpg: Signature made Wed 22 Oct 2014 13:56:19 BST using RSA key ID F108B584 # gpg: Can't check signature: public key not found * remotes/mdroth/tags/qga-pull-2014-10-22-tag: qga: Rewrite code where using readdir_r Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
This commit is contained in:
commit
e40830afa1
|
@ -956,7 +956,7 @@ static void build_guest_fsinfo_for_virtual_device(char const *syspath,
|
|||
{
|
||||
DIR *dir;
|
||||
char *dirpath;
|
||||
struct dirent entry, *result;
|
||||
struct dirent *entry;
|
||||
|
||||
dirpath = g_strdup_printf("%s/slaves", syspath);
|
||||
dir = opendir(dirpath);
|
||||
|
@ -965,22 +965,24 @@ 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) {
|
||||
error_setg_errno(errp, errno, "readdir_r(\"%s\")", dirpath);
|
||||
break;
|
||||
errno = 0;
|
||||
entry = readdir(dir);
|
||||
if (entry == NULL) {
|
||||
if (errno) {
|
||||
error_setg_errno(errp, errno, "readdir(\"%s\")", dirpath);
|
||||
}
|
||||
if (!result) {
|
||||
break;
|
||||
}
|
||||
|
||||
if (entry.d_type == DT_LNK) {
|
||||
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);
|
||||
if (entry->d_type == DT_LNK) {
|
||||
char *path;
|
||||
|
||||
g_debug(" slave device '%s'", entry->d_name);
|
||||
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 +990,7 @@ static void build_guest_fsinfo_for_virtual_device(char const *syspath,
|
|||
}
|
||||
}
|
||||
|
||||
g_free(dirpath);
|
||||
closedir(dir);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue