api: fix LastError override

The LastError was overridden by the stdout reader thread exit code
masking the true reason why ExecuteRunDll32() failed and even worse: as
the thread exited gracefully, the true reason was overridden by
ERROR_SUCCESS and returning TRUE (success).

Signed-off-by: Simon Rozman <simon@rozman.si>
This commit is contained in:
Simon Rozman 2020-11-06 16:50:00 +01:00 committed by Jason A. Donenfeld
parent 3f843c9aab
commit b0ebb6d0ad

View File

@ -206,9 +206,10 @@ cleanupThreads:
CloseHandle(StreamWStdout);
StreamWStdout = INVALID_HANDLE_VALUE;
WaitForSingleObject(ThreadStdout, INFINITE);
if (!GetExitCodeThread(ThreadStdout, &LastError))
LastError = LOG_LAST_ERROR(L"Failed to retrieve stdout reader result");
else if (LastError != ERROR_SUCCESS)
DWORD ThreadResult;
if (!GetExitCodeThread(ThreadStdout, &ThreadResult))
LOG_LAST_ERROR(L"Failed to retrieve stdout reader result");
else if (ThreadResult != ERROR_SUCCESS)
LOG_ERROR(L"Failed to read process output", LastError);
CloseHandle(ThreadStdout);
}