Browse Source

r9309@totoro: nickm | 2006-11-13 19:05:41 -0500
Whitespace fixes, and clean up code from last natd patch.


svn:r8947

Nick Mathewson 17 years ago
parent
commit
0f6402f17b
4 changed files with 27 additions and 16 deletions
  1. 4 3
      src/or/config.c
  2. 19 11
      src/or/connection_edge.c
  3. 2 1
      src/or/main.c
  4. 2 1
      src/or/routerparse.c

+ 4 - 3
src/or/config.c

@@ -2100,18 +2100,19 @@ options_validate(or_options_t *old_options, or_options_t *options,
     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) {

+ 19 - 11
src/or/connection_edge.c

@@ -1479,7 +1479,8 @@ connection_ap_process_transparent(edge_connection_t *conn)
 
   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 @@ connection_ap_process_natd(edge_connection_t *conn)
 {
   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 @@ connection_ap_process_natd(edge_connection_t *conn)
     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) {

+ 2 - 1
src/or/main.c

@@ -1333,7 +1333,8 @@ extern uint64_t buf_total_used;
 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.

+ 2 - 1
src/or/routerparse.c

@@ -703,7 +703,8 @@ void dump_distinct_digests_xx(int severity);
 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",