Skip to content

Commit

Permalink
qga-win: fix error-handling in getNameByStringSID()
Browse files Browse the repository at this point in the history
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 <[email protected]>
Suggested-by: Tomáš Golembiovský <[email protected]>
Signed-off-by: Michael Roth <[email protected]>
  • Loading branch information
mdroth committed Oct 27, 2017
1 parent 53f9fcb commit 8cedc80
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions qga/vss-win32/install.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down

0 comments on commit 8cedc80

Please sign in to comment.