From 7cc61258b3b66c62b0828fdaa234ee8ae2fee2dc Mon Sep 17 00:00:00 2001 From: millert <> Date: Mon, 16 Mar 1998 05:07:02 +0000 Subject: Use fgetln(3) instead of fgets(3) so we can easily recognize lines that are too long and ignore them instead of corrupting later entries. --- src/lib/libc/net/getprotoent.c | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) (limited to 'src/lib/libc/net/getprotoent.c') diff --git a/src/lib/libc/net/getprotoent.c b/src/lib/libc/net/getprotoent.c index 381feb6faf..2bef526e7a 100644 --- a/src/lib/libc/net/getprotoent.c +++ b/src/lib/libc/net/getprotoent.c @@ -32,7 +32,7 @@ */ #if defined(LIBC_SCCS) && !defined(lint) -static char rcsid[] = "$OpenBSD: getprotoent.c,v 1.2 1996/08/19 08:28:52 tholo Exp $"; +static char rcsid[] = "$OpenBSD: getprotoent.c,v 1.3 1998/03/16 05:06:59 millert Exp $"; #endif /* LIBC_SCCS and not lint */ #include @@ -74,20 +74,24 @@ endprotoent() struct protoent * getprotoent() { - char *p; - register char *cp, **q; + char *p, *cp, **q; + size_t len; if (protof == NULL && (protof = fopen(_PATH_PROTOCOLS, "r" )) == NULL) return (NULL); again: - if ((p = fgets(line, BUFSIZ, protof)) == NULL) + if ((p = fgetln(protof, &len)) == NULL) return (NULL); - if (*p == '#') + if (p[len-1] == '\n') + len--; + if (len >= sizeof(line) || len == 0) goto again; - cp = strpbrk(p, "#\n"); - if (cp == NULL) + p = memcpy(line, p, len); + line[len] = '\0'; + if (*p == '#') goto again; - *cp = '\0'; + if ((cp = strchr(p, '#')) != NULL) + *cp = '\0'; proto.p_name = p; cp = strpbrk(p, " \t"); if (cp == NULL) -- cgit v1.2.3-55-g6feb