Skip to content

Conversation

@vstinner
Copy link
Member

@vstinner vstinner commented Mar 23, 2020

On Darwin 19.3 (macOS 10.15 Catalina), getgrouplist() returns a
non-zero value without setting errno if the group list is too small.
Double the list size and call it again in this case.

https://bugs.python.org/issue40014

@vstinner
Copy link
Member Author

@ambv @ned-deily: Would you mind to review this fix?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just question:
I 've understood the situation.

Is there any reason not to try with INT_MAX for the last trying?

if (ngroups == INT_MAX) {
   return PyErr_NoMemory();
} else if (ngroups > INT_MAX / 2) {
    ngroups = INT_MAX;
} else {
    ngroups *= 2;
}

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If (ngroups > INT_MAX / 2) is false, ngroups *= 2 would overflow: ngroups type is int.

} else if (ngroups > INT_MAX / 2) {
    ngroups = INT_MAX;

I don't think that it's worth it to bother with attempting that. I don't think that any user has more than 1073741823 groups. Such user is going to get larger issues than that.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay got it :) Sounds reasonable.

Copy link
Member

@ned-deily ned-deily left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The change itself looks good, thanks. But, as noted on the bpo, with further testing, it seems this is not a new issue with 10.15: it also fails on 10.14 and 10.13. I didn't test any older systems. So the comments and the PR title should be changed to remove the version references and just refer to something like "some versions of macOS".

@bedevere-bot
Copy link

When you're done making the requested changes, leave the comment: I have made the requested changes; please review again.

On macOS, getgrouplist() returns a non-zero value without setting
errno if the group list is too small.  Double the list size and call
it again in this case.
@vstinner
Copy link
Member Author

The change itself looks good, thanks. But, as noted on the bpo, with further testing, it seems this is not a new issue with 10.15: it also fails on 10.14 and 10.13. I didn't test any older systems. So the comments and the PR title should be changed to remove the version references and just refer to something like "some versions of macOS".

Sorry, I missed that comment. I rewrote my PR to remove all Darwin and macOS versions. I just wrote "on macOS", it should be enough ;-) I added the bpo number anyway, for curious people wanting the further details ;-)

@ned-deily ned-deily changed the title bpo-40014: Fix os.getgrouplist() on macOS 10.5 bpo-40014: Fix os.getgrouplist() failure on macOS with many groups Mar 23, 2020
Copy link
Member

@ned-deily ned-deily left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks

@vstinner vstinner merged commit 8ec7370 into python:master Mar 23, 2020
@miss-islington
Copy link
Contributor

Thanks @vstinner for the PR 🌮🎉.. I'm working now to backport this PR to: 3.7, 3.8.
🐍🍒⛏🤖

@vstinner vstinner deleted the getgrouplist_macos branch March 23, 2020 19:01
miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Mar 23, 2020
On macOS, getgrouplist() returns a non-zero value without setting
errno if the group list is too small. Double the list size and call
it again in this case.
(cherry picked from commit 8ec7370)

Co-authored-by: Victor Stinner <[email protected]>
@bedevere-bot
Copy link

GH-19123 is a backport of this pull request to the 3.8 branch.

@bedevere-bot
Copy link

GH-19124 is a backport of this pull request to the 3.7 branch.

miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Mar 23, 2020
On macOS, getgrouplist() returns a non-zero value without setting
errno if the group list is too small. Double the list size and call
it again in this case.
(cherry picked from commit 8ec7370)

Co-authored-by: Victor Stinner <[email protected]>
miss-islington added a commit that referenced this pull request Mar 23, 2020
On macOS, getgrouplist() returns a non-zero value without setting
errno if the group list is too small. Double the list size and call
it again in this case.
(cherry picked from commit 8ec7370)

Co-authored-by: Victor Stinner <[email protected]>
miss-islington added a commit that referenced this pull request Mar 23, 2020
On macOS, getgrouplist() returns a non-zero value without setting
errno if the group list is too small. Double the list size and call
it again in this case.
(cherry picked from commit 8ec7370)

Co-authored-by: Victor Stinner <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants