summaryrefslogtreecommitdiff
path: root/lib/libc/net/getservent.c
diff options
context:
space:
mode:
authorTodd C. Miller <millert@cvs.openbsd.org>1999-09-03 16:23:20 +0000
committerTodd C. Miller <millert@cvs.openbsd.org>1999-09-03 16:23:20 +0000
commit49aebb598146d4d57b680055b575b4923212427c (patch)
tree5585ce86b34fdabf330c018ebbede316ae795f7a /lib/libc/net/getservent.c
parent30af2905c3d217ed35bfdf507d777f1695b39a87 (diff)
Use strtol() and strtoul() instead of atoi(). This allows us to catch
errors reasonably and deal correctly with unsigned quantities.
Diffstat (limited to 'lib/libc/net/getservent.c')
-rw-r--r--lib/libc/net/getservent.c10
1 files changed, 7 insertions, 3 deletions
diff --git a/lib/libc/net/getservent.c b/lib/libc/net/getservent.c
index 7d8cb6d8cad..ff6bf1e57f8 100644
--- a/lib/libc/net/getservent.c
+++ b/lib/libc/net/getservent.c
@@ -32,7 +32,7 @@
*/
#if defined(LIBC_SCCS) && !defined(lint)
-static char rcsid[] = "$OpenBSD: getservent.c,v 1.4 1998/03/16 05:07:00 millert Exp $";
+static char rcsid[] = "$OpenBSD: getservent.c,v 1.5 1999/09/03 16:23:19 millert Exp $";
#endif /* LIBC_SCCS and not lint */
#include <sys/types.h>
@@ -74,7 +74,8 @@ endservent()
struct servent *
getservent()
{
- char *p, *cp, **q;
+ char *p, *cp, **q, *endp;
+ long l;
size_t len;
if (servf == NULL && (servf = fopen(_PATH_SERVICES, "r" )) == NULL)
@@ -103,7 +104,10 @@ again:
if (cp == NULL)
goto again;
*cp++ = '\0';
- serv.s_port = htons((in_port_t)atoi(p));
+ l = strtol(p, &endp, 10);
+ if (endp == p || *endp != '\0' || l < 0 || l > USHRT_MAX)
+ goto again;
+ serv.s_port = htons((in_port_t)l);
serv.s_proto = cp;
q = serv.s_aliases = serv_aliases;
cp = strpbrk(cp, " \t");