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

[or-cvs] Make directory download code slightly less likely to segfau...



Update of /home/or/cvsroot/tor/src/or
In directory moria:/tmp/cvs-serv31885/src/or

Modified Files:
	directory.c routerlist.c 
Log Message:
Make directory download code slightly less likely to segfault or assert.

Index: directory.c
===================================================================
RCS file: /home/or/cvsroot/tor/src/or/directory.c,v
retrieving revision 1.257
retrieving revision 1.258
diff -u -d -r1.257 -r1.258
--- directory.c	8 Sep 2005 06:22:43 -0000	1.257
+++ directory.c	8 Sep 2005 16:18:28 -0000	1.258
@@ -170,6 +170,8 @@
   int priv = purpose_is_private(purpose);
   int need_v1_support = purpose == DIR_PURPOSE_FETCH_DIR ||
                         purpose == DIR_PURPOSE_FETCH_RUNNING_LIST;
+  int need_v2_support = purpose == DIR_PURPOSE_FETCH_NETWORKSTATUS ||
+                        purpose == DIR_PURPOSE_FETCH_SERVERDESC;
 
   if (directconn) {
     if (fetch_fresh_first && purpose == DIR_PURPOSE_FETCH_NETWORKSTATUS &&
@@ -186,7 +188,7 @@
     }
     if (!ds) {
       /* anybody with a non-zero dirport will do */
-      r = router_pick_directory_server(1, fascistfirewall, 0,
+      r = router_pick_directory_server(1, fascistfirewall, need_v2_support,
                                        retry_if_no_servers);
       if (!r) {
         const char *which;

Index: routerlist.c
===================================================================
RCS file: /home/or/cvsroot/tor/src/or/routerlist.c,v
retrieving revision 1.271
retrieving revision 1.272
diff -u -d -r1.271 -r1.272
--- routerlist.c	8 Sep 2005 06:22:44 -0000	1.271
+++ routerlist.c	8 Sep 2005 16:18:28 -0000	1.272
@@ -1294,12 +1294,14 @@
    * publication time.  We want to download a new *one* if the most recent
    * one's publication time is under ABOUT_HALF_AN_HOUR.
    */
-
-  tor_assert(trusted_dir_servers);
+  if (!trusted_dir_servers || !smartlist_len(trusted_dir_servers))
+    return;
   n_dirservers = smartlist_len(trusted_dir_servers);
   SMARTLIST_FOREACH(trusted_dir_servers, trusted_dir_server_t *, ds,
      {
        networkstatus_t *ns = networkstatus_get_by_digest(ds->digest);
+       if (!ns)
+         continue;
        if (ns->published_on > now-ABOUT_TWO_DAYS)
          ++n_live;
        if (!most_recent || ns->received_on > most_recent_received) {
@@ -1330,7 +1332,7 @@
   for (i = most_recent_idx+1; needed; ++i) {
     char resource[HEX_DIGEST_LEN+1];
     trusted_dir_server_t *ds;
-    if (i > n_dirservers)
+    if (i >= n_dirservers)
       i = 0;
     ds = smartlist_get(trusted_dir_servers, i);
     base16_encode(resource, sizeof(resource), ds->digest, DIGEST_LEN);