summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNick Mathewson <nickm@torproject.org>2009-01-04 19:47:17 +0000
committerNick Mathewson <nickm@torproject.org>2009-01-04 19:47:17 +0000
commit9c94b428d9f30f1c5a493856cfea293c634a3c9f (patch)
treea92189d7d7cafee62249609f8e8d83844adc1e84
parent360a059948e47b69bd86caf3b1de698954093df8 (diff)
downloadtor-9c94b428d9f30f1c5a493856cfea293c634a3c9f.tar.gz
tor-9c94b428d9f30f1c5a493856cfea293c634a3c9f.zip
Fix the oldest bug in a while: stop accepting 1.2.3 as a valid IPv4 address on any platform.
svn:r17887
-rw-r--r--ChangeLog2
-rw-r--r--src/common/compat.c15
-rw-r--r--src/or/test.c2
3 files changed, 17 insertions, 2 deletions
diff --git a/ChangeLog b/ChangeLog
index 9ba226cb73..d4b8081555 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -31,6 +31,8 @@ Changes in version 0.2.1.10-alpha - 2009-01-??
0.2.1.9-alpha.
- Do not remove routers as too old if we do not have any consensus
document. Bugfix on 0.2.0.7-alpha.
+ - Do not accept incomplete ipv4 addresses (like 192.168.0) as valid.
+ Spec conformance issue. Bugfix on Tor 0.0.2pre27.
o Deprecated and removed features:
- The old "tor --version --version" command, which would spit out the
diff --git a/src/common/compat.c b/src/common/compat.c
index c54342e56f..904d5308cb 100644
--- a/src/common/compat.c
+++ b/src/common/compat.c
@@ -1207,8 +1207,20 @@ get_user_homedir(const char *username)
* but works on Windows and Solaris.)
*/
int
-tor_inet_aton(const char *c, struct in_addr* addr)
+tor_inet_aton(const char *str, struct in_addr* addr)
{
+ int a,b,c,d;
+ char more;
+ if (sscanf(str, "%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;
+
+#if 0
#ifdef HAVE_INET_ATON
return inet_aton(c, addr);
#else
@@ -1225,6 +1237,7 @@ tor_inet_aton(const char *c, struct in_addr* addr)
addr->s_addr = r;
return 1;
#endif
+#endif
}
/** Given <b>af</b>==AF_INET and <b>src</b> a struct in_addr, or
diff --git a/src/or/test.c b/src/or/test.c
index e3f92f6d4f..cf33840264 100644
--- a/src/or/test.c
+++ b/src/or/test.c
@@ -1699,7 +1699,7 @@ test_util_ip6_helpers(void)
test_eq(i, -1);
i = tor_addr_parse_reverse_lookup_name(&t1, "32.1.1.in-addr.arpa",
AF_UNSPEC, 0);
- /* test_eq(i, -1); XXXX021 Apparently '32.1.1' is a valid aton address. */
+ test_eq(i, -1);
i = tor_addr_parse_reverse_lookup_name(&t1, ".in-addr.arpa",
AF_UNSPEC, 0);
test_eq(i, -1);