Commit e1c3ee6d authored by Paul Gofman's avatar Paul Gofman Committed by Alexandre Julliard

server: Do not allow parenting non-empty job.

Fixes a regression introduced by 21f5597dSigned-off-by: 's avatarPaul Gofman <pgofman@codeweavers.com> Signed-off-by: 's avatarAlexandre Julliard <julliard@winehq.org>
parent 543e4939
......@@ -4502,6 +4502,7 @@ done:
static void test_nested_jobs(void)
{
BOOL ret, already_in_job = TRUE, create_succeeded = FALSE;
PROCESS_INFORMATION info[2];
char buffer[MAX_PATH + 26];
STARTUPINFOA si = {0};
......@@ -4514,6 +4515,65 @@ static void test_nested_jobs(void)
return;
}
job1 = pCreateJobObjectW(NULL, NULL);
ok(!!job1, "CreateJobObjectW failed, error %u.\n", GetLastError());
job2 = pCreateJobObjectW(NULL, NULL);
ok(!!job2, "CreateJobObjectW failed, error %u.\n", GetLastError());
create_succeeded = TRUE;
sprintf(buffer, "\"%s\" process wait", selfname);
for (i = 0; i < 2; ++i)
{
ret = CreateProcessA(NULL, buffer, NULL, NULL, FALSE, CREATE_BREAKAWAY_FROM_JOB, NULL, NULL, &si, &info[i]);
if (!ret && GetLastError() == ERROR_ACCESS_DENIED)
{
create_succeeded = FALSE;
break;
}
ok(ret, "CreateProcessA error %u\n", GetLastError());
}
if (create_succeeded)
{
ret = pIsProcessInJob(info[0].hProcess, NULL, &already_in_job);
ok(ret, "IsProcessInJob error %u\n", GetLastError());
if (!already_in_job)
{
ret = pAssignProcessToJobObject(job2, info[1].hProcess);
ok(ret, "AssignProcessToJobObject error %u\n", GetLastError());
ret = pAssignProcessToJobObject(job1, info[0].hProcess);
ok(ret, "AssignProcessToJobObject error %u\n", GetLastError());
ret = pAssignProcessToJobObject(job2, info[0].hProcess);
ok(!ret, "AssignProcessToJobObject succeeded\n");
ok(GetLastError() == ERROR_ACCESS_DENIED, "Got unexpected error %u.\n", GetLastError());
TerminateProcess(info[1].hProcess, 0);
wait_child_process(info[1].hProcess);
CloseHandle(info[1].hProcess);
CloseHandle(info[1].hThread);
ret = pAssignProcessToJobObject(job2, info[0].hProcess);
ok(!ret, "AssignProcessToJobObject succeeded\n");
ok(GetLastError() == ERROR_ACCESS_DENIED, "Got unexpected error %u.\n", GetLastError());
}
TerminateProcess(info[0].hProcess, 0);
wait_child_process(info[0].hProcess);
CloseHandle(info[0].hProcess);
CloseHandle(info[0].hThread);
}
if (already_in_job)
{
win_skip("Test process is already in job, can't test parenting non-empty job.\n");
}
CloseHandle(job1);
CloseHandle(job2);
job1 = pCreateJobObjectW(NULL, L"test_nested_jobs_0");
ok(!!job1, "CreateJobObjectW failed, error %u.\n", GetLastError());
job2 = pCreateJobObjectW(NULL, L"test_nested_jobs_1");
......
......@@ -311,6 +311,11 @@ static void add_job_process( struct job *job, struct process *process )
}
else
{
if (job->total_processes)
{
set_error( STATUS_ACCESS_DENIED );
return;
}
/* transfer reference. */
job->parent = process->job;
list_add_tail( &job->parent->child_job_list, &job->parent_job_entry );
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment