summaryrefslogtreecommitdiffstats
path: root/usr.sbin/lpr
diff options
context:
space:
mode:
authoralfred <alfred@FreeBSD.org>2000-08-23 23:36:32 +0000
committeralfred <alfred@FreeBSD.org>2000-08-23 23:36:32 +0000
commit702a9ba819ee66bb6e9e401039df9d5d7c644d44 (patch)
tree806c49e8e2b051314aecf94c1a2d47e18754db27 /usr.sbin/lpr
parent99533f6c61e9d8adefa5eb5144179e63328e0ef8 (diff)
downloadFreeBSD-src-702a9ba819ee66bb6e9e401039df9d5d7c644d44.zip
FreeBSD-src-702a9ba819ee66bb6e9e401039df9d5d7c644d44.tar.gz
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>
Diffstat (limited to 'usr.sbin/lpr')
-rw-r--r--usr.sbin/lpr/lpc/lpc.c6
1 files changed, 4 insertions, 2 deletions
diff --git a/usr.sbin/lpr/lpc/lpc.c b/usr.sbin/lpr/lpc/lpc.c
index 5bfa859..866b8ac 100644
--- a/usr.sbin/lpr/lpc/lpc.c
+++ b/usr.sbin/lpr/lpc/lpc.c
@@ -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);
OpenPOWER on IntegriCloud