From 3a99927859a16eee177ec934e116a57b92d60007 Mon Sep 17 00:00:00 2001 From: Nick Mathewson Date: Thu, 8 Sep 2005 16:18:28 +0000 Subject: [PATCH] Make directory download code slightly less likely to segfault or assert. svn:r4929 --- src/or/directory.c | 4 +++- src/or/routerlist.c | 8 +++++--- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/or/directory.c b/src/or/directory.c index c340e504b2..1dc0a9fb45 100644 --- a/src/or/directory.c +++ b/src/or/directory.c @@ -170,6 +170,8 @@ directory_get_from_dirserver(uint8_t purpose, const char *resource, 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 @@ directory_get_from_dirserver(uint8_t purpose, const char *resource, } 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; diff --git a/src/or/routerlist.c b/src/or/routerlist.c index c572f3d2ac..b9b590c6db 100644 --- a/src/or/routerlist.c +++ b/src/or/routerlist.c @@ -1294,12 +1294,14 @@ update_networkstatus_downloads(void) * 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 @@ update_networkstatus_downloads(void) 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);