diff options
Diffstat (limited to '')
| -rw-r--r-- | src/lib/libc/net/getnetent.c | 21 |
1 files changed, 12 insertions, 9 deletions
diff --git a/src/lib/libc/net/getnetent.c b/src/lib/libc/net/getnetent.c index e40fb50c0f..8f618a1d5e 100644 --- a/src/lib/libc/net/getnetent.c +++ b/src/lib/libc/net/getnetent.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: getnetent.c,v 1.7 1997/04/24 08:37:09 tholo Exp $"; | 35 | static char rcsid[] = "$OpenBSD: getnetent.c,v 1.8 1998/03/16 05:06:57 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> |
| @@ -75,21 +75,24 @@ endnetent() | |||
| 75 | struct netent * | 75 | struct netent * |
| 76 | getnetent() | 76 | getnetent() |
| 77 | { | 77 | { |
| 78 | char *p; | 78 | char *p, *cp, **q; |
| 79 | register char *cp, **q; | 79 | size_t len; |
| 80 | 80 | ||
| 81 | if (netf == NULL && (netf = fopen(_PATH_NETWORKS, "r" )) == NULL) | 81 | if (netf == NULL && (netf = fopen(_PATH_NETWORKS, "r" )) == NULL) |
| 82 | return (NULL); | 82 | return (NULL); |
| 83 | again: | 83 | again: |
| 84 | p = fgets(line, BUFSIZ, netf); | 84 | if ((p = fgetln(netf, &len)) == NULL) |
| 85 | if (p == NULL) | ||
| 86 | return (NULL); | 85 | return (NULL); |
| 87 | if (*p == '#') | 86 | if (p[len-1] == '\n') |
| 87 | len--; | ||
| 88 | if (len >= sizeof(line) || len == 0) | ||
| 88 | goto again; | 89 | goto again; |
| 89 | cp = strpbrk(p, "#\n"); | 90 | p = memcpy(line, p, len); |
| 90 | if (cp == NULL) | 91 | line[len] = '\0'; |
| 92 | if (*p == '#') | ||
| 91 | goto again; | 93 | goto again; |
| 92 | *cp = '\0'; | 94 | if ((cp = strchr(p, '#')) != NULL) |
| 95 | *cp = '\0'; | ||
| 93 | net.n_name = p; | 96 | net.n_name = p; |
| 94 | if (strlen(net.n_name) >= MAXHOSTNAMELEN-1) | 97 | if (strlen(net.n_name) >= MAXHOSTNAMELEN-1) |
| 95 | net.n_name[MAXHOSTNAMELEN-1] = '\0'; | 98 | net.n_name[MAXHOSTNAMELEN-1] = '\0'; |
