Fix handle scan error checking
@@ -941,29 +941,30 @@ NTSTATUS PhpEnumHiddenProcessHandles(
if (!NT_SUCCESS(status = PhEnumProcesses(&processes)))
return status;
- if (NT_SUCCESS(NtGetNextProcess(
+ if (!NT_SUCCESS(status = NtGetNextProcess(
NULL,
- PROCESS_QUERY_LIMITED_INFORMATION,
+ ProcessQueryAccess,
0,
0,
&processHandle
)))
- {
+ goto CleanupExit;
+
while (TRUE)
{
- HANDLE newProcessHandle;
+ HANDLE enumProcessHandle;
PROCESS_EXTENDED_BASIC_INFORMATION basicInfo;
if (NT_SUCCESS(PhGetProcessExtendedBasicInformation(processHandle, &basicInfo)))
{
- if (!PhFindProcessInformation(PhProcessInformation, basicInfo.BasicInfo.UniqueProcessId))
+ if (!PhFindProcessInformation(processes, basicInfo.BasicInfo.UniqueProcessId))
{
PH_HIDDEN_PROCESS_ENTRY entry;
PPH_STRING fileName;
entry.ProcessId = basicInfo.BasicInfo.UniqueProcessId;
- if (NT_SUCCESS(status = PhGetProcessImageFileName(processHandle, &fileName)))
+ if (NT_SUCCESS(PhGetProcessImageFileName(processHandle, &fileName)))
{
entry.FileName = PhGetFileName(fileName);
PhDereferenceObject(fileName);
@@ -977,8 +978,7 @@ NTSTATUS PhpEnumHiddenProcessHandles(
PhDereferenceObject(entry.FileName);
}
-
- if (!NT_SUCCESS(status))
+ else
{
entry.FileName = NULL;
entry.Type = UnknownProcess;
@@ -991,14 +991,14 @@ NTSTATUS PhpEnumHiddenProcessHandles(
if (NT_SUCCESS(status = NtGetNextProcess(
processHandle,
- PROCESS_QUERY_LIMITED_INFORMATION,
+ ProcessQueryAccess,
0,
0,
- &newProcessHandle
+ &enumProcessHandle
)))
{
NtClose(processHandle);
- processHandle = newProcessHandle;
+ processHandle = enumProcessHandle;
}
else
{
@@ -1006,13 +1006,13 @@ NTSTATUS PhpEnumHiddenProcessHandles(
break;
}
}
- }
-
- PhFree(processes);
if (status == STATUS_NO_MORE_ENTRIES)
status = STATUS_SUCCESS; // HACK
+CleanupExit:
+ PhFree(processes);
+
return status;
}
