authorgravatar for mlugg@mlugg.co.ukMatthew Lugg <mlugg@mlugg.co.uk> 2024-05-26 01:50:54+01:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2024-05-27 20:56:48-07:00
logacdf988c24c51129ed3ad9929b6ed8482b9abe54
treef3b0bd3e7800d23b2b75ca5e06477a563c248043
parent9331da8fe3854c57446574a1afc75e6e0811f610

std.process.Child: prevent racing children from inheriting progress pipes

This fix is already in master branch for stdin, stdout, and stderr; this commit solves the same problem but for the progress pipe. Both fixes were originally included in one commit on this branch, however it was split it into two so that master branch could receive the fix before the progress branch is merged.

1 files changed, 2 insertions(+), 7 deletions(-)

lib/std/process/Child.zig+2-7
......@@ -587,8 +587,8 @@ fn spawnPosix(self: *ChildProcess) SpawnError!void {
587587 if (self.progress_node.index == .none) {
588588 break :p .{ -1, -1 };
589589 } else {
590 // No CLOEXEC because the child needs access to this file descriptor.
591 break :p try posix.pipe2(.{ .NONBLOCK = true });
590 // We use CLOEXEC for the same reason as in `pipe_flags`.
591 break :p try posix.pipe2(.{ .NONBLOCK = true, .CLOEXEC = true });
592592 }
593593 };
594594 errdefer destroyPipe(prog_pipe);
......@@ -655,11 +655,6 @@ fn spawnPosix(self: *ChildProcess) SpawnError!void {
655655 setUpChildIo(self.stderr_behavior, stderr_pipe[1], posix.STDERR_FILENO, dev_null_fd) catch |err| forkChildErrReport(err_pipe[1], err);
656656 if (prog_pipe[1] != -1) posix.dup2(prog_pipe[1], prog_fileno) catch |err| forkChildErrReport(err_pipe[1], err);
657657
658 if (prog_pipe[1] != -1) {
659 if (prog_pipe[0] != prog_fileno) posix.close(prog_pipe[0]);
660 if (prog_pipe[1] != prog_fileno) posix.close(prog_pipe[1]);
661 }
662
663658 if (self.cwd_dir) |cwd| {
664659 posix.fchdir(cwd.fd) catch |err| forkChildErrReport(err_pipe[1], err);
665660 } else if (self.cwd) |cwd| {