From 8cedc80555e5a395a4fda7130b0115015e775c48 Mon Sep 17 00:00:00 2001 From: Michael Roth Date: Thu, 26 Oct 2017 19:53:45 -0500 Subject: qga-win: fix error-handling in getNameByStringSID() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 Suggested-by: Tomáš Golembiovský Signed-off-by: Michael Roth --- qga/vss-win32/install.cpp | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) (limited to 'qga') 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); -- cgit v1.2.1