Commit 8cedc805 authored by Michael Roth's avatar Michael Roth
Browse files

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: default avatarChen Hanxiao <chenhanxiao@gmail.com>
Suggested-by: default avatarTomáš Golembiovský <tgolembi@redhat.com>
Signed-off-by: default avatarMichael Roth <mdroth@linux.vnet.ibm.com>
parent 53f9fcb2
Loading
Loading
Loading
Loading
+9 −4
Original line number Diff line number Diff line
@@ -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);