From: Pino Toscano Date: Fri, 20 Jul 2012 22:06:33 +0000 (+0200) Subject: Hurd: compliance fixes for getgroups X-Git-Tag: glibc-2.17~814 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=0ced335ac081474e12c89709c81cf2f2094c5351;p=thirdparty%2Fglibc.git Hurd: compliance fixes for getgroups Fail with EINVAL when the requested number of groups is negative, or when it is positive but less than the actual number of groups. --- diff --git a/ChangeLog b/ChangeLog index a804f2cf03e..560bb95533f 100644 --- a/ChangeLog +++ b/ChangeLog @@ -10,6 +10,9 @@ * sysdeps/mach/hurd/lremovexattr.c: New file, copied from removexattr.c with O_NOLINK passed to __file_name_lookup. + * sysdeps/mach/hurd/getgroups.c: Return -1 and set EINVAL for + negative N or less than NGIDS. + 2012-07-20 Joseph Myers * elf/Makefile (check-data): Remove. diff --git a/sysdeps/mach/hurd/getgroups.c b/sysdeps/mach/hurd/getgroups.c index 157a981740f..35b219ef66c 100644 --- a/sysdeps/mach/hurd/getgroups.c +++ b/sysdeps/mach/hurd/getgroups.c @@ -30,6 +30,9 @@ __getgroups (n, gidset) int ngids; void *crit; + if (n < 0) + return __hurd_fail (EINVAL); + crit = _hurd_critical_section_lock (); __mutex_lock (&_hurd_id.lock); @@ -53,7 +56,7 @@ __getgroups (n, gidset) /* Now that the lock is released, we can safely copy the group set into the user's array, which might fault. */ if (ngids > n) - ngids = n; + return __hurd_fail (EINVAL); memcpy (gidset, gids, ngids * sizeof (gid_t)); } else