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
This commit is contained in:
James Teh 2024-02-05 21:57:37 +00:00
Родитель a90769d041
Коммит c2b101c8e7
1 изменённых файлов: 12 добавлений и 8 удалений

Просмотреть файл

@ -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,
@ -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;