Skip to content

Commit

Permalink
Remove use of ngroups return value to size the buffer
Browse files Browse the repository at this point in the history
As mentioned in the PR comments, we may want to dynamically detect if the runtime `libc` appears to be setting `ngroups` to the required buffer size, rather than hardcoding based on target OS.  That may require a bit more conversation, and I think it's best to not tie up the buffer overrun fix in the meantime.
  • Loading branch information
vitalyd committed Sep 28, 2021
1 parent dbf3bf1 commit a236610
Showing 1 changed file with 2 additions and 10 deletions.
12 changes: 2 additions & 10 deletions src/unistd.rs
Expand Up @@ -1567,16 +1567,8 @@ pub fn getgrouplist(user: &CStr, group: Gid) -> Result<Vec<Gid>> {
// BSD systems will still fill the groups buffer with as many
// groups as possible, but Linux manpages do not mention this
// behavior.
// Linux stores the number of groups found in ngroups. We can
// use that to resize the buffer exactly.
cfg_if! {
if #[cfg(target_os = "linux")] {
groups.reserve_exact(ngroups as usize);
} else {
reserve_double_buffer_size(&mut groups, ngroups_max as usize)
.map_err(|_| Errno::EINVAL)?;
}
}
reserve_double_buffer_size(&mut groups, ngroups_max as usize)
.map_err(|_| Errno::EINVAL)?;
}
}
}
Expand Down

0 comments on commit a236610

Please sign in to comment.