Skip to content

Commit c2b101c

Browse files
committed
Bug 1854040: When doing UIA client detection on Windows 11, call GetNamedPipeServerProcessId before querying the handle's name. r=nlapre
Querying a handle's name can hang forever in some cases. I'm hoping (albeit doubtfully) that GetNamedPipeServerProcessId might not hang where querying the handle's name does, and also that the handle that's hanging isn't the handle we need. This seems to fix the problem for one user, so maybe my doubts are unfounded. Differential Revision: https://phabricator.services.mozilla.com/D197035
1 parent a90769d commit c2b101c

File tree

1 file changed

+12
-8
lines changed

1 file changed

+12
-8
lines changed

accessible/windows/msaa/CompatibilityUIA.cpp

+12-8
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,18 @@ static void GetUiaClientPidsWin11(nsTArray<DWORD>& aPids) {
162162
// We're only interested in handles in our own process.
163163
return true;
164164
}
165-
// Get the name of the handle.
165+
// UIA creates a named pipe between the client and server processes. We want
166+
// to find our handle to that pipe (if any). If this is a named pipe, get
167+
// the process id of the remote end. We do this first because querying the
168+
// name of the handle might hang in some cases. Counter-intuitively, for UIA
169+
// pipes, we're the client and the remote process is the server.
170+
ULONG pid = 0;
171+
::GetNamedPipeServerProcessId(aHandle, &pid);
172+
if (!pid) {
173+
return true;
174+
}
175+
// We know this is a named pipe and we have the pid. Now, get the name of
176+
// the handle and check whether it's a UIA pipe.
166177
ULONG objNameBufLen;
167178
NTSTATUS ntStatus = ::NtQueryObject(
168179
aHandle, (OBJECT_INFORMATION_CLASS)ObjectNameInformation, nullptr, 0,
@@ -184,14 +195,7 @@ static void GetUiaClientPidsWin11(nsTArray<DWORD>& aPids) {
184195
}
185196
nsDependentString objName(objNameInfo->Name.Buffer,
186197
objNameInfo->Name.Length / sizeof(wchar_t));
187-
188-
// UIA creates a named pipe between the client and server processes. Find
189-
// our handle to that pipe (if any).
190198
if (StringBeginsWith(objName, u"\\Device\\NamedPipe\\UIA_PIPE_"_ns)) {
191-
// Get the process id of the remote end. Counter-intuitively, for this
192-
// pipe, we're the client and the remote process is the server.
193-
ULONG pid = 0;
194-
::GetNamedPipeServerProcessId(aHandle, &pid);
195199
aPids.AppendElement(pid);
196200
}
197201
return true;

0 commit comments

Comments
 (0)