Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 81c348b

Browse filesBrowse files
GH-130727: Avoid race condition in _wmimodule by copying shared data (GH-134313)
(cherry picked from commit e4fbfb1) Co-authored-by: Chris Eibl <138194463+chris-eibl@users.noreply.github.com>
1 parent 69710b7 commit 81c348b
Copy full SHA for 81c348b

File tree

Expand file treeCollapse file tree

2 files changed

+13
-11
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+13
-11
lines changed
+2Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Fix a race in internal calls into WMI that can result in an "invalid handle"
2+
exception under high load. Patch by Chris Eibl.

‎PC/_wmimodule.cpp

Copy file name to clipboardExpand all lines: PC/_wmimodule.cpp
+11-11Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -57,11 +57,11 @@ _query_thread(LPVOID param)
5757
IEnumWbemClassObject* enumerator = NULL;
5858
HRESULT hr = S_OK;
5959
BSTR bstrQuery = NULL;
60-
struct _query_data *data = (struct _query_data*)param;
60+
_query_data data = *(struct _query_data*)param;
6161

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

7373
if (FAILED(hr)) {
74-
CloseHandle(data->writePipe);
74+
CloseHandle(data.writePipe);
7575
if (bstrQuery) {
7676
SysFreeString(bstrQuery);
7777
}
@@ -96,7 +96,7 @@ _query_thread(LPVOID param)
9696
IID_IWbemLocator, (LPVOID *)&locator
9797
);
9898
}
99-
if (SUCCEEDED(hr) && !SetEvent(data->initEvent)) {
99+
if (SUCCEEDED(hr) && !SetEvent(data.initEvent)) {
100100
hr = HRESULT_FROM_WIN32(GetLastError());
101101
}
102102
if (SUCCEEDED(hr)) {
@@ -105,7 +105,7 @@ _query_thread(LPVOID param)
105105
NULL, NULL, 0, NULL, 0, 0, &services
106106
);
107107
}
108-
if (SUCCEEDED(hr) && !SetEvent(data->connectEvent)) {
108+
if (SUCCEEDED(hr) && !SetEvent(data.connectEvent)) {
109109
hr = HRESULT_FROM_WIN32(GetLastError());
110110
}
111111
if (SUCCEEDED(hr)) {
@@ -143,7 +143,7 @@ _query_thread(LPVOID param)
143143
if (FAILED(hr) || got != 1 || !value) {
144144
continue;
145145
}
146-
if (!startOfEnum && !WriteFile(data->writePipe, (LPVOID)L"\0", 2, &written, NULL)) {
146+
if (!startOfEnum && !WriteFile(data.writePipe, (LPVOID)L"\0", 2, &written, NULL)) {
147147
hr = HRESULT_FROM_WIN32(GetLastError());
148148
break;
149149
}
@@ -171,10 +171,10 @@ _query_thread(LPVOID param)
171171
DWORD cbStr1, cbStr2;
172172
cbStr1 = (DWORD)(wcslen(propName) * sizeof(propName[0]));
173173
cbStr2 = (DWORD)(wcslen(propStr) * sizeof(propStr[0]));
174-
if (!WriteFile(data->writePipe, propName, cbStr1, &written, NULL) ||
175-
!WriteFile(data->writePipe, (LPVOID)L"=", 2, &written, NULL) ||
176-
!WriteFile(data->writePipe, propStr, cbStr2, &written, NULL) ||
177-
!WriteFile(data->writePipe, (LPVOID)L"\0", 2, &written, NULL)
174+
if (!WriteFile(data.writePipe, propName, cbStr1, &written, NULL) ||
175+
!WriteFile(data.writePipe, (LPVOID)L"=", 2, &written, NULL) ||
176+
!WriteFile(data.writePipe, propStr, cbStr2, &written, NULL) ||
177+
!WriteFile(data.writePipe, (LPVOID)L"\0", 2, &written, NULL)
178178
) {
179179
hr = HRESULT_FROM_WIN32(GetLastError());
180180
}
@@ -200,7 +200,7 @@ _query_thread(LPVOID param)
200200
locator->Release();
201201
}
202202
CoUninitialize();
203-
CloseHandle(data->writePipe);
203+
CloseHandle(data.writePipe);
204204
return (DWORD)hr;
205205
}
206206

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.