mirror of
https://gitlab.torproject.org/tpo/core/tor.git
synced 2024-11-11 05:33:47 +01:00
Fix remaining cases of using consensus without a len parameter.
(Thanks to cyberpunks for noting two of them!)
This commit is contained in:
parent
81a5448c18
commit
594140574e
@ -189,6 +189,7 @@ static consdiff_cfg_t consdiff_cfg = {
|
|||||||
|
|
||||||
static int consdiffmgr_ensure_space_for_files(int n);
|
static int consdiffmgr_ensure_space_for_files(int n);
|
||||||
static int consensus_queue_compression_work(const char *consensus,
|
static int consensus_queue_compression_work(const char *consensus,
|
||||||
|
size_t consensus_len,
|
||||||
const networkstatus_t *as_parsed);
|
const networkstatus_t *as_parsed);
|
||||||
static int consensus_diff_queue_diff_work(consensus_cache_entry_t *diff_from,
|
static int consensus_diff_queue_diff_work(consensus_cache_entry_t *diff_from,
|
||||||
consensus_cache_entry_t *diff_to);
|
consensus_cache_entry_t *diff_to);
|
||||||
@ -509,8 +510,25 @@ get_max_age_to_cache(void)
|
|||||||
MAX_MAX_AGE_TO_CACHE);
|
MAX_MAX_AGE_TO_CACHE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef TOR_UNIT_TESTS
|
||||||
|
/** As consdiffmgr_add_consensus, but requires a nul-terminated input. For
|
||||||
|
* testing. */
|
||||||
|
int
|
||||||
|
consdiffmgr_add_consensus_nulterm(const char *consensus,
|
||||||
|
const networkstatus_t *as_parsed)
|
||||||
|
{
|
||||||
|
size_t len = strlen(consensus);
|
||||||
|
/* make a non-nul-terminated copy so that we can have a better chance
|
||||||
|
* of catching errors. */
|
||||||
|
char *ctmp = tor_memdup(consensus, len);
|
||||||
|
int r = consdiffmgr_add_consensus(ctmp, len, as_parsed);
|
||||||
|
tor_free(ctmp);
|
||||||
|
return r;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Given a string containing a networkstatus consensus, and the results of
|
* Given a buffer containing a networkstatus consensus, and the results of
|
||||||
* having parsed that consensus, add that consensus to the cache if it is not
|
* having parsed that consensus, add that consensus to the cache if it is not
|
||||||
* already present and not too old. Create new consensus diffs from or to
|
* already present and not too old. Create new consensus diffs from or to
|
||||||
* that consensus as appropriate.
|
* that consensus as appropriate.
|
||||||
@ -519,6 +537,7 @@ get_max_age_to_cache(void)
|
|||||||
*/
|
*/
|
||||||
int
|
int
|
||||||
consdiffmgr_add_consensus(const char *consensus,
|
consdiffmgr_add_consensus(const char *consensus,
|
||||||
|
size_t consensus_len,
|
||||||
const networkstatus_t *as_parsed)
|
const networkstatus_t *as_parsed)
|
||||||
{
|
{
|
||||||
if (BUG(consensus == NULL) || BUG(as_parsed == NULL))
|
if (BUG(consensus == NULL) || BUG(as_parsed == NULL))
|
||||||
@ -544,7 +563,7 @@ consdiffmgr_add_consensus(const char *consensus,
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* We don't have it. Add it to the cache. */
|
/* We don't have it. Add it to the cache. */
|
||||||
return consensus_queue_compression_work(consensus, as_parsed);
|
return consensus_queue_compression_work(consensus, consensus_len, as_parsed);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -1826,14 +1845,15 @@ static int background_compression = 0;
|
|||||||
*/
|
*/
|
||||||
static int
|
static int
|
||||||
consensus_queue_compression_work(const char *consensus,
|
consensus_queue_compression_work(const char *consensus,
|
||||||
|
size_t consensus_len,
|
||||||
const networkstatus_t *as_parsed)
|
const networkstatus_t *as_parsed)
|
||||||
{
|
{
|
||||||
tor_assert(consensus);
|
tor_assert(consensus);
|
||||||
tor_assert(as_parsed);
|
tor_assert(as_parsed);
|
||||||
|
|
||||||
consensus_compress_worker_job_t *job = tor_malloc_zero(sizeof(*job));
|
consensus_compress_worker_job_t *job = tor_malloc_zero(sizeof(*job));
|
||||||
job->consensus = tor_strdup(consensus);
|
job->consensus = tor_memdup_nulterm(consensus, consensus_len);
|
||||||
job->consensus_len = strlen(consensus);
|
job->consensus_len = strlen(job->consensus);
|
||||||
job->flavor = as_parsed->flavor;
|
job->flavor = as_parsed->flavor;
|
||||||
|
|
||||||
char va_str[ISO_TIME_LEN+1];
|
char va_str[ISO_TIME_LEN+1];
|
||||||
|
@ -22,6 +22,7 @@ typedef struct consdiff_cfg_t {
|
|||||||
struct consensus_cache_entry_t; // from conscache.h
|
struct consensus_cache_entry_t; // from conscache.h
|
||||||
|
|
||||||
int consdiffmgr_add_consensus(const char *consensus,
|
int consdiffmgr_add_consensus(const char *consensus,
|
||||||
|
size_t consensus_len,
|
||||||
const networkstatus_t *as_parsed);
|
const networkstatus_t *as_parsed);
|
||||||
|
|
||||||
consdiff_status_t consdiffmgr_find_consensus(
|
consdiff_status_t consdiffmgr_find_consensus(
|
||||||
@ -73,4 +74,9 @@ STATIC int uncompress_or_set_ptr(const char **out, size_t *outlen,
|
|||||||
consensus_cache_entry_t *ent);
|
consensus_cache_entry_t *ent);
|
||||||
#endif /* defined(CONSDIFFMGR_PRIVATE) */
|
#endif /* defined(CONSDIFFMGR_PRIVATE) */
|
||||||
|
|
||||||
|
#ifdef TOR_UNIT_TESTS
|
||||||
|
int consdiffmgr_add_consensus_nulterm(const char *consensus,
|
||||||
|
const networkstatus_t *as_parsed);
|
||||||
|
#endif
|
||||||
|
|
||||||
#endif /* !defined(TOR_CONSDIFFMGR_H) */
|
#endif /* !defined(TOR_CONSDIFFMGR_H) */
|
||||||
|
@ -1272,6 +1272,7 @@ free_cached_dir_(void *_d)
|
|||||||
* validation is performed. */
|
* validation is performed. */
|
||||||
void
|
void
|
||||||
dirserv_set_cached_consensus_networkstatus(const char *networkstatus,
|
dirserv_set_cached_consensus_networkstatus(const char *networkstatus,
|
||||||
|
size_t networkstatus_len,
|
||||||
const char *flavor_name,
|
const char *flavor_name,
|
||||||
const common_digests_t *digests,
|
const common_digests_t *digests,
|
||||||
const uint8_t *sha3_as_signed,
|
const uint8_t *sha3_as_signed,
|
||||||
@ -1282,7 +1283,9 @@ dirserv_set_cached_consensus_networkstatus(const char *networkstatus,
|
|||||||
if (!cached_consensuses)
|
if (!cached_consensuses)
|
||||||
cached_consensuses = strmap_new();
|
cached_consensuses = strmap_new();
|
||||||
|
|
||||||
new_networkstatus = new_cached_dir(tor_strdup(networkstatus), published);
|
new_networkstatus =
|
||||||
|
new_cached_dir(tor_memdup_nulterm(networkstatus, networkstatus_len),
|
||||||
|
published);
|
||||||
memcpy(&new_networkstatus->digests, digests, sizeof(common_digests_t));
|
memcpy(&new_networkstatus->digests, digests, sizeof(common_digests_t));
|
||||||
memcpy(&new_networkstatus->digest_sha3_as_signed, sha3_as_signed,
|
memcpy(&new_networkstatus->digest_sha3_as_signed, sha3_as_signed,
|
||||||
DIGEST256_LEN);
|
DIGEST256_LEN);
|
||||||
|
@ -148,6 +148,7 @@ int directory_too_idle_to_fetch_descriptors(const or_options_t *options,
|
|||||||
|
|
||||||
cached_dir_t *dirserv_get_consensus(const char *flavor_name);
|
cached_dir_t *dirserv_get_consensus(const char *flavor_name);
|
||||||
void dirserv_set_cached_consensus_networkstatus(const char *consensus,
|
void dirserv_set_cached_consensus_networkstatus(const char *consensus,
|
||||||
|
size_t consensus_len,
|
||||||
const char *flavor_name,
|
const char *flavor_name,
|
||||||
const common_digests_t *digests,
|
const common_digests_t *digests,
|
||||||
const uint8_t *sha3_as_signed,
|
const uint8_t *sha3_as_signed,
|
||||||
|
@ -2107,17 +2107,18 @@ networkstatus_set_current_consensus(const char *consensus,
|
|||||||
|
|
||||||
if (we_want_to_fetch_flavor(options, flav)) {
|
if (we_want_to_fetch_flavor(options, flav)) {
|
||||||
dirserv_set_cached_consensus_networkstatus(consensus,
|
dirserv_set_cached_consensus_networkstatus(consensus,
|
||||||
|
consensus_len,
|
||||||
flavor,
|
flavor,
|
||||||
&c->digests,
|
&c->digests,
|
||||||
c->digest_sha3_as_signed,
|
c->digest_sha3_as_signed,
|
||||||
c->valid_after);
|
c->valid_after);
|
||||||
if (dir_server_mode(get_options())) {
|
if (dir_server_mode(get_options())) {
|
||||||
consdiffmgr_add_consensus(consensus, c);
|
consdiffmgr_add_consensus(consensus, consensus_len, c);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!from_cache) {
|
if (!from_cache) {
|
||||||
write_str_to_file(consensus_fname, consensus, 0);
|
write_bytes_to_file(consensus_fname, consensus, consensus_len, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
warn_early_consensus(c, flavor, now);
|
warn_early_consensus(c, flavor, now);
|
||||||
|
@ -21,6 +21,8 @@
|
|||||||
#include "test/test.h"
|
#include "test/test.h"
|
||||||
#include "test/log_test_helpers.h"
|
#include "test/log_test_helpers.h"
|
||||||
|
|
||||||
|
#define consdiffmgr_add_consensus consdiffmgr_add_consensus_nulterm
|
||||||
|
|
||||||
static char *
|
static char *
|
||||||
consensus_diff_apply_(const char *c, const char *d)
|
consensus_diff_apply_(const char *c, const char *d)
|
||||||
{
|
{
|
||||||
|
@ -67,6 +67,8 @@ ENABLE_GCC_WARNING(overlength-strings)
|
|||||||
#define NOT_ENOUGH_CONSENSUS_SIGNATURES "HTTP/1.0 404 " \
|
#define NOT_ENOUGH_CONSENSUS_SIGNATURES "HTTP/1.0 404 " \
|
||||||
"Consensus not signed by sufficient number of requested authorities\r\n\r\n"
|
"Consensus not signed by sufficient number of requested authorities\r\n\r\n"
|
||||||
|
|
||||||
|
#define consdiffmgr_add_consensus consdiffmgr_add_consensus_nulterm
|
||||||
|
|
||||||
static dir_connection_t *
|
static dir_connection_t *
|
||||||
new_dir_conn(void)
|
new_dir_conn(void)
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user