mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-29 03:57:44 +00:00
uucore: correctly truncate response if getgroups shrinks (#6978)
The code above this line handles the case if `res` is larger than `ngroups`, but `res < ngroups` is also a possibility, which this line attempts to address but actually does not. The original code resizes to `ngroups` which is a no-op (given that `groups` is already `ngroups` size). The correct target for re-sizing the `groups` is the result from the last `getgroups`, i.e., `res`.
This commit is contained in:
parent
4341ae3223
commit
2ae914b268
1 changed files with 3 additions and 2 deletions
|
@ -83,13 +83,14 @@ pub fn get_groups() -> IOResult<Vec<gid_t>> {
|
|||
if res == -1 {
|
||||
let err = IOError::last_os_error();
|
||||
if err.raw_os_error() == Some(libc::EINVAL) {
|
||||
// Number of groups changed, retry
|
||||
// Number of groups has increased, retry
|
||||
continue;
|
||||
} else {
|
||||
return Err(err);
|
||||
}
|
||||
} else {
|
||||
groups.truncate(ngroups.try_into().unwrap());
|
||||
// Number of groups may have decreased
|
||||
groups.truncate(res.try_into().unwrap());
|
||||
return Ok(groups);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue