[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[or-cvs] r13371: Don't trigger an assert if we start a directory authority wi (in tor/trunk: . src/or)



Author: arma
Date: 2008-02-04 11:58:50 -0500 (Mon, 04 Feb 2008)
New Revision: 13371

Modified:
   tor/trunk/ChangeLog
   tor/trunk/src/or/config.c
   tor/trunk/src/or/or.h
   tor/trunk/src/or/router.c
   tor/trunk/src/or/routerlist.c
Log:
Don't trigger an assert if we start a directory authority with a
private IP address (like 127.0.0.1).


Modified: tor/trunk/ChangeLog
===================================================================
--- tor/trunk/ChangeLog	2008-02-04 16:54:14 UTC (rev 13370)
+++ tor/trunk/ChangeLog	2008-02-04 16:58:50 UTC (rev 13371)
@@ -16,6 +16,8 @@
       0.1.2.x.
     - Stop incorrectly truncating zlib responses to directory authority
       signature download requests.  Fix for bug 593.  Bugfix on 0.2.0.x.
+    - Don't trigger an assert if we start a directory authority with a
+      private IP address (like 127.0.0.1).
 
 
 Changes in version 0.2.0.18-alpha - 2008-01-25

Modified: tor/trunk/src/or/config.c
===================================================================
--- tor/trunk/src/or/config.c	2008-02-04 16:54:14 UTC (rev 13370)
+++ tor/trunk/src/or/config.c	2008-02-04 16:58:50 UTC (rev 13371)
@@ -2872,7 +2872,7 @@
           options->V1AuthoritativeDir || options->V2AuthoritativeDir ||
           options->V3AuthoritativeDir))
       REJECT("AuthoritativeDir is set, but none of "
-             "(Bridge/HS/V1/V2/V3)AuthoriativeDir is set.");
+             "(Bridge/HS/V1/V2/V3)AuthoritativeDir is set.");
   }
 
   if (options->AuthoritativeDir && !options->DirPort)
@@ -3974,12 +3974,12 @@
   return r;
 }
 
-/** Read the contents of a DirServer line from <b>line</b>.  Return 0
- * if the line is well-formed, and -1 if it isn't.  If
+/** Read the contents of a DirServer line from <b>line</b>. If
  * <b>validate_only</b> is 0, and the line is well-formed, and it
  * shares any bits with <b>required_type</b> or <b>required_type</b>
  * is 0, then add the dirserver described in the line (minus whatever
- * bits it's missing) as a valid authority. */
+ * bits it's missing) as a valid authority. Return 0 on success,
+ * or -1 if the line isn't well-formed or if we can't add it. */
 static int
 parse_dir_server_line(const char *line, authority_type_t required_type,
                       int validate_only)
@@ -4088,8 +4088,9 @@
                               * authority for. */
     log_debug(LD_DIR, "Trusted %d dirserver at %s:%d (%s)", (int)type,
               address, (int)dir_port, (char*)smartlist_get(items,0));
-    add_trusted_dir_server(nickname, address, dir_port, or_port, digest,
-                           v3_digest, type);
+    if (!add_trusted_dir_server(nickname, address, dir_port, or_port,
+                                digest, v3_digest, type))
+      goto err;
   }
 
   r = 0;

Modified: tor/trunk/src/or/or.h
===================================================================
--- tor/trunk/src/or/or.h	2008-02-04 16:54:14 UTC (rev 13370)
+++ tor/trunk/src/or/or.h	2008-02-04 16:58:50 UTC (rev 13371)
@@ -3929,10 +3929,11 @@
 int router_exit_policy_all_routers_reject(uint32_t addr, uint16_t port,
                                           int need_uptime);
 int router_exit_policy_rejects_all(routerinfo_t *router);
-void add_trusted_dir_server(const char *nickname, const char *address,
-                       uint16_t dir_port, uint16_t or_port,
-                       const char *digest, const char *v3_auth_digest,
-                       authority_type_t type);
+trusted_dir_server_t *add_trusted_dir_server(const char *nickname,
+                           const char *address,
+                           uint16_t dir_port, uint16_t or_port,
+                           const char *digest, const char *v3_auth_digest,
+                           authority_type_t type);
 void authority_cert_free(authority_cert_t *cert);
 void clear_trusted_dir_servers(void);
 int any_trusted_dir_is_v1_authority(void);

Modified: tor/trunk/src/or/router.c
===================================================================
--- tor/trunk/src/or/router.c	2008-02-04 16:54:14 UTC (rev 13370)
+++ tor/trunk/src/or/router.c	2008-02-04 16:58:50 UTC (rev 13371)
@@ -559,16 +559,20 @@
           (options->BridgeAuthoritativeDir ? BRIDGE_AUTHORITY : NO_AUTHORITY) |
           (options->HSAuthoritativeDir ? HIDSERV_AUTHORITY : NO_AUTHORITY));
 
-  if (!router_get_trusteddirserver_by_digest(digest)) {
-    add_trusted_dir_server(options->Nickname, NULL,
-                           (uint16_t)options->DirPort,
-                           (uint16_t)options->ORPort,
-                           digest,
-                           v3_digest,
-                           type);
+  ds = router_get_trusteddirserver_by_digest(digest);
+  if (!ds) {
+    ds = add_trusted_dir_server(options->Nickname, NULL,
+                                (uint16_t)options->DirPort,
+                                (uint16_t)options->ORPort,
+                                digest,
+                                v3_digest,
+                                type);
+    if (!ds) {
+      log_err(LD_GENERAL,"We want to be a directory authority, but we "
+              "couldn't add ourselves to the authority list. Failing.");
+      return -1;
+    }
   }
-  ds = router_get_trusteddirserver_by_digest(digest);
-  tor_assert(ds);
   if (ds->type != type) {
     log_warn(LD_DIR,  "Configured authority type does not match authority "
              "type in DirServer list.  Adjusting. (%d v %d)",

Modified: tor/trunk/src/or/routerlist.c
===================================================================
--- tor/trunk/src/or/routerlist.c	2008-02-04 16:54:14 UTC (rev 13370)
+++ tor/trunk/src/or/routerlist.c	2008-02-04 16:58:50 UTC (rev 13371)
@@ -3366,8 +3366,9 @@
 
 /** Add to the list of authorized directory servers one at
  * <b>address</b>:<b>port</b>, with identity key <b>digest</b>.  If
- * <b>address</b> is NULL, add ourself. */
-void
+ * <b>address</b> is NULL, add ourself. Return 0 if success, -1 if
+ * we couldn't add it. */
+trusted_dir_server_t *
 add_trusted_dir_server(const char *nickname, const char *address,
                        uint16_t dir_port, uint16_t or_port,
                        const char *digest, const char *v3_auth_digest,
@@ -3385,14 +3386,14 @@
       log_warn(LD_CONFIG,
                "Couldn't find a suitable address when adding ourself as a "
                "trusted directory server.");
-      return;
+      return NULL;
     }
   } else {
     if (tor_lookup_hostname(address, &a)) {
       log_warn(LD_CONFIG,
                "Unable to lookup address for directory server at '%s'",
                address);
-      return;
+      return NULL;
     }
     hostname = tor_strdup(address);
   }
@@ -3433,6 +3434,7 @@
 
   smartlist_add(trusted_dir_servers, ent);
   router_dir_info_changed();
+  return ent;
 }
 
 /** Free storage held in <b>cert</b>. */