diff options
author | vitalyd <vitalyd@gmail.com> | 2021-09-27 09:55:59 -0400 |
---|---|---|
committer | Alan Somers <asomers@gmail.com> | 2021-09-28 19:06:52 -0600 |
commit | 1671edc3e7d3fea63fbf721071bd2ddbad8e9e67 (patch) | |
tree | f380df87b8965e37a7d5c7e908b39d9047f01758 /src | |
parent | 9a2f86f4cf9bddefc1878a124b4ee6f83e6ef064 (diff) | |
download | nix-1671edc3e7d3fea63fbf721071bd2ddbad8e9e67.zip |
Fix memory unsafety in unistd::getgrouplist
Fixes #1541
Diffstat (limited to 'src')
-rw-r--r-- | src/unistd.rs | 4 |
1 files changed, 2 insertions, 2 deletions
diff --git a/src/unistd.rs b/src/unistd.rs index 64759dc6..a9862d37 100644 --- a/src/unistd.rs +++ b/src/unistd.rs @@ -1540,8 +1540,7 @@ pub fn getgrouplist(user: &CStr, group: Gid) -> Result<Vec<Gid>> { Ok(None) | Err(_) => <c_int>::max_value(), }; use std::cmp::min; - let mut ngroups = min(ngroups_max, 8); - let mut groups = Vec::<Gid>::with_capacity(ngroups as usize); + let mut groups = Vec::<Gid>::with_capacity(min(ngroups_max, 8) as usize); cfg_if! { if #[cfg(any(target_os = "ios", target_os = "macos"))] { type getgrouplist_group_t = c_int; @@ -1551,6 +1550,7 @@ pub fn getgrouplist(user: &CStr, group: Gid) -> Result<Vec<Gid>> { } let gid: gid_t = group.into(); loop { + let mut ngroups = groups.capacity() as i32; let ret = unsafe { libc::getgrouplist(user.as_ptr(), gid as getgrouplist_group_t, |