diff options
Diffstat (limited to 'src/lib/libc/net/getnetent.c')
| -rw-r--r-- | src/lib/libc/net/getnetent.c | 40 |
1 files changed, 19 insertions, 21 deletions
diff --git a/src/lib/libc/net/getnetent.c b/src/lib/libc/net/getnetent.c index b4e16b8f5d..4c3b38e7d8 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. |
| @@ -12,11 +10,7 @@ | |||
| 12 | * 2. Redistributions in binary form must reproduce the above copyright | 10 | * 2. Redistributions in binary form must reproduce the above copyright |
| 13 | * notice, this list of conditions and the following disclaimer in the | 11 | * notice, this list of conditions and the following disclaimer in the |
| 14 | * documentation and/or other materials provided with the distribution. | 12 | * documentation and/or other materials provided with the distribution. |
| 15 | * 3. All advertising materials mentioning features or use of this software | 13 | * 3. Neither the name of the University nor the names of its contributors |
| 16 | * must display the following acknowledgement: | ||
| 17 | * This product includes software developed by the University of | ||
| 18 | * California, Berkeley and its contributors. | ||
| 19 | * 4. Neither the name of the University nor the names of its contributors | ||
| 20 | * may be used to endorse or promote products derived from this software | 14 | * may be used to endorse or promote products derived from this software |
| 21 | * without specific prior written permission. | 15 | * without specific prior written permission. |
| 22 | * | 16 | * |
| @@ -34,11 +28,7 @@ | |||
| 34 | */ | 28 | */ |
| 35 | 29 | ||
| 36 | #if defined(LIBC_SCCS) && !defined(lint) | 30 | #if defined(LIBC_SCCS) && !defined(lint) |
| 37 | #if 0 | 31 | static char rcsid[] = "$OpenBSD: getnetent.c,v 1.9 2003/06/02 20:18:35 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 */ | 32 | #endif /* LIBC_SCCS and not lint */ |
| 43 | 33 | ||
| 44 | #include <sys/types.h> | 34 | #include <sys/types.h> |
| @@ -81,22 +71,27 @@ endnetent() | |||
| 81 | struct netent * | 71 | struct netent * |
| 82 | getnetent() | 72 | getnetent() |
| 83 | { | 73 | { |
| 84 | char *p; | 74 | char *p, *cp, **q; |
| 85 | register char *cp, **q; | 75 | size_t len; |
| 86 | 76 | ||
| 87 | if (netf == NULL && (netf = fopen(_PATH_NETWORKS, "r" )) == NULL) | 77 | if (netf == NULL && (netf = fopen(_PATH_NETWORKS, "r" )) == NULL) |
| 88 | return (NULL); | 78 | return (NULL); |
| 89 | again: | 79 | again: |
| 90 | p = fgets(line, BUFSIZ, netf); | 80 | if ((p = fgetln(netf, &len)) == NULL) |
| 91 | if (p == NULL) | ||
| 92 | return (NULL); | 81 | return (NULL); |
| 93 | if (*p == '#') | 82 | if (p[len-1] == '\n') |
| 83 | len--; | ||
| 84 | if (len >= sizeof(line) || len == 0) | ||
| 94 | goto again; | 85 | goto again; |
| 95 | cp = strpbrk(p, "#\n"); | 86 | p = memcpy(line, p, len); |
| 96 | if (cp == NULL) | 87 | line[len] = '\0'; |
| 88 | if (*p == '#') | ||
| 97 | goto again; | 89 | goto again; |
| 98 | *cp = '\0'; | 90 | if ((cp = strchr(p, '#')) != NULL) |
| 91 | *cp = '\0'; | ||
| 99 | net.n_name = p; | 92 | net.n_name = p; |
| 93 | if (strlen(net.n_name) >= MAXHOSTNAMELEN-1) | ||
| 94 | net.n_name[MAXHOSTNAMELEN-1] = '\0'; | ||
| 100 | cp = strpbrk(p, " \t"); | 95 | cp = strpbrk(p, " \t"); |
| 101 | if (cp == NULL) | 96 | if (cp == NULL) |
| 102 | goto again; | 97 | goto again; |
| @@ -116,8 +111,11 @@ again: | |||
| 116 | cp++; | 111 | cp++; |
| 117 | continue; | 112 | continue; |
| 118 | } | 113 | } |
| 119 | if (q < &net_aliases[MAXALIASES - 1]) | 114 | if (q < &net_aliases[MAXALIASES - 1]) { |
| 120 | *q++ = cp; | 115 | *q++ = cp; |
| 116 | if (strlen(cp) >= MAXHOSTNAMELEN-1) | ||
| 117 | cp[MAXHOSTNAMELEN-1] = '\0'; | ||
| 118 | } | ||
| 121 | cp = strpbrk(cp, " \t"); | 119 | cp = strpbrk(cp, " \t"); |
| 122 | if (cp != NULL) | 120 | if (cp != NULL) |
| 123 | *cp++ = '\0'; | 121 | *cp++ = '\0'; |
