uucore: correctly truncate response if getgroups shrinks#6978
Merged
sylvestre merged 2 commits intouutils:mainfrom Dec 19, 2024
santtu:patch-1
Merged
uucore: correctly truncate response if getgroups shrinks#6978sylvestre merged 2 commits intouutils:mainfrom santtu:patch-1
sylvestre merged 2 commits intouutils:mainfrom
santtu:patch-1
Conversation
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`.
|
GNU testsuite comparison: |
|
GNU testsuite comparison: |
sylvestre
reviewed
Dec 19, 2024
| 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 |
Contributor
There was a problem hiding this comment.
are you sure it is always increased ?
Contributor
Author
There was a problem hiding this comment.
POSIX.1-1988 on getgroups return value:
[EINVAL]
The gidsetsize argument is non-zero and less than the number of group IDs that would have been returned.
Since ngroups is based on earlier getgroups return value, the only case where EINVAL is returned when the indicated size (ngroups parameter for getgroups) is less than what the return list would be. If the reserved space is larger than the actual list, then res != -1.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The code above the line with
truncatehandles the case ifresis larger thanngroups, butres < ngroupsis also a possibility, which this line attempts to address but actually does not.The original code resizes to
ngroupswhich is a no-op (given thatgroupsis alreadyngroupssize). The correct target for re-sizing thegroupsis the result from the lastgetgroups, i.e.,res.