Skip to content

Validate jobserver fd more conservatively #6

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 24, 2018
Merged
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
18 changes: 3 additions & 15 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -472,7 +472,7 @@ mod imp {
// If we're called from `make` *without* the leading + on our rule
// then we'll have `MAKEFLAGS` env vars but won't actually have
// access to the file descriptors.
if is_pipe(read) && is_pipe(write) {
if is_valid_fd(read) && is_valid_fd(write) {
drop(set_cloexec(read, true));
drop(set_cloexec(write, true));
Some(Client::from_fds(read, write))
Expand Down Expand Up @@ -653,21 +653,9 @@ mod imp {
}
}

#[allow(unused_assignments)]
fn is_pipe(fd: c_int) -> bool {
fn is_valid_fd(fd: c_int) -> bool {
unsafe {
let mut stat = mem::zeroed();
if libc::fstat(fd, &mut stat) == 0 {
// On android arm and i686 mode_t is u16 and st_mode is u32,
// this generates a type mismatch when S_IFIFO (declared as mode_t)
// is used in operations with st_mode, so we use this workaround
// to get the value of S_IFIFO with the same type of st_mode.
let mut s_ififo = stat.st_mode;
s_ififo = libc::S_IFIFO as _;
stat.st_mode & s_ififo == s_ififo
} else {
false
}
return libc::fcntl(fd, libc::F_GETFD) != -1;
}
}

Expand Down