diff options
author | Jeffrey Kintscher <49998481+websurfer5@users.noreply.github.com> | 2019-06-13 07:01:29 (GMT) |
---|---|---|
committer | Ned Deily <nad@python.org> | 2019-06-13 07:01:29 (GMT) |
commit | 8725c83ed5ca8959195ad8326db99d564a921749 (patch) | |
tree | 23f300bdd1f775b164bbeba50db899ddaecda915 | |
parent | 905e19a9bf9afd6439ea44fc6a4f3c8631750d6d (diff) | |
download | cpython-8725c83ed5ca8959195ad8326db99d564a921749.zip cpython-8725c83ed5ca8959195ad8326db99d564a921749.tar.gz cpython-8725c83ed5ca8959195ad8326db99d564a921749.tar.bz2 |
bpo-35070: test_getgrouplist may fail on macOS if too many groups (GH-13071)
-rw-r--r-- | Misc/NEWS.d/next/Library/2019-05-09-18-50-55.bpo-35070.4vaqNL.rst | 2 | ||||
-rw-r--r-- | Modules/posixmodule.c | 32 |
2 files changed, 19 insertions, 15 deletions
diff --git a/Misc/NEWS.d/next/Library/2019-05-09-18-50-55.bpo-35070.4vaqNL.rst b/Misc/NEWS.d/next/Library/2019-05-09-18-50-55.bpo-35070.4vaqNL.rst new file mode 100644 index 0000000..e823f1d --- /dev/null +++ b/Misc/NEWS.d/next/Library/2019-05-09-18-50-55.bpo-35070.4vaqNL.rst @@ -0,0 +1,2 @@ +posix.getgrouplist() now works correctly when the user belongs to +NGROUPS_MAX supplemental groups. Patch by Jeffrey Kintscher. diff --git a/Modules/posixmodule.c b/Modules/posixmodule.c index 8f6cfff..7a47180 100644 --- a/Modules/posixmodule.c +++ b/Modules/posixmodule.c @@ -6722,6 +6722,13 @@ os_getpid_impl(PyObject *module) } #endif /* HAVE_GETPID */ +#ifdef NGROUPS_MAX +#define MAX_GROUPS NGROUPS_MAX +#else + /* defined to be 16 on Solaris7, so this should be a small number */ +#define MAX_GROUPS 64 +#endif + #ifdef HAVE_GETGROUPLIST /* AC 3.5: funny apple logic below */ @@ -6734,13 +6741,6 @@ Returns a list of groups to which a user belongs.\n\n\ static PyObject * posix_getgrouplist(PyObject *self, PyObject *args) { -#ifdef NGROUPS_MAX -#define MAX_GROUPS NGROUPS_MAX -#else - /* defined to be 16 on Solaris7, so this should be a small number */ -#define MAX_GROUPS 64 -#endif - const char *user; int i, ngroups; PyObject *list; @@ -6749,7 +6749,16 @@ posix_getgrouplist(PyObject *self, PyObject *args) #else gid_t *groups, basegid; #endif - ngroups = MAX_GROUPS; + + /* + * NGROUPS_MAX is defined by POSIX.1 as the maximum + * number of supplimental groups a users can belong to. + * We have to increment it by one because + * getgrouplist() returns both the supplemental groups + * and the primary group, i.e. all of the groups the + * user belongs to. + */ + ngroups = 1 + MAX_GROUPS; #ifdef __APPLE__ if (!PyArg_ParseTuple(args, "si:getgrouplist", &user, &basegid)) @@ -6818,13 +6827,6 @@ os_getgroups_impl(PyObject *module) /*[clinic end generated code: output=42b0c17758561b56 input=d3f109412e6a155c]*/ { PyObject *result = NULL; - -#ifdef NGROUPS_MAX -#define MAX_GROUPS NGROUPS_MAX -#else - /* defined to be 16 on Solaris7, so this should be a small number */ -#define MAX_GROUPS 64 -#endif gid_t grouplist[MAX_GROUPS]; /* On MacOSX getgroups(2) can return more than MAX_GROUPS results |