diff --git a/CHANGELOG.md b/CHANGELOG.md index 5367d7a845..6eff5e1eca 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,14 @@ All notable changes to this project will be documented in this file. This project adheres to [Semantic Versioning](https://semver.org/). +## [0.22.2] - 28 September 2021 +### Added +### Changed +### Fixed + +- Fixed buffer overflow in `unistd::getgrouplist`. + (#[1545](https://github.com/nix-rust/nix/pull/1545)) + ## [0.22.1] - 13 August 2021 ### Added ### Changed diff --git a/src/unistd.rs b/src/unistd.rs index de3b049080..d94cb9933c 100644 --- a/src/unistd.rs +++ b/src/unistd.rs @@ -1530,8 +1530,7 @@ pub fn getgrouplist(user: &CStr, group: Gid) -> Result> { Ok(None) | Err(_) => ::max_value(), }; use std::cmp::min; - let mut ngroups = min(ngroups_max, 8); - let mut groups = Vec::::with_capacity(ngroups as usize); + let mut groups = Vec::::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; @@ -1541,6 +1540,7 @@ pub fn getgrouplist(user: &CStr, group: Gid) -> Result> { } 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,