mirror of
https://github.com/python/cpython.git
synced 2025-11-03 11:23:31 +00:00
bpo-40014: Fix os.getgrouplist() on macOS (GH-19118)
On macOS, getgrouplist() returns a non-zero value without setting errno if the group list is too small. Double the list size and call it again in this case.
This commit is contained in:
parent
bd409bb5b7
commit
8ec7370c89
2 changed files with 22 additions and 0 deletions
|
|
@ -0,0 +1,3 @@
|
||||||
|
Fix ``os.getgrouplist()``: on macOS, the ``getgrouplist()`` function returns a
|
||||||
|
non-zero value without setting ``errno`` if the group list is too small. Double
|
||||||
|
the list size and call it again in this case.
|
||||||
|
|
@ -6999,10 +6999,29 @@ posix_getgrouplist(PyObject *self, PyObject *args)
|
||||||
if (groups == NULL)
|
if (groups == NULL)
|
||||||
return PyErr_NoMemory();
|
return PyErr_NoMemory();
|
||||||
|
|
||||||
|
#ifdef __APPLE__
|
||||||
|
while (getgrouplist(user, basegid, groups, &ngroups)) {
|
||||||
|
/* On macOS, getgrouplist() returns a non-zero value without setting
|
||||||
|
errno if the group list is too small. Double the list size and call
|
||||||
|
it again in this case. */
|
||||||
|
PyMem_Free(groups);
|
||||||
|
|
||||||
|
if (ngroups > INT_MAX / 2) {
|
||||||
|
return PyErr_NoMemory();
|
||||||
|
}
|
||||||
|
ngroups *= 2;
|
||||||
|
|
||||||
|
groups = PyMem_New(int, ngroups);
|
||||||
|
if (groups == NULL) {
|
||||||
|
return PyErr_NoMemory();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#else
|
||||||
if (getgrouplist(user, basegid, groups, &ngroups) == -1) {
|
if (getgrouplist(user, basegid, groups, &ngroups) == -1) {
|
||||||
PyMem_Del(groups);
|
PyMem_Del(groups);
|
||||||
return posix_error();
|
return posix_error();
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifdef _Py_MEMORY_SANITIZER
|
#ifdef _Py_MEMORY_SANITIZER
|
||||||
/* Clang memory sanitizer libc intercepts don't know getgrouplist. */
|
/* Clang memory sanitizer libc intercepts don't know getgrouplist. */
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue