[or-cvs] Fix critical bug in circuit_list_path: cpath is a circular ...

Nick Mathewson nickm at seul.org
Tue Nov 23 00:11:39 UTC 2004


Update of /home/or/cvsroot/tor/src/or
In directory moria.mit.edu:/tmp/cvs-serv2338/src/or

Modified Files:
	circuitbuild.c control.c or.h 
Log Message:
Fix critical bug in circuit_list_path: cpath is a circular list!  (Also reimplement circuit_log_cpath using circuit_list_cpath).

Index: circuitbuild.c
===================================================================
RCS file: /home/or/cvsroot/tor/src/or/circuitbuild.c,v
retrieving revision 1.59
retrieving revision 1.60
diff -u -d -r1.59 -r1.60
--- circuitbuild.c	21 Nov 2004 07:43:12 -0000	1.59
+++ circuitbuild.c	23 Nov 2004 00:11:36 -0000	1.60
@@ -61,36 +61,57 @@
   return test_circ_id;
 }
 
-/** Allocate and return a comma-separated list of the currently built
- * elements of circuit_t.
+/** If <b>verbose</b> is false, allocate and return a comma-separated
+ * list of the currently built elements of circuit_t.  If
+ * <b>verbose</b> is true, also list information about link status in
+ * a more verbose format using spaces.
  */
-char *circuit_list_path(circuit_t *circ)
+char *
+circuit_list_path(circuit_t *circ, int verbose)
 {
   struct crypt_path_t *hop;
-  routerinfo_t *r;
   smartlist_t *elements;
+  const char *states[] = {"closed", "waiting for keys", "open"};
+  char buf[128];
   char *s;
   tor_assert(CIRCUIT_IS_ORIGIN(circ));
   tor_assert(circ->cpath);
 
   elements = smartlist_create();
 
-  for (hop = circ->cpath; hop; hop = hop->next) {
-    if (hop->state != CPATH_STATE_OPEN)
+  if (verbose) {
+    tor_snprintf(buf, sizeof(buf)-1, "circ (length %d, exit %s):",
+                 circ->build_state->desired_path_len,
+                 circ->build_state->chosen_exit_name);
+    smartlist_add(elements, tor_strdup(buf));
+  }
+
+  for (hop = circ->cpath; hop && hop != circ->cpath; hop = hop->next) {
+    const char *elt;
+    routerinfo_t *r;
+    if (!verbose && hop->state != CPATH_STATE_OPEN)
       break;
     if ((r = router_get_by_digest(hop->identity_digest))) {
-      smartlist_add(elements, tor_strdup(r->nickname));
+      elt = r->nickname;
     } else if (circ->purpose == CIRCUIT_PURPOSE_C_REND_JOINED) {
-      smartlist_add(elements, tor_strdup("<rendezvous splice>"));
+      elt = "<rendezvous splice>";
     } else {
-      s = tor_malloc(HEX_DIGEST_LEN+2);
-      s[0]='$';
-      base16_encode(s+1,HEX_DIGEST_LEN+1,hop->identity_digest,DIGEST_LEN);
-      smartlist_add(elements, s);
+      buf[0]='$';
+      base16_encode(buf+1,sizeof(buf)-1,hop->identity_digest,DIGEST_LEN);
+      elt = buf;
+    }
+    if (verbose) {
+      size_t len = strlen(elt)+2+strlen(states[hop->state])+1;
+      char *v = tor_malloc(len);
+      tor_assert(hop->state <= 2);
+      tor_snprintf(v,len,"%s(%s)",elt,states[hop->state]);
+      smartlist_add(elements, v);
+    } else {
+      smartlist_add(elements, tor_strdup(elt));
     }
   }
 
-  s = smartlist_join_strings(elements, ",", 0, NULL);
+  s = smartlist_join_strings(elements, verbose?" ":",", 0, NULL);
   SMARTLIST_FOREACH(elements, char*, cp, tor_free(cp));
   return s;
 }
@@ -100,6 +121,11 @@
  * exit point.
  */
 void circuit_log_path(int severity, circuit_t *circ) {
+#if 1
+  char *s = circuit_list_path(circ,1);
+  log_fn(severity,"%s",s);
+  tor_free(s);
+#else
   char buf[1024];
   char *s = buf;
   struct crypt_path_t *hop;
@@ -127,6 +153,7 @@
     hop=hop->next;
   } while(hop!=circ->cpath);
   log_fn(severity,"%s",buf);
+#endif
 }
 
 /** Tell the rep(utation)hist(ory) module about the status of the links
@@ -631,7 +658,7 @@
   }
 
   hop->state = CPATH_STATE_OPEN;
-  log_fn(LOG_INFO,"finished");
+  log_fn(LOG_INFO,"Finished building circuit:");
   circuit_log_path(LOG_INFO,circ);
   control_event_circuit_status(circ, CIRC_EVENT_EXTENDED);
 

Index: control.c
===================================================================
RCS file: /home/or/cvsroot/tor/src/or/control.c,v
retrieving revision 1.28
retrieving revision 1.29
diff -u -d -r1.28 -r1.29
--- control.c	21 Nov 2004 10:14:57 -0000	1.28
+++ control.c	23 Nov 2004 00:11:36 -0000	1.29
@@ -492,7 +492,7 @@
   tor_assert(circ);
   tor_assert(CIRCUIT_IS_ORIGIN(circ));
 
-  path = circuit_list_path(circ);
+  path = circuit_list_path(circ,0);
   path_len = strlen(path);
   msg = tor_malloc(1+4+path_len+1); /* event, circid, path, NUL. */
   msg[0] = (uint8_t) tp;

Index: or.h
===================================================================
RCS file: /home/or/cvsroot/tor/src/or/or.h,v
retrieving revision 1.493
retrieving revision 1.494
diff -u -d -r1.493 -r1.494
--- or.h	22 Nov 2004 21:56:51 -0000	1.493
+++ or.h	23 Nov 2004 00:11:36 -0000	1.494
@@ -1032,7 +1032,7 @@
 
 /********************************* circuitbuild.c **********************/
 
-char *circuit_list_path(circuit_t *circ);
+char *circuit_list_path(circuit_t *circ, int verbose);
 void circuit_log_path(int severity, circuit_t *circ);
 void circuit_rep_hist_note_result(circuit_t *circ);
 void circuit_dump_by_conn(connection_t *conn, int severity);



More information about the tor-commits mailing list