From a236610ef570d0c68f0eaf7fece2c3f4ed281122 Mon Sep 17 00:00:00 2001 From: vitalyd Date: Mon, 27 Sep 2021 15:52:13 -0400 Subject: [PATCH] Remove use of ngroups return value to size the buffer 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. --- src/unistd.rs | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/src/unistd.rs b/src/unistd.rs index cb6fc29bf8..a9862d37a3 100644 --- a/src/unistd.rs +++ b/src/unistd.rs @@ -1567,16 +1567,8 @@ pub fn getgrouplist(user: &CStr, group: Gid) -> Result> { // 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)?; } } }