]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
s3:lib: Fix incorrect logic in sys_broken_getgroups()
authorJeremy Allison <jra@samba.org>
Mon, 17 Apr 2017 21:30:04 +0000 (14:30 -0700)
committerKarolin Seeger <kseeger@samba.org>
Thu, 20 Apr 2017 10:23:18 +0000 (12:23 +0200)
If setlen == 0 then the second argument must be ignored.

BUG: https://bugzilla.samba.org/show_bug.cgi?id=12747

Signed-off-by: Jeremy Allison <jra@samba.org>
Reviewed-by: Andreas Schneider <asn@samba.org>
(cherry picked from commit 60af864f751706c48b8af448700bf06e33e45946)

source3/lib/system.c

index 3d3eeeda7c47cd849ea1f2d0bd98b9f9e5d7eb1b..99462b631c790763ae2be4a90191dbf5499d9f20 100644 (file)
@@ -790,12 +790,11 @@ int groups_max(void)
 
 static int sys_broken_getgroups(int setlen, gid_t *gidset)
 {
-       GID_T gid;
        GID_T *group_list;
        int i, ngroups;
 
        if(setlen == 0) {
-               return getgroups(setlen, &gid);
+               return getgroups(0, NULL);
        }
 
        /*
@@ -808,9 +807,6 @@ static int sys_broken_getgroups(int setlen, gid_t *gidset)
                return -1;
        } 
 
-       if (setlen == 0)
-               setlen = groups_max();
-
        if((group_list = SMB_MALLOC_ARRAY(GID_T, setlen)) == NULL) {
                DEBUG(0,("sys_getgroups: Malloc fail.\n"));
                return -1;
@@ -823,6 +819,12 @@ static int sys_broken_getgroups(int setlen, gid_t *gidset)
                return -1;
        }
 
+       /*
+        * We're safe here as if ngroups > setlen then
+        * getgroups *must* return EINVAL.
+        * pubs.opengroup.org/onlinepubs/009695399/functions/getgroups.html
+        */
+
        for(i = 0; i < ngroups; i++)
                gidset[i] = (gid_t)group_list[i];