Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Fix a race in internal calls into WMI that can result in an "invalid handle"
exception under high load. Patch by Chris Eibl.
22 changes: 11 additions & 11 deletions PC/_wmimodule.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,11 @@ _query_thread(LPVOID param)
IEnumWbemClassObject* enumerator = NULL;
HRESULT hr = S_OK;
BSTR bstrQuery = NULL;
struct _query_data *data = (struct _query_data*)param;
_query_data data = *(struct _query_data*)param;

// gh-125315: Copy the query string first, so that if the main thread gives
// up on waiting we aren't left with a dangling pointer (and a likely crash)
bstrQuery = SysAllocString(data->query);
bstrQuery = SysAllocString(data.query);
if (!bstrQuery) {
hr = HRESULT_FROM_WIN32(ERROR_NOT_ENOUGH_MEMORY);
}
Expand All @@ -71,7 +71,7 @@ _query_thread(LPVOID param)
}

if (FAILED(hr)) {
CloseHandle(data->writePipe);
CloseHandle(data.writePipe);
if (bstrQuery) {
SysFreeString(bstrQuery);
}
Expand All @@ -96,7 +96,7 @@ _query_thread(LPVOID param)
IID_IWbemLocator, (LPVOID *)&locator
);
}
if (SUCCEEDED(hr) && !SetEvent(data->initEvent)) {
if (SUCCEEDED(hr) && !SetEvent(data.initEvent)) {
hr = HRESULT_FROM_WIN32(GetLastError());
}
if (SUCCEEDED(hr)) {
Expand All @@ -105,7 +105,7 @@ _query_thread(LPVOID param)
NULL, NULL, 0, NULL, 0, 0, &services
);
}
if (SUCCEEDED(hr) && !SetEvent(data->connectEvent)) {
if (SUCCEEDED(hr) && !SetEvent(data.connectEvent)) {
hr = HRESULT_FROM_WIN32(GetLastError());
}
if (SUCCEEDED(hr)) {
Expand Down Expand Up @@ -143,7 +143,7 @@ _query_thread(LPVOID param)
if (FAILED(hr) || got != 1 || !value) {
continue;
}
if (!startOfEnum && !WriteFile(data->writePipe, (LPVOID)L"\0", 2, &written, NULL)) {
if (!startOfEnum && !WriteFile(data.writePipe, (LPVOID)L"\0", 2, &written, NULL)) {
hr = HRESULT_FROM_WIN32(GetLastError());
break;
}
Expand Down Expand Up @@ -171,10 +171,10 @@ _query_thread(LPVOID param)
DWORD cbStr1, cbStr2;
cbStr1 = (DWORD)(wcslen(propName) * sizeof(propName[0]));
cbStr2 = (DWORD)(wcslen(propStr) * sizeof(propStr[0]));
if (!WriteFile(data->writePipe, propName, cbStr1, &written, NULL) ||
!WriteFile(data->writePipe, (LPVOID)L"=", 2, &written, NULL) ||
!WriteFile(data->writePipe, propStr, cbStr2, &written, NULL) ||
!WriteFile(data->writePipe, (LPVOID)L"\0", 2, &written, NULL)
if (!WriteFile(data.writePipe, propName, cbStr1, &written, NULL) ||
!WriteFile(data.writePipe, (LPVOID)L"=", 2, &written, NULL) ||
!WriteFile(data.writePipe, propStr, cbStr2, &written, NULL) ||
!WriteFile(data.writePipe, (LPVOID)L"\0", 2, &written, NULL)
) {
hr = HRESULT_FROM_WIN32(GetLastError());
}
Expand All @@ -200,7 +200,7 @@ _query_thread(LPVOID param)
locator->Release();
}
CoUninitialize();
CloseHandle(data->writePipe);
CloseHandle(data.writePipe);
return (DWORD)hr;
}

Expand Down
Loading