the code assumes that getgroups() always returns NGROUPS groups, however
that is not true. Instead of looping NGROUPS times, get the return value from getgroups() and loop over the return that many times. Noticed by: David A. Holland <dholland@eecs.harvard.edu>
This commit is contained in:
parent
03f808c55a
commit
00e64813a2
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=65035
@ -334,6 +334,7 @@ ingroup(grname)
|
||||
char *grname;
|
||||
{
|
||||
static struct group *gptr=NULL;
|
||||
static int ngroups = 0;
|
||||
static gid_t groups[NGROUPS];
|
||||
register gid_t gid;
|
||||
register int i;
|
||||
@ -343,11 +344,12 @@ ingroup(grname)
|
||||
warnx("warning: unknown group '%s'", grname);
|
||||
return(0);
|
||||
}
|
||||
if (getgroups(NGROUPS, groups) < 0)
|
||||
ngroups = getgroups(NGROUPS, groups);
|
||||
if (ngroups < 0)
|
||||
err(1, "getgroups");
|
||||
}
|
||||
gid = gptr->gr_gid;
|
||||
for (i = 0; i < NGROUPS; i++)
|
||||
for (i = 0; i < ngroups; i++)
|
||||
if (gid == groups[i])
|
||||
return(1);
|
||||
return(0);
|
||||
|
Loading…
Reference in New Issue
Block a user