summaryrefslogtreecommitdiffstats
path: root/usr.sbin/ypserv
diff options
context:
space:
mode:
authorray <ray@openbsd.org>2006-11-22 07:36:01 +0000
committerray <ray@openbsd.org>2006-11-22 07:36:01 +0000
commitbae3e34984ffc86458d048816c97cad3a7e93056 (patch)
treebf134814d7b62eef64d0db0eb5f04e9c4ed31f5a /usr.sbin/ypserv
parentMark signal race. (diff)
downloadwireguard-openbsd-bae3e34984ffc86458d048816c97cad3a7e93056.tar.xz
wireguard-openbsd-bae3e34984ffc86458d048816c97cad3a7e93056.zip
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@.
Diffstat (limited to 'usr.sbin/ypserv')
-rw-r--r--usr.sbin/ypserv/revnetgroup/Makefile5
-rw-r--r--usr.sbin/ypserv/revnetgroup/revnetgroup.c26
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);