summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichael Roth2017-10-27 02:53:45 +0200
committerMichael Roth2017-10-27 03:01:32 +0200
commit8cedc80555e5a395a4fda7130b0115015e775c48 (patch)
tree2651c66a40af16f8ed2e8395e7c1a6e4764a87f3
parentqga: add network stats to guest-network-get-interfaces (diff)
downloadqemu-8cedc80555e5a395a4fda7130b0115015e775c48.tar.gz
qemu-8cedc80555e5a395a4fda7130b0115015e775c48.tar.xz
qemu-8cedc80555e5a395a4fda7130b0115015e775c48.zip
qga-win: fix error-handling in getNameByStringSID()
In one case we misconstrue a BOOL return as an HRESULT, and in the other case we don't check the BOOL return from LookupAccountSidW() before extracting the HRESULT from GetLastError(). Both can lead to getNameByStringSID() misreporting an error. Reported-by: Chen Hanxiao <chenhanxiao@gmail.com> Suggested-by: Tomáš Golembiovský <tgolembi@redhat.com> Signed-off-by: Michael Roth <mdroth@linux.vnet.ibm.com>
-rw-r--r--qga/vss-win32/install.cpp13
1 files changed, 9 insertions, 4 deletions
diff --git a/qga/vss-win32/install.cpp b/qga/vss-win32/install.cpp
index ba7c94eb25..6713e58670 100644
--- a/qga/vss-win32/install.cpp
+++ b/qga/vss-win32/install.cpp
@@ -148,10 +148,15 @@ static HRESULT getNameByStringSID(
DWORD domainNameLen = BUFFER_SIZE;
wchar_t domainName[BUFFER_SIZE];
- chk(ConvertStringSidToSidW(sid, &psid));
- LookupAccountSidW(NULL, psid, buffer, bufferLen,
- domainName, &domainNameLen, &groupType);
- hr = HRESULT_FROM_WIN32(GetLastError());
+ if (!ConvertStringSidToSidW(sid, &psid)) {
+ hr = HRESULT_FROM_WIN32(GetLastError());
+ goto out;
+ }
+ if (!LookupAccountSidW(NULL, psid, buffer, bufferLen,
+ domainName, &domainNameLen, &groupType)) {
+ hr = HRESULT_FROM_WIN32(GetLastError());
+ /* Fall through and free psid */
+ }
LocalFree(psid);