[or-cvs] r17887: {tor} Fix the oldest bug in a while: stop accepting 1.2.3 as a val (in tor/trunk: . src/common src/or)

nickm at seul.org nickm at seul.org
Sun Jan 4 19:47:17 UTC 2009


Author: nickm
Date: 2009-01-04 14:47:17 -0500 (Sun, 04 Jan 2009)
New Revision: 17887

Modified:
   tor/trunk/ChangeLog
   tor/trunk/src/common/compat.c
   tor/trunk/src/or/test.c
Log:
Fix the oldest bug in a while: stop accepting 1.2.3 as a valid IPv4 address on any platform.

Modified: tor/trunk/ChangeLog
===================================================================
--- tor/trunk/ChangeLog	2009-01-04 19:47:12 UTC (rev 17886)
+++ tor/trunk/ChangeLog	2009-01-04 19:47:17 UTC (rev 17887)
@@ -31,6 +31,8 @@
       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

Modified: tor/trunk/src/common/compat.c
===================================================================
--- tor/trunk/src/common/compat.c	2009-01-04 19:47:12 UTC (rev 17886)
+++ tor/trunk/src/common/compat.c	2009-01-04 19:47:17 UTC (rev 17887)
@@ -1207,8 +1207,20 @@
  * 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 @@
   addr->s_addr = r;
   return 1;
 #endif
+#endif
 }
 
 /** Given <b>af</b>==AF_INET and <b>src</b> a struct in_addr, or

Modified: tor/trunk/src/or/test.c
===================================================================
--- tor/trunk/src/or/test.c	2009-01-04 19:47:12 UTC (rev 17886)
+++ tor/trunk/src/or/test.c	2009-01-04 19:47:17 UTC (rev 17887)
@@ -1699,7 +1699,7 @@
   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);



More information about the tor-commits mailing list