diff options
author | itojun <> | 2002-07-01 07:43:48 +0000 |
---|---|---|
committer | itojun <> | 2002-07-01 07:43:48 +0000 |
commit | 6ab363350120175a35ec0eb4710d1bc9182dd9ce (patch) | |
tree | 023ad61ce8d220c0680da7f24904168f4f0945fe /src | |
parent | 2017f10cf1ac39ad2de4d933762f297698a97f23 (diff) | |
download | openbsd-6ab363350120175a35ec0eb4710d1bc9182dd9ce.tar.gz openbsd-6ab363350120175a35ec0eb4710d1bc9182dd9ce.tar.bz2 openbsd-6ab363350120175a35ec0eb4710d1bc9182dd9ce.zip |
make more pedantic check on strtoul. from deraadt, sync w/kame
Diffstat (limited to 'src')
-rw-r--r-- | src/lib/libc/net/getaddrinfo.c | 20 |
1 files changed, 12 insertions, 8 deletions
diff --git a/src/lib/libc/net/getaddrinfo.c b/src/lib/libc/net/getaddrinfo.c index 0d945d1aba..da4bc47cb7 100644 --- a/src/lib/libc/net/getaddrinfo.c +++ b/src/lib/libc/net/getaddrinfo.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: getaddrinfo.c,v 1.36 2002/06/29 12:25:42 itojun Exp $ */ | 1 | /* $OpenBSD: getaddrinfo.c,v 1.37 2002/07/01 07:43:48 itojun Exp $ */ |
2 | /* $KAME: getaddrinfo.c,v 1.31 2000/08/31 17:36:43 itojun Exp $ */ | 2 | /* $KAME: getaddrinfo.c,v 1.31 2000/08/31 17:36:43 itojun Exp $ */ |
3 | 3 | ||
4 | /* | 4 | /* |
@@ -219,7 +219,7 @@ static const struct afd *find_afd(int); | |||
219 | static int addrconfig(const struct addrinfo *); | 219 | static int addrconfig(const struct addrinfo *); |
220 | #endif | 220 | #endif |
221 | #ifdef INET6 | 221 | #ifdef INET6 |
222 | static int ip6_str2scopeid(char *, struct sockaddr_in6 *); | 222 | static u_int32_t ip6_str2scopeid(char *, struct sockaddr_in6 *); |
223 | #endif | 223 | #endif |
224 | 224 | ||
225 | static void _sethtent(void); | 225 | static void _sethtent(void); |
@@ -292,8 +292,9 @@ str_isnumber(p) | |||
292 | if (*p == '\0') | 292 | if (*p == '\0') |
293 | return NO; | 293 | return NO; |
294 | ep = NULL; | 294 | ep = NULL; |
295 | errno = 0; | ||
295 | (void)strtoul(p, &ep, 10); | 296 | (void)strtoul(p, &ep, 10); |
296 | if (ep && *ep == '\0') | 297 | if (errno == 0 && ep && *ep == '\0') |
297 | return YES; | 298 | return YES; |
298 | else | 299 | else |
299 | return NO; | 300 | return NO; |
@@ -777,7 +778,7 @@ explore_numeric_scope(pai, hostname, servname, res) | |||
777 | 778 | ||
778 | error = explore_numeric(pai, addr, servname, res); | 779 | error = explore_numeric(pai, addr, servname, res); |
779 | if (error == 0) { | 780 | if (error == 0) { |
780 | int scopeid; | 781 | u_int32_t scopeid; |
781 | 782 | ||
782 | for (cur = *res; cur; cur = cur->ai_next) { | 783 | for (cur = *res; cur; cur = cur->ai_next) { |
783 | if (cur->ai_family != AF_INET6) | 784 | if (cur->ai_family != AF_INET6) |
@@ -967,12 +968,13 @@ addrconfig(pai) | |||
967 | 968 | ||
968 | #ifdef INET6 | 969 | #ifdef INET6 |
969 | /* convert a string to a scope identifier. XXX: IPv6 specific */ | 970 | /* convert a string to a scope identifier. XXX: IPv6 specific */ |
970 | static int | 971 | static u_int32_t |
971 | ip6_str2scopeid(scope, sin6) | 972 | ip6_str2scopeid(scope, sin6) |
972 | char *scope; | 973 | char *scope; |
973 | struct sockaddr_in6 *sin6; | 974 | struct sockaddr_in6 *sin6; |
974 | { | 975 | { |
975 | int scopeid; | 976 | u_int32_t scopeid; |
977 | u_long lscopeid; | ||
976 | struct in6_addr *a6 = &sin6->sin6_addr; | 978 | struct in6_addr *a6 = &sin6->sin6_addr; |
977 | char *ep; | 979 | char *ep; |
978 | 980 | ||
@@ -1002,8 +1004,10 @@ ip6_str2scopeid(scope, sin6) | |||
1002 | 1004 | ||
1003 | /* try to convert to a numeric id as a last resort */ | 1005 | /* try to convert to a numeric id as a last resort */ |
1004 | trynumeric: | 1006 | trynumeric: |
1005 | scopeid = (int)strtoul(scope, &ep, 10); | 1007 | errno = 0; |
1006 | if (*ep == '\0') | 1008 | lscopeid = strtoul(scope, &ep, 10); |
1009 | scopeid = lscopeid & 0xffffffff; | ||
1010 | if (errno == 0 && ep && *ep == '\0' && scopeid == lscopeid) | ||
1007 | return scopeid; | 1011 | return scopeid; |
1008 | else | 1012 | else |
1009 | return -1; | 1013 | return -1; |