From 36934d35fec44eaefcb112d5d544542c19a0594a Mon Sep 17 00:00:00 2001 From: dds Date: Wed, 19 Nov 2003 15:51:26 +0000 Subject: Fix problem where initgroups would silently truncate groups with more than NGROUP elements without providing the opportunity to setgroups to fail and correctly return error and set errno. MFC after: 2 weeks --- lib/libc/gen/initgroups.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'lib/libc') diff --git a/lib/libc/gen/initgroups.c b/lib/libc/gen/initgroups.c index 3a3f513..82bbb3a 100644 --- a/lib/libc/gen/initgroups.c +++ b/lib/libc/gen/initgroups.c @@ -50,9 +50,14 @@ initgroups(uname, agroup) const char *uname; gid_t agroup; { - int groups[NGROUPS], ngroups; + int ngroups; + /* + * Provide space for one group more than NGROUPS to allow + * setgroups to fail and set errno. + */ + gid_t groups[NGROUPS + 1]; - ngroups = NGROUPS; + ngroups = NGROUPS + 1; getgrouplist(uname, agroup, groups, &ngroups); return (setgroups(ngroups, groups)); } -- cgit v1.1