]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Issue #17557: Fix os.getgroups() to work with the modified behavior of
authorNed Deily <nad@acm.org>
Fri, 2 Aug 2013 04:19:09 +0000 (21:19 -0700)
committerNed Deily <nad@acm.org>
Fri, 2 Aug 2013 04:19:09 +0000 (21:19 -0700)
getgroups(2) on OS X 10.8.  Original patch by Mateusz Lenik.

Misc/ACKS
Misc/NEWS
Modules/posixmodule.c

index cf553b70e6f55216635e1d4b7acdbee84cb58273..822a523d05cee2370c1741a4b3a030d85cdd2186 100644 (file)
--- a/Misc/ACKS
+++ b/Misc/ACKS
@@ -599,6 +599,7 @@ Petri Lehtinen
 Luke Kenneth Casson Leighton
 Tshepang Lekhonkhobe
 Marc-AndrĂ© Lemburg
+Mateusz Lenik
 John Lenton
 Kostyantyn Leschenko
 Christopher Tur Lesniewski-Laas
index ee5c8f044fd691f5fcaf533bf260d9868d05c1d3..e3394c47fece058e3b1a5e74e26553e763db8b5b 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -26,6 +26,9 @@ Core and Builtins
 Library
 -------
 
+- Issue #17557: Fix os.getgroups() to work with the modified behavior of
+  getgroups(2) on OS X 10.8.  Original patch by Mateusz Lenik.
+
 - Issue #18455: multiprocessing should not retry connect() with same socket.
 
 - Issue #18513: Fix behaviour of cmath.rect w.r.t. signed zeros on OS X 10.8 +
index 65ade9fb9fd8a5cc13c89bf976d0b31525bbf9cb..8352dd3e00a163e965c1af3d2d9b8a06d011b3f5 100644 (file)
@@ -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;