Improve enumeration of processes in a job
@@ -2049,9 +2049,10 @@ NTSTATUS PhGetJobProcessIdList(
{
NTSTATUS status;
PVOID buffer;
- ULONG bufferSize;
+ ULONG bufferSize = 0x100;
- bufferSize = 0x100;
+ do
+ {
buffer = PhAllocate(bufferSize);
status = NtQueryInformationJobObject(
@@ -2062,27 +2063,16 @@ NTSTATUS PhGetJobProcessIdList(
&bufferSize
);
- if (status == STATUS_BUFFER_OVERFLOW)
+ if (NT_SUCCESS(status))
{
- PhFree(buffer);
- buffer = PhAllocate(bufferSize);
-
- status = NtQueryInformationJobObject(
- JobHandle,
- JobObjectBasicProcessIdList,
- buffer,
- bufferSize,
- NULL
- );
+ *ProcessIdList = (PJOBOBJECT_BASIC_PROCESS_ID_LIST)buffer;
}
-
- if (!NT_SUCCESS(status))
+ else
{
PhFree(buffer);
- return status;
}
- *ProcessIdList = (PJOBOBJECT_BASIC_PROCESS_ID_LIST)buffer;
+ } while (status == STATUS_BUFFER_OVERFLOW);
return status;
}
