Skip to content

Commit 1afc36e

Browse files
committed
Windows: Fix buffer size of QueryInformationJobObject request
As noted in GHC #17926, the QueryInformationJobObject system call apparently relies on the buffer size in addition to the NumberOfAssignedProcesses field to determine how many results it should return. For this reason it's important that we pass the true size of the buffer to the call.
1 parent 8fffea5 commit 1afc36e

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

cbits/runProcess.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -862,8 +862,10 @@ waitForJobCompletion ( HANDLE hJob )
862862
JOBOBJECT_BASIC_PROCESS_ID_LIST *pid_list = NULL;
863863

864864
while (true) {
865+
size_t pid_list_size = sizeof(JOBOBJECT_BASIC_PROCESS_ID_LIST) + sizeof(ULONG_PTR) * (process_count - 1);
866+
865867
if (pid_list == NULL) {
866-
pid_list = malloc(sizeof(JOBOBJECT_BASIC_PROCESS_ID_LIST) + sizeof(ULONG_PTR) * process_count);
868+
pid_list = malloc(pid_list_size);
867869
pid_list->NumberOfAssignedProcesses = process_count;
868870
}
869871

@@ -872,7 +874,7 @@ waitForJobCompletion ( HANDLE hJob )
872874
hJob,
873875
JobObjectBasicProcessIdList,
874876
pid_list,
875-
sizeof(JOBOBJECT_BASIC_PROCESS_ID_LIST),
877+
pid_list_size,
876878
NULL);
877879

878880
if (!success && GetLastError() == ERROR_MORE_DATA) {

0 commit comments

Comments
 (0)