From d93f1b0fec720572e9aea1878754d75e3f7c4162 Mon Sep 17 00:00:00 2001 From: Theo de Raadt Date: Tue, 19 Aug 1997 16:24:43 +0000 Subject: do not reuse id's. also be more careful with maxgids. --- lib/libc/gen/getgrouplist.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'lib/libc') diff --git a/lib/libc/gen/getgrouplist.c b/lib/libc/gen/getgrouplist.c index 37cc2b5c5d5..9ee03354eb9 100644 --- a/lib/libc/gen/getgrouplist.c +++ b/lib/libc/gen/getgrouplist.c @@ -32,7 +32,7 @@ */ #if defined(LIBC_SCCS) && !defined(lint) -static char rcsid[] = "$OpenBSD: getgrouplist.c,v 1.5 1997/07/09 00:28:21 millert Exp $"; +static char rcsid[] = "$OpenBSD: getgrouplist.c,v 1.6 1997/08/19 16:24:42 deraadt Exp $"; #endif /* LIBC_SCCS and not lint */ /* @@ -60,6 +60,10 @@ getgrouplist(uname, agroup, groups, grpcnt) /* * install primary group */ + if (ngroups >= maxgroups) { + *grpcnt = ngroups; + return (-1); + } groups[ngroups++] = agroup; /* @@ -69,6 +73,11 @@ getgrouplist(uname, agroup, groups, grpcnt) while ((grp = getgrent())) { if (grp->gr_gid == agroup) continue; + for (i = 0; i < ngroups; i++) + if (groups[i] == grp->gr_gid) + break; + if (groups[i] == grp->gr_gid) + continue; for (i = 0; grp->gr_mem[i]; i++) { if (!strcmp(grp->gr_mem[i], uname)) { if (ngroups >= maxgroups) { -- cgit v1.2.3