diff options
author | Nick Mathewson <nickm@torproject.org> | 2009-02-10 19:43:11 +0000 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2009-02-10 19:43:11 +0000 |
commit | da49d6a3b05cd7d3c9d417f4f08cb63431635617 (patch) | |
tree | 1294133b9f3f76181eaa0de931d1c18cdd4fe274 /evutil.c | |
parent | 01456265c3113c401579895f60c410202d633788 (diff) | |
download | libevent-da49d6a3b05cd7d3c9d417f4f08cb63431635617.tar.gz |
Stop using platform inet_aton/inet_addr; they can behave strangely on certain misformed addresses.
svn:r1111
Diffstat (limited to 'evutil.c')
-rw-r--r-- | evutil.c | 26 |
1 files changed, 11 insertions, 15 deletions
@@ -479,21 +479,17 @@ evutil_inet_pton(int af, const char *src, void *dst) return inet_pton(af, src, dst); #else if (af == AF_INET) { -#ifdef _EVENT_HAVE_INET_ATON - return inet_aton(src, dst); -#else - ev_uint32_t r; - struct in_addr *out = dst; - if (strcmp(src, "255.255.255.255") == 0) { - out->s_addr = 0xffffffffu; - } else { - r = inet_addr(src); - if (r == INADDR_NONE) - return 0; - out->s_addr = r; - } - return 1; -#endif + int a,b,c,d; + char more; + struct in_addr *addr = dst; + if (sscanf(src, "%d.%d.%d.%d%c", &a,&b,&c,&d,&more) != 4) + return 0; + if (a < 0 || a > 255) return 0; + if (b < 0 || b > 255) return 0; + if (c < 0 || c > 255) return 0; + if (d < 0 || d > 255) return 0; + addr->s_addr = htonl((a<<24) | (b<<16) | (c<<8) | d); + return 1; #ifdef AF_INET6 } else if (af == AF_INET6) { struct in6_addr *out = dst; |