[or-cvs] reject odd-looking addresses at the client, rather than hav...

Roger Dingledine arma at seul.org
Tue Feb 1 12:19:46 UTC 2005


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

Modified Files:
	connection_edge.c 
Log Message:
reject odd-looking addresses at the client, rather than having
the server drop them because they're malformed.


Index: connection_edge.c
===================================================================
RCS file: /home2/or/cvsroot/tor/src/or/connection_edge.c,v
retrieving revision 1.271
retrieving revision 1.272
diff -u -d -r1.271 -r1.272
--- connection_edge.c	1 Feb 2005 00:37:16 -0000	1.271
+++ connection_edge.c	1 Feb 2005 12:19:44 -0000	1.272
@@ -329,6 +329,17 @@
   }
 }
 
+/** Return 1 if <b>address</b> has funny characters in it like
+ * colons. Return 0 if it's fine.
+ */
+static int
+address_is_invalid_destination(const char *address) {
+  /* FFFF should flesh this out */
+  if (strchr(address,':'))
+    return 1;
+  return 0;
+}
+
 /** connection_edge_process_inbuf() found a conn in state
  * socks_wait. See if conn->inbuf has the right bytes to proceed with
  * the socks handshake.
@@ -381,7 +392,7 @@
     /* .exit -- modify conn to specify the exit node. */
     char *s = strrchr(socks->address,'.');
     if (!s || s[1] == '\0') {
-      log_fn(LOG_WARN,"Malformed address '%s.exit'. Refusing.", socks->address);
+      log_fn(LOG_WARN,"Malformed exit address '%s'. Refusing.", socks->address);
       return -1;
     }
     conn->chosen_exit_name = tor_strdup(s+1);
@@ -391,6 +402,11 @@
   if (addresstype != ONION_HOSTNAME) {
     /* not a hidden-service request (i.e. normal or .exit) */
 
+    if (address_is_invalid_destination(socks->address)) {
+      log_fn(LOG_WARN,"Destination '%s' seems to be an invalid hostname. Failing.", socks->address);
+      return -1;
+    }
+
     if (socks->command == SOCKS_COMMAND_RESOLVE) {
       uint32_t answer = 0;
       struct in_addr in;



More information about the tor-commits mailing list