diff options
Diffstat (limited to 'src/lib/libc/net/getnetent.c')
-rw-r--r-- | src/lib/libc/net/getnetent.c | 34 |
1 files changed, 18 insertions, 16 deletions
diff --git a/src/lib/libc/net/getnetent.c b/src/lib/libc/net/getnetent.c index b4e16b8f5d..8f618a1d5e 100644 --- a/src/lib/libc/net/getnetent.c +++ b/src/lib/libc/net/getnetent.c | |||
@@ -1,5 +1,3 @@ | |||
1 | /* $NetBSD: getnetent.c,v 1.4 1995/02/25 06:20:33 cgd Exp $ */ | ||
2 | |||
3 | /* | 1 | /* |
4 | * Copyright (c) 1983, 1993 | 2 | * Copyright (c) 1983, 1993 |
5 | * The Regents of the University of California. All rights reserved. | 3 | * The Regents of the University of California. All rights reserved. |
@@ -34,11 +32,7 @@ | |||
34 | */ | 32 | */ |
35 | 33 | ||
36 | #if defined(LIBC_SCCS) && !defined(lint) | 34 | #if defined(LIBC_SCCS) && !defined(lint) |
37 | #if 0 | 35 | static char rcsid[] = "$OpenBSD: getnetent.c,v 1.8 1998/03/16 05:06:57 millert Exp $"; |
38 | static char sccsid[] = "@(#)getnetent.c 8.1 (Berkeley) 6/4/93"; | ||
39 | #else | ||
40 | static char rcsid[] = "$NetBSD: getnetent.c,v 1.4 1995/02/25 06:20:33 cgd Exp $"; | ||
41 | #endif | ||
42 | #endif /* LIBC_SCCS and not lint */ | 36 | #endif /* LIBC_SCCS and not lint */ |
43 | 37 | ||
44 | #include <sys/types.h> | 38 | #include <sys/types.h> |
@@ -81,22 +75,27 @@ endnetent() | |||
81 | struct netent * | 75 | struct netent * |
82 | getnetent() | 76 | getnetent() |
83 | { | 77 | { |
84 | char *p; | 78 | char *p, *cp, **q; |
85 | register char *cp, **q; | 79 | size_t len; |
86 | 80 | ||
87 | if (netf == NULL && (netf = fopen(_PATH_NETWORKS, "r" )) == NULL) | 81 | if (netf == NULL && (netf = fopen(_PATH_NETWORKS, "r" )) == NULL) |
88 | return (NULL); | 82 | return (NULL); |
89 | again: | 83 | again: |
90 | p = fgets(line, BUFSIZ, netf); | 84 | if ((p = fgetln(netf, &len)) == NULL) |
91 | if (p == NULL) | ||
92 | return (NULL); | 85 | return (NULL); |
93 | if (*p == '#') | 86 | if (p[len-1] == '\n') |
87 | len--; | ||
88 | if (len >= sizeof(line) || len == 0) | ||
94 | goto again; | 89 | goto again; |
95 | cp = strpbrk(p, "#\n"); | 90 | p = memcpy(line, p, len); |
96 | if (cp == NULL) | 91 | line[len] = '\0'; |
92 | if (*p == '#') | ||
97 | goto again; | 93 | goto again; |
98 | *cp = '\0'; | 94 | if ((cp = strchr(p, '#')) != NULL) |
95 | *cp = '\0'; | ||
99 | net.n_name = p; | 96 | net.n_name = p; |
97 | if (strlen(net.n_name) >= MAXHOSTNAMELEN-1) | ||
98 | net.n_name[MAXHOSTNAMELEN-1] = '\0'; | ||
100 | cp = strpbrk(p, " \t"); | 99 | cp = strpbrk(p, " \t"); |
101 | if (cp == NULL) | 100 | if (cp == NULL) |
102 | goto again; | 101 | goto again; |
@@ -116,8 +115,11 @@ again: | |||
116 | cp++; | 115 | cp++; |
117 | continue; | 116 | continue; |
118 | } | 117 | } |
119 | if (q < &net_aliases[MAXALIASES - 1]) | 118 | if (q < &net_aliases[MAXALIASES - 1]) { |
120 | *q++ = cp; | 119 | *q++ = cp; |
120 | if (strlen(cp) >= MAXHOSTNAMELEN-1) | ||
121 | cp[MAXHOSTNAMELEN-1] = '\0'; | ||
122 | } | ||
121 | cp = strpbrk(cp, " \t"); | 123 | cp = strpbrk(cp, " \t"); |
122 | if (cp != NULL) | 124 | if (cp != NULL) |
123 | *cp++ = '\0'; | 125 | *cp++ = '\0'; |