From 434c74760ffe91c6f4cc3dff0d49a24dddb975c6 Mon Sep 17 00:00:00 2001 From: Diomidis Spinellis Date: Wed, 19 Nov 2003 15:51:26 +0000 Subject: [PATCH] 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(-) diff --git a/lib/libc/gen/initgroups.c b/lib/libc/gen/initgroups.c index 3a3f51356795..82bbb3af1fa6 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)); }