[or-cvs] Fix several bugs (including some crashes) related to contro...

Nick Mathewson nickm at seul.org
Wed Mar 23 08:40:14 UTC 2005


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

Modified Files:
	connection_edge.c control.c dirserv.c or.h 
Log Message:
Fix several bugs (including some crashes) related to control interface; implement missing desc/name functionality.

Index: connection_edge.c
===================================================================
RCS file: /home/or/cvsroot/tor/src/or/connection_edge.c,v
retrieving revision 1.304
retrieving revision 1.305
diff -u -d -r1.304 -r1.305
--- connection_edge.c	23 Mar 2005 05:32:06 -0000	1.304
+++ connection_edge.c	23 Mar 2005 08:40:10 -0000	1.305
@@ -413,7 +413,7 @@
 } virtaddress_entry_t;
 
 /** The tree of client-side address rewrite instructions. */
-static strmap_t *addressmap;
+static strmap_t *addressmap=NULL;
 /**
  * Tree mapping addresses to which virtual address, if any, we
  * assigned them to.
@@ -424,7 +424,7 @@
  * if it fails, then we could end up mapping two virtual addresses to
  * the same address, which is no disaster.
  **/
-static strmap_t *virtaddress_reversemap;
+static strmap_t *virtaddress_reversemap=NULL;
 
 /** Initialize addressmap. */
 void addressmap_init(void) {
@@ -454,6 +454,7 @@
   if (ent && address_is_in_virtual_range(ent->new_address)) {
     virtaddress_entry_t *ve =
       strmap_get(virtaddress_reversemap, ent->new_address);
+    /*log_fn(LOG_NOTICE,"remove reverse mapping for %s",ent->new_address);*/
     if (ve) {
       if (!strcmp(addr, ve->ipv4_address))
         tor_free(ve->ipv4_address);
@@ -533,8 +534,9 @@
 }
 
 /** Register a request to map <b>address</b> to <b>new_address</b>,
- * which will expire on <b>expires</b> (or 0 if never expires from config
- * file, 1 if never expires from controller).
+ * which will expire on <b>expires</b> (or 0 if never expires from
+ * config file, 1 if never expires from controller, 2 if never expires
+ * (virtual address mapping) from the controller.)
  *
  * <b>new_address</b> should be a newly dup'ed string, which we'll use or
  * free as appropriate. We will leave address alone.
@@ -564,14 +566,17 @@
       tor_free(new_address);
       return;
     }
-    if (address_is_in_virtual_range(ent->new_address)) {
+    if (address_is_in_virtual_range(ent->new_address) &&
+        expires != 2) {
+      /* XXX This isn't the perfect test; we want to avoid removing
+       * mappings set from the control interface _as virtual mapping */
       addressmap_virtaddress_remove(address, ent);
     }
     tor_free(ent->new_address);
   } /* else { we have an in-progress resolve with no mapping. } */
 
   ent->new_address = new_address;
-  ent->expires = expires;
+  ent->expires = expires==2 ? 1 : expires;
   ent->num_resolve_failures = 0;
 
   log_fn(LOG_INFO, "Addressmap: (re)mapped '%s' to '%s'",
@@ -673,7 +678,7 @@
   struct in_addr in;
 
   if (type == RESOLVED_TYPE_HOSTNAME) {
-    char rand[16];
+    char rand[10];
     do {
       crypto_rand(rand, sizeof(rand));
       base32_encode(buf,sizeof(buf),rand,sizeof(rand));
@@ -712,33 +717,53 @@
  * The string in <b>new_address</b> may be freed, or inserted into a map
  * as appropriate.
  **/
-char *
+const char *
 addressmap_register_virtual_address(int type, char *new_address)
 {
   char **addrp;
   virtaddress_entry_t *vent;
 
   tor_assert(new_address);
+  tor_assert(addressmap);
+  tor_assert(virtaddress_reversemap);
 
   vent = strmap_get(virtaddress_reversemap, new_address);
-  if (!vent)
+  if (!vent) {
     vent = tor_malloc_zero(sizeof(virtaddress_entry_t));
+    strmap_set(virtaddress_reversemap, new_address, vent);
+  }
 
   addrp = (type == RESOLVED_TYPE_IPV4) ?
     &vent->ipv4_address : &vent->hostname_address;
   if (*addrp) {
     addressmap_entry_t *ent = strmap_get(addressmap, *addrp);
-    if (!strcasecmp(new_address, ent->new_address))
+    if (ent && !strcasecmp(new_address, ent->new_address)) {
+      tor_free(new_address);
       return tor_strdup(*addrp);
-    else
+    } else
       log_fn(LOG_WARN, "Internal confusion: I thought that '%s' was mapped to by '%s', but '%s' really maps to '%s'. This is a harmless bug.",
-             new_address, *addrp, *addrp, ent->new_address);
+             new_address, *addrp, *addrp, ent?ent->new_address:"(nothing)");
   }
 
   tor_free(*addrp);
   *addrp = addressmap_get_virtual_address(type);
-  strmap_set(virtaddress_reversemap, new_address, tor_strdup(*addrp));
-  addressmap_register(*addrp, new_address, 1);
+  addressmap_register(*addrp, new_address, 2);
+
+#if 0
+  {
+    addressmap_entry_t *ent;
+    ent = strmap_get(addressmap, *addrp);
+    tor_assert(ent);
+    tor_assert(!strcasecmp(ent->new_address,new_address));
+    vent = strmap_get(virtaddress_reversemap, new_address);
+    tor_assert(vent);
+    tor_assert(!strcasecmp(*addrp,
+                           (type == RESOLVED_TYPE_IPV4) ?
+                           vent->ipv4_address : vent->hostname_address));
+    log_fn(LOG_INFO, "Map from %s to %s okay.",*addrp,new_address);
+  }
+#endif
+
   return *addrp;
 }
 

Index: control.c
===================================================================
RCS file: /home/or/cvsroot/tor/src/or/control.c,v
retrieving revision 1.63
retrieving revision 1.64
diff -u -d -r1.63 -r1.64
--- control.c	22 Mar 2005 19:36:38 -0000	1.63
+++ control.c	23 Mar 2005 08:40:10 -0000	1.64
@@ -329,7 +329,7 @@
   {
     int recognized = config_option_is_recognized(q);
     if (!recognized) {
-      send_control_error(conn, ERR_UNRECOGNIZED_CONFIG_KEY, body);
+      send_control_error(conn, ERR_UNRECOGNIZED_CONFIG_KEY, q);
       goto done;
     } else {
       struct config_line_t *answer = config_get_assigned_option(options,q);
@@ -508,7 +508,7 @@
       } else if (!is_plausible_address(to)) {
         log_fn(LOG_WARN,"Skipping invalid argument '%s' in MapAddress msg",to);
       } else if (!strcmp(from, ".") || !strcmp(from, "0.0.0.0")) {
-        char *addr = addressmap_register_virtual_address(
+        const char *addr = addressmap_register_virtual_address(
                strcmp(from,".") ? RESOLVED_TYPE_HOSTNAME : RESOLVED_TYPE_IPV4,
                tor_strdup(to));
         if (!addr) {
@@ -518,7 +518,6 @@
           size_t anslen = strlen(addr)+strlen(to)+2;
           char *ans = tor_malloc(anslen);
           tor_snprintf(ans, anslen, "%s %s", addr, to);
-          tor_free(addr);
           smartlist_add(reply, ans);
         }
       } else {
@@ -557,6 +556,10 @@
     routerinfo_t *ri = router_get_by_hexdigest(question+strlen("desc/id/"));
     if (ri && ri->signed_descriptor)
       *answer = tor_strdup(ri->signed_descriptor);
+  } else if (!strcmpstart(question, "desc/name/")) {
+    routerinfo_t *ri = router_get_by_nickname(question+strlen("desc/name/"));
+    if (ri && ri->signed_descriptor)
+      *answer = tor_strdup(ri->signed_descriptor);
   } else if (!strcmp(question, "network-status")) {
     if (list_server_status(NULL, answer) < 0)
       return -1;

Index: dirserv.c
===================================================================
RCS file: /home/or/cvsroot/tor/src/or/dirserv.c,v
retrieving revision 1.146
retrieving revision 1.147
diff -u -d -r1.146 -r1.147
--- dirserv.c	23 Mar 2005 06:39:53 -0000	1.146
+++ dirserv.c	23 Mar 2005 08:40:10 -0000	1.147
@@ -528,6 +528,9 @@
   rr_entries = smartlist_create();
   rs_entries = smartlist_create();
 
+  if (!descriptor_list)
+    descriptor_list = smartlist_create();
+
   SMARTLIST_FOREACH(descriptor_list, routerinfo_t *, ri,
   {
     int is_live;

Index: or.h
===================================================================
RCS file: /home/or/cvsroot/tor/src/or/or.h,v
retrieving revision 1.570
retrieving revision 1.571
diff -u -d -r1.570 -r1.571
--- or.h	23 Mar 2005 06:21:47 -0000	1.570
+++ or.h	23 Mar 2005 08:40:11 -0000	1.571
@@ -1347,7 +1347,7 @@
 void addressmap_register(const char *address, char *new_address, time_t expires);
 int client_dns_incr_failures(const char *address);
 void client_dns_set_addressmap(const char *address, uint32_t val, const char *exitname);
-char *addressmap_register_virtual_address(int type, char *new_address);
+const char *addressmap_register_virtual_address(int type, char *new_address);
 void addressmap_get_mappings(smartlist_t *sl, time_t min_expires, time_t max_expires);
 
 void parse_socks_policy(void);



More information about the tor-commits mailing list