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>
This commit is contained in:
Michael Roth 2017-10-26 19:53:45 -05:00
parent 53f9fcb263
commit 8cedc80555

View File

@ -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);
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);