Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions bubblewrap.c
Original file line number Diff line number Diff line change
Expand Up @@ -3112,7 +3112,7 @@ main (int argc,
}

/* Switch to the custom user ns before the clone, gets us privs in that ns (assuming its a child of the current and thus allowed) */
if (opt_userns_fd > 0 && setns (opt_userns_fd, CLONE_NEWUSER) != 0)
if (opt_userns_fd != -1 && setns (opt_userns_fd, CLONE_NEWUSER) != 0)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's use >= 0 because this really is what makes the fd valid.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Every other check uses != -1. Unexpected invalid fds failing loudly seems like an upside.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fair

{
if (errno == EINVAL)
die ("Joining the specified user namespace failed, it might not be a descendant of the current user namespace.");
Expand Down Expand Up @@ -3178,7 +3178,7 @@ main (int argc,

/* Initial launched process, wait for pid 1 or exec:ed command to exit */

if (opt_userns2_fd > 0 && setns (opt_userns2_fd, CLONE_NEWUSER) != 0)
if (opt_userns2_fd != -1 && setns (opt_userns2_fd, CLONE_NEWUSER) != 0)
die_with_error ("Setting userns2 failed");

/* We don't need any privileges in the launcher, drop them immediately. */
Expand Down Expand Up @@ -3219,7 +3219,7 @@ main (int argc,
return monitor_child (event_fd, pid, setup_finished_pipe[0]);
}

if (opt_pidns_fd > 0)
if (opt_pidns_fd != -1)
{
if (setns (opt_pidns_fd, CLONE_NEWPID) != 0)
die_with_error ("Setting pidns failed");
Expand Down Expand Up @@ -3446,7 +3446,7 @@ main (int argc,
die_with_error ("chdir /");
}

if (opt_userns2_fd > 0 && setns (opt_userns2_fd, CLONE_NEWUSER) != 0)
if (opt_userns2_fd != -1 && setns (opt_userns2_fd, CLONE_NEWUSER) != 0)
die_with_error ("Setting userns2 failed");

if (opt_unshare_user && opt_userns_block_fd == -1 &&
Expand Down