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
This commit is contained in:
Diomidis Spinellis 2003-11-19 15:51:26 +00:00
parent 6006b8f4c6
commit 434c74760f

View File

@ -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));
}