diff options
author | Jeremy Allison <jra@samba.org> | 2017-04-17 14:30:04 -0700 |
---|---|---|
committer | Andreas Schneider <asn@cryptomilk.org> | 2017-04-18 11:47:17 +0200 |
commit | 60af864f751706c48b8af448700bf06e33e45946 (patch) | |
tree | 7dfefeafbb7a4efd8a2033e25b7d19b5f4eea2fc /source3 | |
parent | 600f8787e3b605c9f3e8f724c726e63157ee9efc (diff) | |
download | samba-60af864f751706c48b8af448700bf06e33e45946.tar.gz |
s3:lib: Fix incorrect logic in sys_broken_getgroups()
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>
Diffstat (limited to 'source3')
-rw-r--r-- | source3/lib/system.c | 12 |
1 files changed, 7 insertions, 5 deletions
diff --git a/source3/lib/system.c b/source3/lib/system.c index 3d3eeeda7c4..99462b631c7 100644 --- a/source3/lib/system.c +++ b/source3/lib/system.c @@ -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]; |