summaryrefslogtreecommitdiff
path: root/Modules
diff options
context:
space:
mode:
authorNed Deily <nad@acm.org>2013-08-01 21:37:17 -0700
committerNed Deily <nad@acm.org>2013-08-01 21:37:17 -0700
commitda8f062d3621c37bcbda53b72a1d5d1f5ad3e9e8 (patch)
tree514d4a3e6663501aee04837c772dcc027e84e744 /Modules
parent5f4ed2aba162971332a76036fd45df3a3c601193 (diff)
parent6180739e53fdce7c286b16c14f30ea6e85edb469 (diff)
downloadcpython-da8f062d3621c37bcbda53b72a1d5d1f5ad3e9e8.tar.gz
Issue #17557: merge from 3.3
Diffstat (limited to 'Modules')
-rw-r--r--Modules/posixmodule.c30
1 files changed, 30 insertions, 0 deletions
diff --git a/Modules/posixmodule.c b/Modules/posixmodule.c
index 32fbadc447..e5d7ae15dd 100644
--- a/Modules/posixmodule.c
+++ b/Modules/posixmodule.c
@@ -5911,6 +5911,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) {
@@ -5937,6 +5965,8 @@ posix_getgroups(PyObject *self, PyObject *noargs)
return posix_error();
}
}
+#endif
+
result = PyList_New(n);
if (result != NULL) {
int i;