diff options
author | Ray Lai <ray@cvs.openbsd.org> | 2006-11-22 07:36:02 +0000 |
---|---|---|
committer | Ray Lai <ray@cvs.openbsd.org> | 2006-11-22 07:36:02 +0000 |
commit | c46f5f9f10f74164b12b1d3bde9fe734769001f4 (patch) | |
tree | f657a02d868e9d1577a0c069fae59285ca2abc9a | |
parent | 5f2e69ad5df2cf6b9baa85543d8bc58a78d659c7 (diff) |
Outsource fgets line reading, newline continuation, and comment
handling to fparseln. Fixes out of bounds array access for strings
of length 0 or 1.
OK moritz@.
-rw-r--r-- | usr.sbin/ypserv/revnetgroup/Makefile | 5 | ||||
-rw-r--r-- | usr.sbin/ypserv/revnetgroup/revnetgroup.c | 26 |
2 files changed, 16 insertions, 15 deletions
diff --git a/usr.sbin/ypserv/revnetgroup/Makefile b/usr.sbin/ypserv/revnetgroup/Makefile index a96581a3f8a..8ffb83c92d3 100644 --- a/usr.sbin/ypserv/revnetgroup/Makefile +++ b/usr.sbin/ypserv/revnetgroup/Makefile @@ -1,4 +1,4 @@ -# $OpenBSD: Makefile,v 1.1 1997/04/15 22:06:10 maja Exp $ +# $OpenBSD: Makefile,v 1.2 2006/11/22 07:36:01 ray Exp $ # $FreeBSD: Makefile,v 1.3 1997/02/22 14:22:00 peter Exp $ PROG= revnetgroup @@ -6,4 +6,7 @@ SRCS= revnetgroup.c hash.c parse_netgroup.c MAN= revnetgroup.8 +LDADD+= -lutil +DPADD+= ${LIBUTIL} + .include <bsd.prog.mk> diff --git a/usr.sbin/ypserv/revnetgroup/revnetgroup.c b/usr.sbin/ypserv/revnetgroup/revnetgroup.c index 212d873a731..ced15b0d66a 100644 --- a/usr.sbin/ypserv/revnetgroup/revnetgroup.c +++ b/usr.sbin/ypserv/revnetgroup/revnetgroup.c @@ -1,4 +1,4 @@ -/* $OpenBSD: revnetgroup.c,v 1.6 2006/04/03 05:01:23 deraadt Exp $ */ +/* $OpenBSD: revnetgroup.c,v 1.7 2006/11/22 07:36:01 ray Exp $ */ /* * Copyright (c) 1995 * Bill Paul <wpaul@ctr.columbia.edu>. All rights reserved. @@ -42,12 +42,13 @@ #include <stdio.h> #include <stdlib.h> #include <string.h> +#include <util.h> #include <errno.h> #include <err.h> #include "hash.h" #ifndef lint -static const char rcsid[] = "$OpenBSD: revnetgroup.c,v 1.6 2006/04/03 05:01:23 deraadt Exp $"; +static const char rcsid[] = "$OpenBSD: revnetgroup.c,v 1.7 2006/11/22 07:36:01 ray Exp $"; #endif /* Default location of netgroup file. */ @@ -73,7 +74,7 @@ int main(int argc, char *argv[]) { FILE *fp; - char readbuf[LINSIZ]; + char *readbuf; struct group_entry *gcur; struct member_entry *mcur; char *host, *user, *domain; @@ -122,20 +123,17 @@ main(int argc, char *argv[]) } /* Stuff all the netgroup names and members into a hash table. */ - while (fgets(readbuf, LINSIZ, fp)) { - if (readbuf[0] == '#') + while ((readbuf = fparseln(fp, NULL, NULL, NULL, 0)) != NULL) { + data = strpbrk(readbuf, " \t"); + if (data == NULL) { + free(readbuf); continue; - /* handle backslash line continuations */ - while (readbuf[strlen(readbuf) - 2] == '\\') { - fgets((char *)&readbuf[strlen(readbuf) - 2], - sizeof(readbuf) - strlen(readbuf), fp); } - data = NULL; - if ((data = (char *)(strpbrk(readbuf, " \t") + 1)) < (char *)2) - continue; - key = (char *)&readbuf; - *(data - 1) = '\0'; + *data = '\0'; + ++data; + key = readbuf; ngstore(gtable, key, data); + free(readbuf); } fclose(fp); |