diff options
author | Nick Mathewson <nickm@torproject.org> | 2018-09-11 09:38:20 -0400 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2018-09-11 11:16:50 -0400 |
commit | 5595b212270215eaa020603cabbe2c7b3b34d624 (patch) | |
tree | 1ea7bd05f23d00a7f09c7b769fbd350ba36880f7 /src/feature/dircache | |
parent | e5601f14ed4384e8de1030d21cc7442df48adabe (diff) | |
download | tor-5595b212270215eaa020603cabbe2c7b3b34d624.tar.gz tor-5595b212270215eaa020603cabbe2c7b3b34d624.zip |
Consdiff: use lengths on inputs so they don't need NUL at the end
This is part of #27244, so that we can safely mmap consensus
documents.
Diffstat (limited to 'src/feature/dircache')
-rw-r--r-- | src/feature/dircache/consdiffmgr.c | 9 | ||||
-rw-r--r-- | src/feature/dircache/directory.c | 10 |
2 files changed, 14 insertions, 5 deletions
diff --git a/src/feature/dircache/consdiffmgr.c b/src/feature/dircache/consdiffmgr.c index 304b64f3b6..7999df08d5 100644 --- a/src/feature/dircache/consdiffmgr.c +++ b/src/feature/dircache/consdiffmgr.c @@ -1496,7 +1496,10 @@ consensus_diff_worker_threadfn(void *state_, void *work_) // XXXX ugh; this is going to calculate the SHA3 of both its // XXXX inputs again, even though we already have that. Maybe it's time // XXXX to change the API here? - consensus_diff = consensus_diff_generate(diff_from_nt, diff_to_nt); + consensus_diff = consensus_diff_generate(diff_from_nt, + strlen(diff_from_nt), + diff_to_nt, + strlen(diff_to_nt)); tor_free(diff_from_nt); tor_free(diff_to_nt); } @@ -1746,8 +1749,8 @@ consensus_compress_worker_threadfn(void *state_, void *work_) (const uint8_t *)consensus, bodylen); { const char *start, *end; - if (router_get_networkstatus_v3_signed_boundaries(consensus, - &start, &end) < 0) { + if (router_get_networkstatus_v3_signed_boundaries(consensus, bodylen, + &start, &end) < 0) { start = consensus; end = consensus+bodylen; } diff --git a/src/feature/dircache/directory.c b/src/feature/dircache/directory.c index de0bcdbfa7..8e5fc86836 100644 --- a/src/feature/dircache/directory.c +++ b/src/feature/dircache/directory.c @@ -2607,12 +2607,17 @@ handle_response_fetch_consensus(dir_connection_t *conn, /* First find our previous consensus. Maybe it's in ram, maybe not. */ cached_dir_t *cd = dirserv_get_consensus(flavname); const char *consensus_body; + size_t consensus_body_len; char *owned_consensus = NULL; if (cd) { consensus_body = cd->dir; + consensus_body_len = cd->dir_len; } else { owned_consensus = networkstatus_read_cached_consensus(flavname); - consensus_body = owned_consensus; + if (owned_consensus) { + consensus_body = owned_consensus; + consensus_body_len = strlen(consensus_body); + } } if (!consensus_body) { log_warn(LD_DIR, "Received a consensus diff, but we can't find " @@ -2622,7 +2627,8 @@ handle_response_fetch_consensus(dir_connection_t *conn, return -1; } - new_consensus = consensus_diff_apply(consensus_body, body); + new_consensus = consensus_diff_apply(consensus_body, consensus_body_len, + body, body_len); tor_free(owned_consensus); if (new_consensus == NULL) { log_warn(LD_DIR, "Could not apply consensus diff received from server " |