diff options
Diffstat (limited to 'src/lib/libc/net/getprotoent.c')
-rw-r--r-- | src/lib/libc/net/getprotoent.c | 32 |
1 files changed, 17 insertions, 15 deletions
diff --git a/src/lib/libc/net/getprotoent.c b/src/lib/libc/net/getprotoent.c index 1179b9029b..2f8b267611 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. |
@@ -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: getprotoent.c,v 1.4 1999/09/03 16:23:18 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 */ | 36 | #endif /* LIBC_SCCS and not lint */ |
43 | 37 | ||
44 | #include <sys/types.h> | 38 | #include <sys/types.h> |
@@ -80,20 +74,25 @@ endprotoent() | |||
80 | struct protoent * | 74 | struct protoent * |
81 | getprotoent() | 75 | getprotoent() |
82 | { | 76 | { |
83 | char *p; | 77 | char *p, *cp, **q, *endp; |
84 | register char *cp, **q; | 78 | long l; |
79 | size_t len; | ||
85 | 80 | ||
86 | if (protof == NULL && (protof = fopen(_PATH_PROTOCOLS, "r" )) == NULL) | 81 | if (protof == NULL && (protof = fopen(_PATH_PROTOCOLS, "r" )) == NULL) |
87 | return (NULL); | 82 | return (NULL); |
88 | again: | 83 | again: |
89 | if ((p = fgets(line, BUFSIZ, protof)) == NULL) | 84 | if ((p = fgetln(protof, &len)) == NULL) |
90 | return (NULL); | 85 | return (NULL); |
91 | if (*p == '#') | 86 | if (p[len-1] == '\n') |
87 | len--; | ||
88 | if (len >= sizeof(line) || len == 0) | ||
92 | goto again; | 89 | goto again; |
93 | cp = strpbrk(p, "#\n"); | 90 | p = memcpy(line, p, len); |
94 | if (cp == NULL) | 91 | line[len] = '\0'; |
92 | if (*p == '#') | ||
95 | goto again; | 93 | goto again; |
96 | *cp = '\0'; | 94 | if ((cp = strchr(p, '#')) != NULL) |
95 | *cp = '\0'; | ||
97 | proto.p_name = p; | 96 | proto.p_name = p; |
98 | cp = strpbrk(p, " \t"); | 97 | cp = strpbrk(p, " \t"); |
99 | if (cp == NULL) | 98 | if (cp == NULL) |
@@ -104,7 +103,10 @@ again: | |||
104 | p = strpbrk(cp, " \t"); | 103 | p = strpbrk(cp, " \t"); |
105 | if (p != NULL) | 104 | if (p != NULL) |
106 | *p++ = '\0'; | 105 | *p++ = '\0'; |
107 | proto.p_proto = atoi(cp); | 106 | l = strtol(cp, &endp, 10); |
107 | if (endp == cp || *endp != '\0' || l < 0 || l >= INT_MAX) | ||
108 | goto again; | ||
109 | proto.p_proto = l; | ||
108 | q = proto.p_aliases = proto_aliases; | 110 | q = proto.p_aliases = proto_aliases; |
109 | if (p != NULL) { | 111 | if (p != NULL) { |
110 | cp = p; | 112 | cp = p; |