[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[or-cvs] r18419: {tor} Backport r17887: stop accepting 1.2.3 as a valid IPv4 addres (in tor/branches/tor-0_2_0-patches: . src/common src/or)



Author: nickm
Date: 2009-02-08 22:12:02 -0500 (Sun, 08 Feb 2009)
New Revision: 18419

Modified:
   tor/branches/tor-0_2_0-patches/ChangeLog
   tor/branches/tor-0_2_0-patches/src/common/compat.c
   tor/branches/tor-0_2_0-patches/src/or/eventdns.c
Log:
Backport r17887: stop accepting 1.2.3 as a valid IPv4 address.  This has security implications.

Modified: tor/branches/tor-0_2_0-patches/ChangeLog
===================================================================
--- tor/branches/tor-0_2_0-patches/ChangeLog	2009-02-09 03:11:58 UTC (rev 18418)
+++ tor/branches/tor-0_2_0-patches/ChangeLog	2009-02-09 03:12:02 UTC (rev 18419)
@@ -10,6 +10,8 @@
       Patch from Matthias Drochner.
     - Don't consider expiring already-closed client connections. Fixes
       bug 893. Bugfix on 0.0.2pre20.
+    - Do not accept incomplete ipv4 addresses (like 192.168.0) as valid.
+      Spec conformance issue. Bugfix on Tor 0.0.2pre27.
 
 
 Changes in version 0.2.0.33 - 2009-01-21

Modified: tor/branches/tor-0_2_0-patches/src/common/compat.c
===================================================================
--- tor/branches/tor-0_2_0-patches/src/common/compat.c	2009-02-09 03:11:58 UTC (rev 18418)
+++ tor/branches/tor-0_2_0-patches/src/common/compat.c	2009-02-09 03:12:02 UTC (rev 18419)
@@ -115,12 +115,6 @@
 #include "strlcat.c"
 #endif
 
-#ifndef INADDR_NONE
-/* This is used by inet_addr, but apparently Solaris doesn't define it
- * anyplace. */
-#define INADDR_NONE ((unsigned long) -1)
-#endif
-
 #ifdef HAVE_SYS_MMAN_H
 /** Implementation for tor_mmap_t: holds the regular tor_mmap_t, along
  * with extra fields needed for mmap()-based memory mapping. */
@@ -1169,24 +1163,18 @@
  * 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)
 {
-#ifdef HAVE_INET_ATON
-  return inet_aton(c, addr);
-#else
-  uint32_t r;
-  tor_assert(c);
-  tor_assert(addr);
-  if (strcmp(c, "255.255.255.255") == 0) {
-    addr->s_addr = 0xFFFFFFFFu;
-    return 1;
-  }
-  r = inet_addr(c);
-  if (r == INADDR_NONE)
+  int a,b,c,d;
+  char more;
+  if (sscanf(str, "%d.%d.%d.%d%c", &a,&b,&c,&d,&more) != 4)
     return 0;
-  addr->s_addr = r;
+  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;
-#endif
 }
 
 /** Given <b>af</b>==AF_INET and <b>src</b> a struct in_addr, or

Modified: tor/branches/tor-0_2_0-patches/src/or/eventdns.c
===================================================================
--- tor/branches/tor-0_2_0-patches/src/or/eventdns.c	2009-02-09 03:11:58 UTC (rev 18418)
+++ tor/branches/tor-0_2_0-patches/src/or/eventdns.c	2009-02-09 03:12:02 UTC (rev 18419)
@@ -357,20 +357,7 @@
 {
 	return err == EAGAIN || err == WSAEWOULDBLOCK;
 }
-static int
-inet_aton(const char *c, struct in_addr *addr)
-{
-	uint32_t r;
-	if (strcmp(c, "255.255.255.255") == 0) {
-		addr->s_addr = 0xffffffffu;
-	} else {
-		r = inet_addr(c);
-		if (r == INADDR_NONE)
-			return 0;
-		addr->s_addr = r;
-	}
-	return 1;
-}
+#define inet_aton(c, addr) tor_inet_aton((c), (addr))
 #define CLOSE_SOCKET(x) closesocket(x)
 #else
 #define last_error(sock) (errno)