From 23b5374f8e5e1cf893e358275617ba8b58163ae7 Mon Sep 17 00:00:00 2001 From: millert <> Date: Fri, 3 Sep 1999 16:23:19 +0000 Subject: Use strtol() and strtoul() instead of atoi(). This allows us to catch errors reasonably and deal correctly with unsigned quantities. --- src/lib/libc/net/getprotoent.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'src/lib/libc/net/getprotoent.c') 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 @@ */ #if defined(LIBC_SCCS) && !defined(lint) -static char rcsid[] = "$OpenBSD: getprotoent.c,v 1.3 1998/03/16 05:06:59 millert Exp $"; +static char rcsid[] = "$OpenBSD: getprotoent.c,v 1.4 1999/09/03 16:23:18 millert Exp $"; #endif /* LIBC_SCCS and not lint */ #include @@ -74,7 +74,8 @@ endprotoent() struct protoent * getprotoent() { - char *p, *cp, **q; + char *p, *cp, **q, *endp; + long l; size_t len; if (protof == NULL && (protof = fopen(_PATH_PROTOCOLS, "r" )) == NULL) @@ -102,7 +103,10 @@ again: p = strpbrk(cp, " \t"); if (p != NULL) *p++ = '\0'; - proto.p_proto = atoi(cp); + l = strtol(cp, &endp, 10); + if (endp == cp || *endp != '\0' || l < 0 || l >= INT_MAX) + goto again; + proto.p_proto = l; q = proto.p_aliases = proto_aliases; if (p != NULL) { cp = p; -- cgit v1.2.3-55-g6feb