Skip to content

Commit 3f0847d

Browse files
committed
Close unused ends of intermediate_pids_sockets sooner
Instead of making this conditional and keeping track of the correct condition under which to call it, we can use cleanup_fdp(), which is a no-op when called with a pointer to a negative number, to close the socket unconditionally. In the parent bwrap monitor process (outside the sandbox), we never want to use the write end (which is reserved for the child), so we can and should close it as soon as we have forked. Conversely, in the child process, we never want to use the read end (which is reserved for the parent), so we should close that as soon as we know we are in the child. Signed-off-by: Simon McVittie <smcv@collabora.com>
1 parent 06bbd28 commit 3f0847d

1 file changed

Lines changed: 3 additions & 3 deletions

File tree

bubblewrap.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3143,10 +3143,10 @@ main (int argc,
31433143
if (pid != 0)
31443144
{
31453145
/* Parent, outside sandbox, privileged (initially) */
3146+
cleanup_fdp (&intermediate_pids_sockets[PIPE_WRITE_END]);
31463147

31473148
if (intermediate_pids_sockets[PIPE_READ_END] != -1)
31483149
{
3149-
close (intermediate_pids_sockets[PIPE_WRITE_END]);
31503150
pid = read_pid_from_socket (intermediate_pids_sockets[PIPE_READ_END]);
31513151
close (intermediate_pids_sockets[PIPE_READ_END]);
31523152
}
@@ -3212,6 +3212,8 @@ main (int argc,
32123212
return monitor_child (event_fd, pid, setup_finished_pipe[0]);
32133213
}
32143214

3215+
cleanup_fdp (&intermediate_pids_sockets[PIPE_READ_END]);
3216+
32153217
if (opt_pidns_fd > 0)
32163218
{
32173219
if (setns (opt_pidns_fd, CLONE_NEWPID) != 0)
@@ -3231,8 +3233,6 @@ main (int argc,
32313233
}
32323234

32333235
/* We're back, either in a child or grandchild, so message the actual pid to the monitor */
3234-
3235-
close (intermediate_pids_sockets[PIPE_READ_END]);
32363236
send_pid_on_socket (intermediate_pids_sockets[PIPE_WRITE_END]);
32373237
close (intermediate_pids_sockets[PIPE_WRITE_END]);
32383238
}

0 commit comments

Comments
 (0)