summaryrefslogtreecommitdiff
path: root/src/feature/control
diff options
context:
space:
mode:
authorNick Mathewson <nickm@torproject.org>2021-05-26 13:02:56 -0400
committerNick Mathewson <nickm@torproject.org>2021-05-26 13:02:56 -0400
commitd12b16614d09b303f9ef9624107b589264537341 (patch)
tree0cd377212c883b56d91150ebef7e35b2b2b9069f /src/feature/control
parent4a7379b80a3d0f61d258b26f82d894da9b8cd0f5 (diff)
downloadtor-d12b16614d09b303f9ef9624107b589264537341.tar.gz
tor-d12b16614d09b303f9ef9624107b589264537341.zip
Prefer mmap()ed consensus files over cached_dir_t entries.
Cached_dir_t is a somewhat "legacy" kind of storage when used for consensus documents, and it appears that there are cases when changing our settings causes us to stop updating those entries. This can cause trouble, as @arma found out in #40375, where he changed his settings around, and consensus diff application got messed up: consensus diffs were being _requested_ based on the latest consensus, but were being (incorrectly) applied to a consensus that was no longer the latest one. This patch is a minimal fix for backporting purposes: it has Tor do the same search when applying consensus diffs as we use to request them. This should be sufficient for correct behavior. There's a similar case in GETINFO handling; I've fixed that too. Fixes #40375; bugfix on 0.3.1.1-alpha.
Diffstat (limited to 'src/feature/control')
-rw-r--r--src/feature/control/control_getinfo.c32
1 files changed, 15 insertions, 17 deletions
diff --git a/src/feature/control/control_getinfo.c b/src/feature/control/control_getinfo.c
index 5feadd23d1..899f188546 100644
--- a/src/feature/control/control_getinfo.c
+++ b/src/feature/control/control_getinfo.c
@@ -353,26 +353,24 @@ getinfo_helper_current_consensus(consensus_flavor_t flavor,
*errmsg = "Internal error: unrecognized flavor name.";
return -1;
}
- if (we_want_to_fetch_flavor(get_options(), flavor)) {
- /** Check from the cache */
- const cached_dir_t *consensus = dirserv_get_consensus(flavor_name);
- if (consensus) {
- *answer = tor_strdup(consensus->dir);
- }
+ tor_mmap_t *mapped = networkstatus_map_cached_consensus(flavor_name);
+ if (mapped) {
+ *answer = tor_memdup_nulterm(mapped->data, mapped->size);
+ tor_munmap_file(mapped);
}
- if (!*answer) { /* try loading it from disk */
-
- tor_mmap_t *mapped = networkstatus_map_cached_consensus(flavor_name);
- if (mapped) {
- *answer = tor_memdup_nulterm(mapped->data, mapped->size);
- tor_munmap_file(mapped);
- }
- if (!*answer) { /* generate an error */
- *errmsg = "Could not open cached consensus. "
- "Make sure FetchUselessDescriptors is set to 1.";
- return -1;
+ if (!*answer) { /* Maybe it's in the cache? */
+ if (we_want_to_fetch_flavor(get_options(), flavor)) {
+ const cached_dir_t *consensus = dirserv_get_consensus(flavor_name);
+ if (consensus) {
+ *answer = tor_strdup(consensus->dir);
+ }
}
}
+ if (!*answer) { /* generate an error */
+ *errmsg = "Could not open cached consensus. "
+ "Make sure FetchUselessDescriptors is set to 1.";
+ return -1;
+ }
return 0;
}