[or-cvs] r8947: Whitespace fixes, and clean up code from last natd patch. (in tor/trunk: . src/or)

nickm at seul.org nickm at seul.org
Tue Nov 14 00:06:46 UTC 2006


Author: nickm
Date: 2006-11-13 19:06:45 -0500 (Mon, 13 Nov 2006)
New Revision: 8947

Modified:
   tor/trunk/
   tor/trunk/src/or/config.c
   tor/trunk/src/or/connection_edge.c
   tor/trunk/src/or/main.c
   tor/trunk/src/or/routerparse.c
Log:
 r9309 at totoro:  nickm | 2006-11-13 19:05:41 -0500
 Whitespace fixes, and clean up code from last natd patch.



Property changes on: tor/trunk
___________________________________________________________________
 svk:merge ticket from /tor/trunk [r9309] on 96637b51-b116-0410-a10e-9941ebb49b64

Modified: tor/trunk/src/or/config.c
===================================================================
--- tor/trunk/src/or/config.c	2006-11-14 00:06:31 UTC (rev 8946)
+++ tor/trunk/src/or/config.c	2006-11-14 00:06:45 UTC (rev 8947)
@@ -2100,18 +2100,19 @@
     int is_socks = i==0;
     int is_trans = i==1;
     config_line_t *line, *opt, *old;
-    const char *tp = is_socks ? "SOCKS proxy" :
-                     is_trans ? "transparent proxy"
-                              : "natd proxy";
+    const char *tp;
     if (is_socks) {
       opt = options->SocksListenAddress;
       old = old_options ? old_options->SocksListenAddress : NULL;
+      tp = "SOCKS proxy";
     } else if (is_trans) {
       opt = options->TransListenAddress;
       old = old_options ? old_options->TransListenAddress : NULL;
+      tp = "transparent proxy";
     } else {
       opt = options->NatdListenAddress;
       old = old_options ? old_options->NatdListenAddress : NULL;
+      tp = "natd proxy";
     }
 
     for (line = opt; line; line = line->next) {

Modified: tor/trunk/src/or/connection_edge.c
===================================================================
--- tor/trunk/src/or/connection_edge.c	2006-11-14 00:06:31 UTC (rev 8946)
+++ tor/trunk/src/or/connection_edge.c	2006-11-14 00:06:45 UTC (rev 8947)
@@ -1479,7 +1479,8 @@
 
   if (connection_ap_get_original_destination(conn, socks) < 0) {
     log_warn(LD_APP,"Fetching original destination failed. Closing.");
-    connection_mark_unattached_ap(conn, END_STREAM_REASON_CANT_FETCH_ORIG_DEST);
+    connection_mark_unattached_ap(conn,
+                               END_STREAM_REASON_CANT_FETCH_ORIG_DEST);
     return -1;
   }
   /* we have the original destination */
@@ -1509,7 +1510,7 @@
 {
   char tmp_buf[36], *tbuf, *daddr;
   size_t tlen = 30;
-  int err;
+  int err, port_ok;
   socks_request_t *socks;
   or_options_t *options = get_options();
 
@@ -1532,27 +1533,34 @@
     return -1;
   }
 
-  if (strncmp(tmp_buf, "[DEST ", 6)) {
-    log_warn(LD_APP,"Natd handshake failed. Closing. tmp_buf = '%s'", tmp_buf);
+  if (strcmpstart(tmp_buf, "[DEST ")) {
+    log_warn(LD_APP,"Natd handshake was ill-formed; closing. The client "
+             "said: '%s'",
+             escaped(tmp_buf));
     connection_mark_unattached_ap(conn, END_STREAM_REASON_INVALID_NATD_DEST);
     return -1;
   }
 
-  tbuf = &tmp_buf[0] + 6;
-  daddr = tbuf;
-  while (tbuf[0] != '\0' && tbuf[0] != ' ')
+  daddr = tbuf = &tmp_buf[0] + 6; /* after end of "[DEST " */
+  while (*tbuf != '\0' && *tbuf != ' ')
     tbuf++;
-  tbuf[0] = '\0';
+  *tbuf = '\0';
   tbuf++;
 
   /* pretend that a socks handshake completed so we don't try to
    * send a socks reply down a natd conn */
+  strlcpy(socks->address, daddr, sizeof(socks->address));
+  socks->port = (uint16_t) tor_parse_long(tbuf, 10, 1, 65535, &port_ok, NULL);
+  if (!port_ok) {
+    log_warn(LD_APP,"Natd handshake failed; port '%s' is ill-formed or out "
+             "of range.", escaped(tbuf));
+    connection_mark_unattached_ap(conn, END_STREAM_REASON_INVALID_NATD_DEST);
+    return -1;
+  }
+
   socks->command = SOCKS_COMMAND_CONNECT;
   socks->has_finished = 1;
 
-  strlcpy(socks->address, daddr, sizeof(socks->address));
-  socks->port = atoi(tbuf);
-
   control_event_stream_status(conn, STREAM_EVENT_NEW, 0);
 
   if (options->LeaveStreamsUnattached) {

Modified: tor/trunk/src/or/main.c
===================================================================
--- tor/trunk/src/or/main.c	2006-11-14 00:06:31 UTC (rev 8946)
+++ tor/trunk/src/or/main.c	2006-11-14 00:06:45 UTC (rev 8947)
@@ -1333,7 +1333,8 @@
 extern uint64_t buf_total_alloc;
 extern uint64_t rephist_total_alloc;
 extern uint32_t rephist_total_num;
-void dump_distinct_digests_xx(int severity); // xxxx0124 remove
+// xxxx0124 remove
+void dump_distinct_digests_xx(int severity);
 
 /**
  * Write current memory usage information to the log.

Modified: tor/trunk/src/or/routerparse.c
===================================================================
--- tor/trunk/src/or/routerparse.c	2006-11-14 00:06:31 UTC (rev 8946)
+++ tor/trunk/src/or/routerparse.c	2006-11-14 00:06:45 UTC (rev 8947)
@@ -703,7 +703,8 @@
 static digestmap_t *verified_digests_tmp = NULL; // XXXX0124 remove me.
 // remove me too.
 void
-dump_distinct_digests_xx(int severity) {
+dump_distinct_digests_xx(int severity)
+{
   if (!verified_digests_tmp)
     verified_digests_tmp = digestmap_new();
   log(severity, LD_GENERAL, "%d *distinct* router digests verified",



More information about the tor-commits mailing list