diff options
Diffstat (limited to 'src/lib/libc/net/getprotoent.c')
-rw-r--r-- | src/lib/libc/net/getprotoent.c | 38 |
1 files changed, 18 insertions, 20 deletions
diff --git a/src/lib/libc/net/getprotoent.c b/src/lib/libc/net/getprotoent.c index 1179b9029b..b2bdd2e164 100644 --- a/src/lib/libc/net/getprotoent.c +++ b/src/lib/libc/net/getprotoent.c | |||
@@ -1,5 +1,3 @@ | |||
1 | /* $NetBSD: getprotoent.c,v 1.4 1995/02/25 06:20:35 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: getprotoent.c,v 1.5 2003/06/02 20:18:35 millert Exp $"; |
38 | static char sccsid[] = "@(#)getprotoent.c 8.1 (Berkeley) 6/4/93"; | ||
39 | #else | ||
40 | static char rcsid[] = "$NetBSD: getprotoent.c,v 1.4 1995/02/25 06:20:35 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> |
@@ -80,20 +70,25 @@ endprotoent() | |||
80 | struct protoent * | 70 | struct protoent * |
81 | getprotoent() | 71 | getprotoent() |
82 | { | 72 | { |
83 | char *p; | 73 | char *p, *cp, **q, *endp; |
84 | register char *cp, **q; | 74 | long l; |
75 | size_t len; | ||
85 | 76 | ||
86 | if (protof == NULL && (protof = fopen(_PATH_PROTOCOLS, "r" )) == NULL) | 77 | if (protof == NULL && (protof = fopen(_PATH_PROTOCOLS, "r" )) == NULL) |
87 | return (NULL); | 78 | return (NULL); |
88 | again: | 79 | again: |
89 | if ((p = fgets(line, BUFSIZ, protof)) == NULL) | 80 | if ((p = fgetln(protof, &len)) == NULL) |
90 | return (NULL); | 81 | return (NULL); |
91 | if (*p == '#') | 82 | if (p[len-1] == '\n') |
83 | len--; | ||
84 | if (len >= sizeof(line) || len == 0) | ||
92 | goto again; | 85 | goto again; |
93 | cp = strpbrk(p, "#\n"); | 86 | p = memcpy(line, p, len); |
94 | if (cp == NULL) | 87 | line[len] = '\0'; |
88 | if (*p == '#') | ||
95 | goto again; | 89 | goto again; |
96 | *cp = '\0'; | 90 | if ((cp = strchr(p, '#')) != NULL) |
91 | *cp = '\0'; | ||
97 | proto.p_name = p; | 92 | proto.p_name = p; |
98 | cp = strpbrk(p, " \t"); | 93 | cp = strpbrk(p, " \t"); |
99 | if (cp == NULL) | 94 | if (cp == NULL) |
@@ -104,7 +99,10 @@ again: | |||
104 | p = strpbrk(cp, " \t"); | 99 | p = strpbrk(cp, " \t"); |
105 | if (p != NULL) | 100 | if (p != NULL) |
106 | *p++ = '\0'; | 101 | *p++ = '\0'; |
107 | proto.p_proto = atoi(cp); | 102 | l = strtol(cp, &endp, 10); |
103 | if (endp == cp || *endp != '\0' || l < 0 || l >= INT_MAX) | ||
104 | goto again; | ||
105 | proto.p_proto = l; | ||
108 | q = proto.p_aliases = proto_aliases; | 106 | q = proto.p_aliases = proto_aliases; |
109 | if (p != NULL) { | 107 | if (p != NULL) { |
110 | cp = p; | 108 | cp = p; |