Skip to content

Commit 94ccf88

Browse files
vitalydasomers
authored andcommitted
Fix memory unsafety in unistd::getgrouplist
Fixes #1541
1 parent de534c1 commit 94ccf88

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,14 @@ All notable changes to this project will be documented in this file.
44
This project adheres to [Semantic Versioning](http://semver.org/).
55
This project adheres to [Semantic Versioning](https://semver.org/).
66

7+
## [0.20.2] - 28 September 2021
8+
### Added
9+
### Changed
10+
### Fixed
11+
12+
- Fixed buffer overflow in `unistd::getgrouplist`.
13+
(#[1545](https://github.com/nix-rust/nix/pull/1545))
14+
715
## [0.20.1] - 13 August 2021
816
### Added
917
### Changed

src/unistd.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1514,8 +1514,7 @@ pub fn getgrouplist(user: &CStr, group: Gid) -> Result<Vec<Gid>> {
15141514
Ok(None) | Err(_) => <c_int>::max_value(),
15151515
};
15161516
use std::cmp::min;
1517-
let mut ngroups = min(ngroups_max, 8);
1518-
let mut groups = Vec::<Gid>::with_capacity(ngroups as usize);
1517+
let mut groups = Vec::<Gid>::with_capacity(min(ngroups_max, 8) as usize);
15191518
cfg_if! {
15201519
if #[cfg(any(target_os = "ios", target_os = "macos"))] {
15211520
type getgrouplist_group_t = c_int;
@@ -1525,6 +1524,7 @@ pub fn getgrouplist(user: &CStr, group: Gid) -> Result<Vec<Gid>> {
15251524
}
15261525
let gid: gid_t = group.into();
15271526
loop {
1527+
let mut ngroups = groups.capacity() as i32;
15281528
let ret = unsafe {
15291529
libc::getgrouplist(user.as_ptr(),
15301530
gid as getgrouplist_group_t,

0 commit comments

Comments
 (0)