Skip to content

Commit ffb3289

Browse files
committed
Issue #17557: merge from 3.3
2 parents 4dbc95e + b5dd6d2 commit ffb3289

3 files changed

Lines changed: 34 additions & 0 deletions

File tree

Misc/ACKS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -737,6 +737,7 @@ Petri Lehtinen
737737
Luke Kenneth Casson Leighton
738738
Tshepang Lekhonkhobe
739739
Marc-André Lemburg
740+
Mateusz Lenik
740741
John Lenton
741742
Kostyantyn Leschenko
742743
Benno Leslie

Misc/NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,9 @@ Core and Builtins
184184
Library
185185
-------
186186

187+
- Issue #17557: Fix os.getgroups() to work with the modified behavior of
188+
getgroups(2) on OS X 10.8. Original patch by Mateusz Lenik.
189+
187190
- Issue #18608: Avoid keeping a strong reference to the locale module
188191
inside the _io module.
189192

Modules/posixmodule.c

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5911,6 +5911,34 @@ posix_getgroups(PyObject *self, PyObject *noargs)
59115911
gid_t* alt_grouplist = grouplist;
59125912
int n;
59135913

5914+
#ifdef __APPLE__
5915+
/* Issue #17557: As of OS X 10.8, getgroups(2) no longer raises EINVAL if
5916+
* there are more groups than can fit in grouplist. Therefore, on OS X
5917+
* always first call getgroups with length 0 to get the actual number
5918+
* of groups.
5919+
*/
5920+
n = getgroups(0, NULL);
5921+
if (n < 0) {
5922+
return posix_error();
5923+
} else if (n <= MAX_GROUPS) {
5924+
/* groups will fit in existing array */
5925+
alt_grouplist = grouplist;
5926+
} else {
5927+
alt_grouplist = PyMem_Malloc(n * sizeof(gid_t));
5928+
if (alt_grouplist == NULL) {
5929+
errno = EINVAL;
5930+
return posix_error();
5931+
}
5932+
}
5933+
5934+
n = getgroups(n, alt_grouplist);
5935+
if (n == -1) {
5936+
if (alt_grouplist != grouplist) {
5937+
PyMem_Free(alt_grouplist);
5938+
}
5939+
return posix_error();
5940+
}
5941+
#else
59145942
n = getgroups(MAX_GROUPS, grouplist);
59155943
if (n < 0) {
59165944
if (errno == EINVAL) {
@@ -5937,6 +5965,8 @@ posix_getgroups(PyObject *self, PyObject *noargs)
59375965
return posix_error();
59385966
}
59395967
}
5968+
#endif
5969+
59405970
result = PyList_New(n);
59415971
if (result != NULL) {
59425972
int i;

0 commit comments

Comments
 (0)