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/getservent.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/getservent.c')
-rw-r--r-- | src/lib/libc/net/getservent.c | 10 |
1 files changed, 7 insertions, 3 deletions
diff --git a/src/lib/libc/net/getservent.c b/src/lib/libc/net/getservent.c index 7d8cb6d8ca..ff6bf1e57f 100644 --- a/src/lib/libc/net/getservent.c +++ b/src/lib/libc/net/getservent.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: getservent.c,v 1.4 1998/03/16 05:07:00 millert Exp $"; | 35 | static char rcsid[] = "$OpenBSD: getservent.c,v 1.5 1999/09/03 16:23:19 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 @@ endservent() | |||
74 | struct servent * | 74 | struct servent * |
75 | getservent() | 75 | getservent() |
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 (servf == NULL && (servf = fopen(_PATH_SERVICES, "r" )) == NULL) | 81 | if (servf == NULL && (servf = fopen(_PATH_SERVICES, "r" )) == NULL) |
@@ -103,7 +104,10 @@ again: | |||
103 | if (cp == NULL) | 104 | if (cp == NULL) |
104 | goto again; | 105 | goto again; |
105 | *cp++ = '\0'; | 106 | *cp++ = '\0'; |
106 | serv.s_port = htons((in_port_t)atoi(p)); | 107 | l = strtol(p, &endp, 10); |
108 | if (endp == p || *endp != '\0' || l < 0 || l > USHRT_MAX) | ||
109 | goto again; | ||
110 | serv.s_port = htons((in_port_t)l); | ||
107 | serv.s_proto = cp; | 111 | serv.s_proto = cp; |
108 | q = serv.s_aliases = serv_aliases; | 112 | q = serv.s_aliases = serv_aliases; |
109 | cp = strpbrk(cp, " \t"); | 113 | cp = strpbrk(cp, " \t"); |