summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorvitalyd <vitalyd@gmail.com>2021-09-27 09:55:59 -0400
committerAlan Somers <asomers@gmail.com>2021-09-28 19:06:52 -0600
commit1671edc3e7d3fea63fbf721071bd2ddbad8e9e67 (patch)
treef380df87b8965e37a7d5c7e908b39d9047f01758 /src
parent9a2f86f4cf9bddefc1878a124b4ee6f83e6ef064 (diff)
downloadnix-1671edc3e7d3fea63fbf721071bd2ddbad8e9e67.zip
Fix memory unsafety in unistd::getgrouplist
Fixes #1541
Diffstat (limited to 'src')
-rw-r--r--src/unistd.rs4
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,