[or-cvs] r11926: backport r11828: when accept gives us something we didn't wa (in tor/branches/tor-0_1_2-patches: . doc src/or)

nickm at seul.org nickm at seul.org
Sun Oct 14 08:48:51 UTC 2007


Author: nickm
Date: 2007-10-14 04:48:51 -0400 (Sun, 14 Oct 2007)
New Revision: 11926

Modified:
   tor/branches/tor-0_1_2-patches/
   tor/branches/tor-0_1_2-patches/ChangeLog
   tor/branches/tor-0_1_2-patches/doc/TODO.012
   tor/branches/tor-0_1_2-patches/src/or/connection.c
Log:
 r15761 at catbus:  nickm | 2007-10-14 04:24:18 -0400
 backport r11828:  when accept gives us something we didn't want (which means "not AF_INET" in 0.1.2.x) then warn and bail from connection_handle_listener_read().



Property changes on: tor/branches/tor-0_1_2-patches
___________________________________________________________________
 svk:merge ticket from /tor/012 [r15761] on 8246c3cf-6607-4228-993b-4d95d33730f1

Modified: tor/branches/tor-0_1_2-patches/ChangeLog
===================================================================
--- tor/branches/tor-0_1_2-patches/ChangeLog	2007-10-14 08:48:48 UTC (rev 11925)
+++ tor/branches/tor-0_1_2-patches/ChangeLog	2007-10-14 08:48:51 UTC (rev 11926)
@@ -31,6 +31,8 @@
     - When we have our clock set far in the future and generate an onion key,
       then re-set our clock to be correct, we should not stop the onion
       key from getting rotated.
+    - On some platforms, accept() can return a broken address.  Detect
+      this more quietly, and deal accordingly.  (Fixes bug 483.)
 
 
 Changes in version 0.1.2.17 - 2007-08-30

Modified: tor/branches/tor-0_1_2-patches/doc/TODO.012
===================================================================
--- tor/branches/tor-0_1_2-patches/doc/TODO.012	2007-10-14 08:48:48 UTC (rev 11925)
+++ tor/branches/tor-0_1_2-patches/doc/TODO.012	2007-10-14 08:48:51 UTC (rev 11926)
@@ -3,7 +3,7 @@
 
 Backport items for 0.1.2:
   o r11166: Don't believe future dates from the state file.
-N - r11828+: Detect bad sa_family from accept().
+  o r11828+: Detect bad sa_family from accept().
 N - r11882: Avoid crash-bug 451.
 N - r11886: Consider family as well as identity when cannibalizing circuits.
 

Modified: tor/branches/tor-0_1_2-patches/src/or/connection.c
===================================================================
--- tor/branches/tor-0_1_2-patches/src/or/connection.c	2007-10-14 08:48:48 UTC (rev 11925)
+++ tor/branches/tor-0_1_2-patches/src/or/connection.c	2007-10-14 08:48:51 UTC (rev 11926)
@@ -736,7 +736,7 @@
   struct sockaddr_in remote;
   char addrbuf[256];
   /* length of the remote address. Must be whatever accept() needs. */
-  socklen_t remotelen = 256;
+  socklen_t remotelen = sizeof(addrbuf);
   char tmpbuf[INET_NTOA_BUF_LEN];
   tor_assert((size_t)remotelen >= sizeof(struct sockaddr_in));
   memset(addrbuf, 0, sizeof(addrbuf));
@@ -762,6 +762,16 @@
             news,conn->s);
 
   set_socket_nonblocking(news);
+  if (((struct sockaddr*)addrbuf)->sa_family != AF_INET) {
+    log_info(LD_BUG, "A listener connection returned a socket with a "
+             "mismatched family.  %s for addr_family %d gave us a socket "
+             "with address family %d.  Dropping.",
+             conn_type_to_string(conn->type),
+             (int)AF_INET,
+             (int)((struct sockaddr*)addrbuf)->sa_family);
+    tor_close_socket(news);
+    return 0;
+  }
 
   if (check_sockaddr_in((struct sockaddr*)addrbuf, remotelen, LOG_INFO)<0) {
     log_info(LD_NET,



More information about the tor-commits mailing list