summaryrefslogtreecommitdiff
path: root/Modules
diff options
context:
space:
mode:
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>2019-06-13 00:18:26 -0700
committerGitHub <noreply@github.com>2019-06-13 00:18:26 -0700
commitb4c8ef7c67712c6639ee896bf7cb8ca1c204946d (patch)
treea7141c29feb0e05024f4db9c6a14f578f1cce602 /Modules
parentd561f848b235f2011a43b705d112055b92fa2366 (diff)
downloadcpython-git-b4c8ef7c67712c6639ee896bf7cb8ca1c204946d.tar.gz
bpo-35070: test_getgrouplist may fail on macOS if too many groups (GH-13071)
(cherry picked from commit 8725c83ed5ca8959195ad8326db99d564a921749) Co-authored-by: Jeffrey Kintscher <49998481+websurfer5@users.noreply.github.com>
Diffstat (limited to 'Modules')
-rw-r--r--Modules/posixmodule.c32
1 files changed, 17 insertions, 15 deletions
diff --git a/Modules/posixmodule.c b/Modules/posixmodule.c
index e7a1f987de..b758e766a4 100644
--- a/Modules/posixmodule.c
+++ b/Modules/posixmodule.c
@@ -6120,6 +6120,13 @@ os_getpid_impl(PyObject *module)
}
#endif /* HAVE_GETPID */
+#ifdef NGROUPS_MAX
+#define MAX_GROUPS NGROUPS_MAX
+#else
+ /* defined to be 16 on Solaris7, so this should be a small number */
+#define MAX_GROUPS 64
+#endif
+
#ifdef HAVE_GETGROUPLIST
/* AC 3.5: funny apple logic below */
@@ -6132,13 +6139,6 @@ Returns a list of groups to which a user belongs.\n\n\
static PyObject *
posix_getgrouplist(PyObject *self, PyObject *args)
{
-#ifdef NGROUPS_MAX
-#define MAX_GROUPS NGROUPS_MAX
-#else
- /* defined to be 16 on Solaris7, so this should be a small number */
-#define MAX_GROUPS 64
-#endif
-
const char *user;
int i, ngroups;
PyObject *list;
@@ -6147,7 +6147,16 @@ posix_getgrouplist(PyObject *self, PyObject *args)
#else
gid_t *groups, basegid;
#endif
- ngroups = MAX_GROUPS;
+
+ /*
+ * NGROUPS_MAX is defined by POSIX.1 as the maximum
+ * number of supplimental groups a users can belong to.
+ * We have to increment it by one because
+ * getgrouplist() returns both the supplemental groups
+ * and the primary group, i.e. all of the groups the
+ * user belongs to.
+ */
+ ngroups = 1 + MAX_GROUPS;
#ifdef __APPLE__
if (!PyArg_ParseTuple(args, "si:getgrouplist", &user, &basegid))
@@ -6216,13 +6225,6 @@ os_getgroups_impl(PyObject *module)
/*[clinic end generated code: output=42b0c17758561b56 input=d3f109412e6a155c]*/
{
PyObject *result = NULL;
-
-#ifdef NGROUPS_MAX
-#define MAX_GROUPS NGROUPS_MAX
-#else
- /* defined to be 16 on Solaris7, so this should be a small number */
-#define MAX_GROUPS 64
-#endif
gid_t grouplist[MAX_GROUPS];
/* On MacOSX getgroups(2) can return more than MAX_GROUPS results