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

[or-cvs] if we don"t like the result of getsockname, blow away the c...



Update of /home2/or/cvsroot/tor/src/or
In directory moria.mit.edu:/home2/arma/work/onion/0091/tor/src/or

Modified Files:
      Tag: tor-0_0_9-patches
	connection.c 
Log Message:
if we don't like the result of getsockname, blow away the connection.


Index: connection.c
===================================================================
RCS file: /home2/or/cvsroot/tor/src/or/connection.c,v
retrieving revision 1.310.2.9
retrieving revision 1.310.2.10
diff -u -d -r1.310.2.9 -r1.310.2.10
--- connection.c	24 Mar 2005 09:00:11 -0000	1.310.2.9
+++ connection.c	24 Mar 2005 09:03:13 -0000	1.310.2.10
@@ -443,6 +443,7 @@
   char addrbuf[256];
   /* length of the remote address. Must be an int, since accept() needs that. */
   int remotelen=256;
+  tor_assert(remotelen >= sizeof(struct sockaddr_in));
   memset(addrbuf, 0, sizeof(addrbuf));
 
   news = accept(conn->s,(struct sockaddr *)addrbuf,&remotelen);
@@ -479,7 +480,11 @@
     if (getsockname(news, (struct sockaddr*)addrbuf, &remotelen)<0) {
       log_fn(LOG_WARN, "getsockname() failed.");
     } else {
-      check_sockaddr_in((struct sockaddr*)addrbuf, remotelen, LOG_WARN);
+      if (check_sockaddr_in((struct sockaddr*)addrbuf, remotelen, LOG_WARN)<0) {
+        log_fn(LOG_WARN,"Something's wrong with this conn. Closing it.");
+        tor_close_socket(news);
+        return 0;
+      }
     }
   }