Skip to content

bpo-35070: test_getgrouplist may fail on macOS if too many groups#13071

Merged
ned-deily merged 3 commits into
python:masterfrom
websurfer5:fix-issue-35070
Jun 13, 2019
Merged

bpo-35070: test_getgrouplist may fail on macOS if too many groups#13071
ned-deily merged 3 commits into
python:masterfrom
websurfer5:fix-issue-35070

Conversation

@websurfer5

@websurfer5 websurfer5 commented May 2, 2019

Copy link
Copy Markdown
Contributor

The test_getgroups subtest fails when the current user running the
test belongs to the maximum number supplemental groups. It
fails because posix.getgrouplist() passes an array to the POSIX API
function getgrouplist() that is too small. It uses NGROUPS_MAX to
determine the size of the array that it passes to getgrouplist()
to be filled with the user's GIDs. NGROUPS_MAX is defined by POSIX.1
as the maximum number of supplimental groups a user can belong to.
The value has to be increased by one because getgrouplist() returns
both the supplemental groups and the primary group, i.e. all of the
groups the user belongs to.

NGROUPS_MAX is defined as 16 on OS X systems, so the test fails when
the user belongs to 16 supplemental groups because it passes an array
with 16 elements to receive the GIDs, but getgrouplist() returns an
error because it wants to return 17 GIDs (the primary plus 16
supplemntals).

This problem most likely is not seen on Linux systems because they typically
have a much higher limit for supplemental groups (e.g. 65,536 on
Ubuntu 16.04.4).

https://bugs.python.org/issue35070

The test_getgroups subtest fails when the current user running the
test belongs to the maximum number supplemental groups. It
fails because posix.getgrouplist() passes an array to the POSIX API
function getgrouplist() that is too small. It uses NGROUPS_MAX to
determine the size of the array that it passes to getgrouplist()
to be filled with the user's GIDs. NGROUPS_MAX is defined by POSIX.1
as the maximum number of supplimental groups a user can belong to.
The value has to be increased by one because getgrouplist() returns
both the supplemental groups and the primary group, i.e. all of the
groups the user belongs to.

NGROUPS_MAX is defined as 16 on OS X systems, so the test fails when
the user belongs to 16 supplemental groups because it passes an array
with 16 elements to receive the GIDs, but getgrouplist() returns an
error because it wants to return 17 GIDs (the primary plus 16
supplemntals).

This problem most likely is not seen on Linux systems because they typically
have a much higher limit for supplemental groups (e.g. 65,536 on
Ubuntu 16.04.4).
@eamanu

eamanu commented May 3, 2019

Copy link
Copy Markdown
Contributor

Hello @websurfer5. Try edit the PR's title and change BPO for bpo, this way Bedevere
will detect the issue number

@websurfer5 websurfer5 changed the title BPO-35070: test_posix fails on macOS 10.14 Mojave bpo-35070: test_posix fails on macOS 10.14 Mojave May 3, 2019

@dpage dpage left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

This patch resolves the regression test failures I've been seeing on macOS Mojave.

@@ -0,0 +1 @@
posix.getgrouplist() fails when when the user has NGROUPS_MAX supplemental GIDs. This becomes a problem on OS X Mojave (14.x) because the system defines NGROUPS_MAX to be 16 and it is common for a user to belong to 16 groups. The fix is to increase the size of the array passed to the underlying getgrouplist() POSIX API function to allow space for the user's primary group, which is not accounted for in the NGROUPS_MAX constant (per POSIX.1). No newline at end of file

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks for adding the blurb entry. It's a bit too verbose, though. It should only be one or two sentences and just needs to say something about preventing test_getgrouplist failures on macOS. If anyone needs to find more detaill, they can refer to the code. Also, this problem is not new to macOS 10.14; it only depends on how many groups the user is a member of. So the test may pass on 10.14 and may fail on older systems.

Comment thread Modules/posixmodule.c Outdated
* and the primary group, i.e. all of the groups the
* user belongs to.
*/
#define MAX_GROUPS (NGROUPS_MAX + 1)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

MAX_GROUPS is also defined later in posixmodule.c in os_getgroups_impl. Without also changing it, the fix here can cause a compile warning:

../../source/Modules/posixmodule.c:6831:9: warning: 'MAX_GROUPS' macro redefined [-Wmacro-redefined]
#define MAX_GROUPS NGROUPS_MAX
        ^
../../source/Modules/posixmodule.c:6746:9: note: previous definition is here
#define MAX_GROUPS (NGROUPS_MAX + 1)
        ^

The simplest fix is to also change the latter definition to be NGROUPS_MAX + 1.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I have made the requested changes; please review again

@bedevere-bot

Copy link
Copy Markdown

A Python core developer has requested some changes be made to your pull request before we can consider merging it. If you could please address their requests along with any other requests in other reviews from core developers that would be appreciated.

Once you have made the requested changes, please leave a comment on this pull request containing the phrase I have made the requested changes; please review again. I will then notify any core developers who have left a review that you're ready for them to take another look at this pull request.

And if you don't make the requested changes, you will be put in the comfy chair!

@ned-deily ned-deily changed the title bpo-35070: test_posix fails on macOS 10.14 Mojave bpo-35070: test_getgrouplist may fail on macOS if too many groups Jun 3, 2019
…istent

throughout the source file; update news blurb with requested changes
@ned-deily
ned-deily merged commit 8725c83 into python:master Jun 13, 2019
@miss-islington

Copy link
Copy Markdown
Contributor

Thanks @websurfer5 for the PR, and @ned-deily for merging it 🌮🎉.. I'm working now to backport this PR to: 3.7.
🐍🍒⛏🤖

miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Jun 13, 2019
…thonGH-13071)

(cherry picked from commit 8725c83)

Co-authored-by: Jeffrey Kintscher <49998481+websurfer5@users.noreply.github.com>
@bedevere-bot

Copy link
Copy Markdown

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

@miss-islington

Copy link
Copy Markdown
Contributor

Thanks @websurfer5 for the PR, and @ned-deily for merging it 🌮🎉.. I'm working now to backport this PR to: 3.7.
🐍🍒⛏🤖

@miss-islington

Copy link
Copy Markdown
Contributor

Thanks @websurfer5 for the PR, and @ned-deily for merging it 🌮🎉.. I'm working now to backport this PR to: 3.8.
🐍🍒⛏🤖

miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Jun 13, 2019
…thonGH-13071)

(cherry picked from commit 8725c83)

Co-authored-by: Jeffrey Kintscher <49998481+websurfer5@users.noreply.github.com>
@bedevere-bot

Copy link
Copy Markdown

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

miss-islington added a commit that referenced this pull request Jun 13, 2019
…-13071)

(cherry picked from commit 8725c83)

Co-authored-by: Jeffrey Kintscher <49998481+websurfer5@users.noreply.github.com>
miss-islington added a commit that referenced this pull request Jun 13, 2019
…-13071)

(cherry picked from commit 8725c83)

Co-authored-by: Jeffrey Kintscher <49998481+websurfer5@users.noreply.github.com>
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.

7 participants