Skip to content

Commit

Permalink
Bug 1854040: When doing UIA client detection on Windows 11, call GetN…
Browse files Browse the repository at this point in the history
…amedPipeServerProcessId 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
  • Loading branch information
jcsteh committed Feb 5, 2024
1 parent a90769d commit c2b101c
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions accessible/windows/msaa/CompatibilityUIA.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,18 @@ static void GetUiaClientPidsWin11(nsTArray<DWORD>& aPids) {
// We're only interested in handles in our own process.
return true;
}
// Get the name of the handle.
// UIA creates a named pipe between the client and server processes. We want
// to find our handle to that pipe (if any). If this is a named pipe, get
// the process id of the remote end. We do this first because querying the
// name of the handle might hang in some cases. Counter-intuitively, for UIA
// pipes, we're the client and the remote process is the server.
ULONG pid = 0;
::GetNamedPipeServerProcessId(aHandle, &pid);
if (!pid) {
return true;
}
// We know this is a named pipe and we have the pid. Now, get the name of
// the handle and check whether it's a UIA pipe.
ULONG objNameBufLen;
NTSTATUS ntStatus = ::NtQueryObject(
aHandle, (OBJECT_INFORMATION_CLASS)ObjectNameInformation, nullptr, 0,
Expand All @@ -184,14 +195,7 @@ static void GetUiaClientPidsWin11(nsTArray<DWORD>& aPids) {
}
nsDependentString objName(objNameInfo->Name.Buffer,
objNameInfo->Name.Length / sizeof(wchar_t));

// UIA creates a named pipe between the client and server processes. Find
// our handle to that pipe (if any).
if (StringBeginsWith(objName, u"\\Device\\NamedPipe\\UIA_PIPE_"_ns)) {
// Get the process id of the remote end. Counter-intuitively, for this
// pipe, we're the client and the remote process is the server.
ULONG pid = 0;
::GetNamedPipeServerProcessId(aHandle, &pid);
aPids.AppendElement(pid);
}
return true;
Expand Down

0 comments on commit c2b101c

Please sign in to comment.