diff options
author | Ned Deily <nad@acm.org> | 2013-08-01 21:19:09 -0700 |
---|---|---|
committer | Ned Deily <nad@acm.org> | 2013-08-01 21:19:09 -0700 |
commit | 8074364f7abb648ac60ba8f78bae7d41a906aead (patch) | |
tree | 0f10e9443d0599eb06505486de57067932f5370e /Modules/posixmodule.c | |
parent | 594e8eba13d2c98159dcc70fb2b81497b3d039b6 (diff) | |
download | cpython-git-8074364f7abb648ac60ba8f78bae7d41a906aead.tar.gz |
Issue #17557: Fix os.getgroups() to work with the modified behavior of
getgroups(2) on OS X 10.8. Original patch by Mateusz Lenik.
Diffstat (limited to 'Modules/posixmodule.c')
-rw-r--r-- | Modules/posixmodule.c | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/Modules/posixmodule.c b/Modules/posixmodule.c index 65ade9fb9f..8352dd3e00 100644 --- a/Modules/posixmodule.c +++ b/Modules/posixmodule.c @@ -4054,6 +4054,34 @@ posix_getgroups(PyObject *self, PyObject *noargs) gid_t* alt_grouplist = grouplist; int n; +#ifdef __APPLE__ + /* Issue #17557: As of OS X 10.8, getgroups(2) no longer raises EINVAL if + * there are more groups than can fit in grouplist. Therefore, on OS X + * always first call getgroups with length 0 to get the actual number + * of groups. + */ + n = getgroups(0, NULL); + if (n < 0) { + return posix_error(); + } else if (n <= MAX_GROUPS) { + /* groups will fit in existing array */ + alt_grouplist = grouplist; + } else { + alt_grouplist = PyMem_Malloc(n * sizeof(gid_t)); + if (alt_grouplist == NULL) { + errno = EINVAL; + return posix_error(); + } + } + + n = getgroups(n, alt_grouplist); + if (n == -1) { + if (alt_grouplist != grouplist) { + PyMem_Free(alt_grouplist); + } + return posix_error(); + } +#else n = getgroups(MAX_GROUPS, grouplist); if (n < 0) { if (errno == EINVAL) { @@ -4080,6 +4108,8 @@ posix_getgroups(PyObject *self, PyObject *noargs) return posix_error(); } } +#endif + result = PyList_New(n); if (result != NULL) { int i; |