diff options
Diffstat (limited to 'src/lib/libc/net/getprotoent.c')
| -rw-r--r-- | src/lib/libc/net/getprotoent.c | 20 |
1 files changed, 12 insertions, 8 deletions
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 @@ | |||
| 32 | */ | 32 | */ |
| 33 | 33 | ||
| 34 | #if defined(LIBC_SCCS) && !defined(lint) | 34 | #if defined(LIBC_SCCS) && !defined(lint) |
| 35 | static char rcsid[] = "$OpenBSD: getprotoent.c,v 1.2 1996/08/19 08:28:52 tholo Exp $"; | 35 | static char rcsid[] = "$OpenBSD: getprotoent.c,v 1.3 1998/03/16 05:06:59 millert Exp $"; |
| 36 | #endif /* LIBC_SCCS and not lint */ | 36 | #endif /* LIBC_SCCS and not lint */ |
| 37 | 37 | ||
| 38 | #include <sys/types.h> | 38 | #include <sys/types.h> |
| @@ -74,20 +74,24 @@ endprotoent() | |||
| 74 | struct protoent * | 74 | struct protoent * |
| 75 | getprotoent() | 75 | getprotoent() |
| 76 | { | 76 | { |
| 77 | char *p; | 77 | char *p, *cp, **q; |
| 78 | register char *cp, **q; | 78 | size_t len; |
| 79 | 79 | ||
| 80 | if (protof == NULL && (protof = fopen(_PATH_PROTOCOLS, "r" )) == NULL) | 80 | if (protof == NULL && (protof = fopen(_PATH_PROTOCOLS, "r" )) == NULL) |
| 81 | return (NULL); | 81 | return (NULL); |
| 82 | again: | 82 | again: |
| 83 | if ((p = fgets(line, BUFSIZ, protof)) == NULL) | 83 | if ((p = fgetln(protof, &len)) == NULL) |
| 84 | return (NULL); | 84 | return (NULL); |
| 85 | if (*p == '#') | 85 | if (p[len-1] == '\n') |
| 86 | len--; | ||
| 87 | if (len >= sizeof(line) || len == 0) | ||
| 86 | goto again; | 88 | goto again; |
| 87 | cp = strpbrk(p, "#\n"); | 89 | p = memcpy(line, p, len); |
| 88 | if (cp == NULL) | 90 | line[len] = '\0'; |
| 91 | if (*p == '#') | ||
| 89 | goto again; | 92 | goto again; |
| 90 | *cp = '\0'; | 93 | if ((cp = strchr(p, '#')) != NULL) |
| 94 | *cp = '\0'; | ||
| 91 | proto.p_name = p; | 95 | proto.p_name = p; |
| 92 | cp = strpbrk(p, " \t"); | 96 | cp = strpbrk(p, " \t"); |
| 93 | if (cp == NULL) | 97 | if (cp == NULL) |
