[or-cvs] Fix segfault and logic error in last patch.

Nick Mathewson nickm at seul.org
Mon May 17 20:41:42 UTC 2004


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

Modified Files:
	routerlist.c 
Log Message:
Fix segfault and logic error in last patch.

Index: routerlist.c
===================================================================
RCS file: /home/or/cvsroot/src/or/routerlist.c,v
retrieving revision 1.76
retrieving revision 1.77
diff -u -d -r1.76 -r1.77
--- routerlist.c	17 May 2004 20:31:01 -0000	1.76
+++ routerlist.c	17 May 2004 20:41:40 -0000	1.77
@@ -408,10 +408,14 @@
     SMARTLIST_FOREACH(new_list->routers, routerinfo_t *, r,
                       if (r->dir_port) r->is_trusted_dir = 1);
   }
-  SMARTLIST_FOREACH(new_list->routers, routerinfo_t *, r,
-                    router_add_to_routerlist(r));
-  smartlist_clear(new_list->routers);
-  routerlist_free(new_list);
+  if (routerlist) {
+    SMARTLIST_FOREACH(new_list->routers, routerinfo_t *, r,
+                      router_add_to_routerlist(r));
+    smartlist_clear(new_list->routers);
+    routerlist_free(new_list);
+  } else {
+    routerlist = new_list;
+  }
   if (router_resolve_routerlist(routerlist)) {
     log(LOG_WARN, "Error resolving routerlist");
     return -1;
@@ -453,18 +457,22 @@
     log_fn(LOG_WARN, "Couldn't parse directory.");
     return -1;
   }
-  SMARTLIST_FOREACH(new_list->routers, routerinfo_t *, r,
-                    router_add_to_routerlist(r));
-  smartlist_clear(new_list->routers);
+  if (routerlist) {
+    SMARTLIST_FOREACH(new_list->routers, routerinfo_t *, r,
+                      router_add_to_routerlist(r));
+    smartlist_clear(new_list->routers);
+    routerlist->published_on = new_list->published_on;
+    tor_free(routerlist->software_versions);
+    routerlist->software_versions = new_list->software_versions;
+    new_list->software_versions = NULL;
+    routerlist_free(new_list);
+  } else {
+    routerlist = new_list;
+  }
   if (router_resolve_routerlist(routerlist)) {
     log_fn(LOG_WARN, "Error resolving routerlist");
     return -1;
   }
-  routerlist->published_on = new_list->published_on;
-  tor_free(routerlist->software_versions);
-  routerlist->software_versions = new_list->software_versions;
-  new_list->software_versions = NULL;
-  routerlist_free(new_list);
   if (!is_recommended_version(VERSION, routerlist->software_versions)) {
     log(options.IgnoreVersion ? LOG_WARN : LOG_ERR,
      "You are running Tor version %s, which will not work with this network.\n"
@@ -519,7 +527,7 @@
       remove = 1;
     } else if (r->addr) {
       /* already resolved. */
-    } else if (!router_resolve(r)) {
+    } else if (router_resolve(r)) {
       log_fn(LOG_WARN, "Couldn't resolve router %s; not using", r->address);
       remove = 1;
     }



More information about the tor-commits mailing list