diff options
author | millert <> | 1999-09-03 16:23:19 +0000 |
---|---|---|
committer | millert <> | 1999-09-03 16:23:19 +0000 |
commit | 23b5374f8e5e1cf893e358275617ba8b58163ae7 (patch) | |
tree | 7ce15115dafea63e80fab4d6099642a83b95444e /src/lib/libc/net/getprotoent.c | |
parent | 16cba6f0dd5d54ed11696fbb4b172ea0e3d44036 (diff) | |
download | openbsd-23b5374f8e5e1cf893e358275617ba8b58163ae7.tar.gz openbsd-23b5374f8e5e1cf893e358275617ba8b58163ae7.tar.bz2 openbsd-23b5374f8e5e1cf893e358275617ba8b58163ae7.zip |
Use strtol() and strtoul() instead of atoi(). This allows us to catch
errors reasonably and deal correctly with unsigned quantities.
Diffstat (limited to 'src/lib/libc/net/getprotoent.c')
-rw-r--r-- | src/lib/libc/net/getprotoent.c | 10 |
1 files changed, 7 insertions, 3 deletions
diff --git a/src/lib/libc/net/getprotoent.c b/src/lib/libc/net/getprotoent.c index 2bef526e7a..2f8b267611 100644 --- a/src/lib/libc/net/getprotoent.c +++ b/src/lib/libc/net/getprotoent.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: getprotoent.c,v 1.3 1998/03/16 05:06:59 millert Exp $"; | 35 | static char rcsid[] = "$OpenBSD: getprotoent.c,v 1.4 1999/09/03 16:23:18 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> |
@@ -74,7 +74,8 @@ endprotoent() | |||
74 | struct protoent * | 74 | struct protoent * |
75 | getprotoent() | 75 | getprotoent() |
76 | { | 76 | { |
77 | char *p, *cp, **q; | 77 | char *p, *cp, **q, *endp; |
78 | long l; | ||
78 | size_t len; | 79 | size_t len; |
79 | 80 | ||
80 | if (protof == NULL && (protof = fopen(_PATH_PROTOCOLS, "r" )) == NULL) | 81 | if (protof == NULL && (protof = fopen(_PATH_PROTOCOLS, "r" )) == NULL) |
@@ -102,7 +103,10 @@ again: | |||
102 | p = strpbrk(cp, " \t"); | 103 | p = strpbrk(cp, " \t"); |
103 | if (p != NULL) | 104 | if (p != NULL) |
104 | *p++ = '\0'; | 105 | *p++ = '\0'; |
105 | 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; | ||
106 | q = proto.p_aliases = proto_aliases; | 110 | q = proto.p_aliases = proto_aliases; |
107 | if (p != NULL) { | 111 | if (p != NULL) { |
108 | cp = p; | 112 | cp = p; |