diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/common/compat.c | 2 | ||||
-rw-r--r-- | src/common/compress_zstd.c | 29 | ||||
-rw-r--r-- | src/common/sandbox.c | 8 | ||||
-rw-r--r-- | src/common/util.c | 16 | ||||
-rw-r--r-- | src/common/util_bug.h | 13 | ||||
-rw-r--r-- | src/or/config.c | 1 | ||||
-rw-r--r-- | src/or/consdiffmgr.c | 13 | ||||
-rw-r--r-- | src/or/or.h | 5 | ||||
-rw-r--r-- | src/rust/tor_util/include.am | 2 | ||||
-rw-r--r-- | src/test/test_crypto_slow.c | 3 | ||||
-rw-r--r-- | src/test/test_link_handshake.c | 4 | ||||
-rwxr-xr-x | src/test/test_rust.sh | 2 |
12 files changed, 86 insertions, 12 deletions
diff --git a/src/common/compat.c b/src/common/compat.c index 3bea626903..4d110aba35 100644 --- a/src/common/compat.c +++ b/src/common/compat.c @@ -3261,7 +3261,7 @@ format_win32_error(DWORD err) FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, NULL, err, - MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), + MAKELANGID(LANG_ENGLISH, SUBLANG_DEFAULT), (LPVOID)&str, 0, NULL); diff --git a/src/common/compress_zstd.c b/src/common/compress_zstd.c index a136db48bf..94974dec06 100644 --- a/src/common/compress_zstd.c +++ b/src/common/compress_zstd.c @@ -98,6 +98,8 @@ struct tor_zstd_compress_state_t { #endif // HAVE_ZSTD. int compress; /**< True if we are compressing; false if we are inflating */ + int have_called_end; /**< True if we are compressing and we've called + * ZSTD_endStream */ /** Number of bytes read so far. Used to detect compression bombs. */ size_t input_so_far; @@ -270,9 +272,16 @@ tor_zstd_compress_process(tor_zstd_compress_state_t *state, ZSTD_inBuffer input = { *in, *in_len, 0 }; ZSTD_outBuffer output = { *out, *out_len, 0 }; + if (BUG(finish == 0 && state->have_called_end)) { + finish = 1; + } + if (state->compress) { - retval = ZSTD_compressStream(state->u.compress_stream, - &output, &input); + if (! state->have_called_end) + retval = ZSTD_compressStream(state->u.compress_stream, + &output, &input); + else + retval = 0; } else { retval = ZSTD_decompressStream(state->u.decompress_stream, &output, &input); @@ -300,7 +309,7 @@ tor_zstd_compress_process(tor_zstd_compress_state_t *state, return TOR_COMPRESS_ERROR; } - if (state->compress && !finish) { + if (state->compress && !state->have_called_end) { retval = ZSTD_flushStream(state->u.compress_stream, &output); *out = (char *)output.dst + output.pos; @@ -314,16 +323,24 @@ tor_zstd_compress_process(tor_zstd_compress_state_t *state, // ZSTD_flushStream returns 0 if the frame is done, or >0 if it // is incomplete. - if (retval > 0) + if (retval > 0) { return TOR_COMPRESS_BUFFER_FULL; + } } if (!finish) { - // We're not done with the input, so no need to flush. + // The caller says we're not done with the input, so no need to write an + // epilogue. return TOR_COMPRESS_OK; } else if (state->compress) { - retval = ZSTD_endStream(state->u.compress_stream, &output); + if (*in_len) { + // We say that we're not done with the input, so we can't write an + // epilogue. + return TOR_COMPRESS_OK; + } + retval = ZSTD_endStream(state->u.compress_stream, &output); + state->have_called_end = 1; *out = (char *)output.dst + output.pos; *out_len = output.size - output.pos; diff --git a/src/common/sandbox.c b/src/common/sandbox.c index 52caa4fcc6..5063717355 100644 --- a/src/common/sandbox.c +++ b/src/common/sandbox.c @@ -734,6 +734,14 @@ sb_setsockopt(scmp_filter_ctx ctx, sandbox_cfg_t *filter) return rc; #endif +#ifdef IPV6_V6ONLY + rc = seccomp_rule_add_2(ctx, SCMP_ACT_ALLOW, SCMP_SYS(setsockopt), + SCMP_CMP(1, SCMP_CMP_EQ, IPPROTO_IPV6), + SCMP_CMP(2, SCMP_CMP_EQ, IPV6_V6ONLY)); + if (rc) + return rc; +#endif + return 0; } diff --git a/src/common/util.c b/src/common/util.c index f53a99533b..5b47028097 100644 --- a/src/common/util.c +++ b/src/common/util.c @@ -5608,6 +5608,18 @@ clamp_double_to_int64(double number) #define PROBLEMATIC_FLOAT_CONVERSION_WARNING DISABLE_GCC_WARNING(float-conversion) #endif + +/* + With clang 4.0 we apparently run into "double promotion" warnings here, + since clang thinks we're promoting a double to a long double. + */ +#if defined(__clang__) +#if __has_warning("-Wdouble-promotion") +#define PROBLEMATIC_DOUBLE_PROMOTION_WARNING +DISABLE_GCC_WARNING(double-promotion) +#endif +#endif + /* NaN is a special case that can't be used with the logic below. */ if (isnan(number)) { return 0; @@ -5633,6 +5645,10 @@ DISABLE_GCC_WARNING(float-conversion) /* Handle infinities and finite numbers with magnitude >= 2^63. */ return signbit(number) ? INT64_MIN : INT64_MAX; + +#ifdef PROBLEMATIC_DOUBLE_PROMOTION_WARNING +ENABLE_GCC_WARNING(double-promotion) +#endif #ifdef PROBLEMATIC_FLOAT_CONVERSION_WARNING ENABLE_GCC_WARNING(float-conversion) #endif diff --git a/src/common/util_bug.h b/src/common/util_bug.h index 7879f880ec..ae7e7a37fd 100644 --- a/src/common/util_bug.h +++ b/src/common/util_bug.h @@ -58,6 +58,19 @@ * return -1; */ +#ifdef __COVERITY__ +#undef BUG +// Coverity defines this in global headers; let's override it. This is a +// magic coverity-only preprocessor thing. +#nodef BUG(x) ((x)?(__coverity_panic__(),1):0) +#endif + +#if defined(__COVERITY__) || defined(__clang_analyzer__) +// We're running with a static analysis tool: let's treat even nonfatal +// assertion failures as something that we need to avoid. +#define ALL_BUGS_ARE_FATAL +#endif + #ifdef ALL_BUGS_ARE_FATAL #define tor_assert_nonfatal_unreached() tor_assert(0) #define tor_assert_nonfatal(cond) tor_assert((cond)) diff --git a/src/or/config.c b/src/or/config.c index 7d2ebbdd03..a0ff0e871a 100644 --- a/src/or/config.c +++ b/src/or/config.c @@ -393,6 +393,7 @@ static config_var_t option_vars_[] = { V(MaxAdvertisedBandwidth, MEMUNIT, "1 GB"), V(MaxCircuitDirtiness, INTERVAL, "10 minutes"), V(MaxClientCircuitsPending, UINT, "32"), + V(MaxConsensusAgeForDiffs, INTERVAL, "0 seconds"), VAR("MaxMemInQueues", MEMUNIT, MaxMemInQueues_raw, "0"), OBSOLETE("MaxOnionsPending"), V(MaxOnionQueueDelay, MSEC_INTERVAL, "1750 msec"), diff --git a/src/or/consdiffmgr.c b/src/or/consdiffmgr.c index 8d0a0af3d5..67a5d0b3c5 100644 --- a/src/or/consdiffmgr.c +++ b/src/or/consdiffmgr.c @@ -14,6 +14,7 @@ #define CONSDIFFMGR_PRIVATE #include "or.h" +#include "config.h" #include "conscache.h" #include "consdiff.h" #include "consdiffmgr.h" @@ -462,12 +463,22 @@ cdm_cache_lookup_consensus(consensus_flavor_t flavor, time_t valid_after) static int32_t get_max_age_to_cache(void) { - /* The parameter is in hours. */ const int32_t DEFAULT_MAX_AGE_TO_CACHE = 8192; const int32_t MIN_MAX_AGE_TO_CACHE = 0; const int32_t MAX_MAX_AGE_TO_CACHE = 8192; const char MAX_AGE_TO_CACHE_NAME[] = "max-consensus-age-to-cache-for-diff"; + const or_options_t *options = get_options(); + + if (options->MaxConsensusAgeForDiffs) { + const int v = options->MaxConsensusAgeForDiffs; + if (v >= MAX_MAX_AGE_TO_CACHE * 3600) + return MAX_MAX_AGE_TO_CACHE; + else + return v; + } + + /* The parameter is in hours, so we multiply */ return 3600 * networkstatus_get_param(NULL, MAX_AGE_TO_CACHE_NAME, DEFAULT_MAX_AGE_TO_CACHE, diff --git a/src/or/or.h b/src/or/or.h index 1f55b55062..77207bc031 100644 --- a/src/or/or.h +++ b/src/or/or.h @@ -4558,6 +4558,11 @@ typedef struct { /** Bool (default: 0): Tells if a %include was used on torrc */ int IncludeUsed; + + /** The seconds after expiration which we as a relay should keep old + * consensuses around so that we can generate diffs from them. If 0, + * use the default. */ + int MaxConsensusAgeForDiffs; } or_options_t; /** Persistent state for an onion router, as saved to disk. */ diff --git a/src/rust/tor_util/include.am b/src/rust/tor_util/include.am index 17a755fe09..f0cd63920c 100644 --- a/src/rust/tor_util/include.am +++ b/src/rust/tor_util/include.am @@ -7,7 +7,7 @@ EXTRA_DIST +=\ src/rust/target/release/libtor_util.a: FORCE ( cd "$(abs_top_srcdir)/src/rust/tor_util" ; \ CARGO_TARGET_DIR="$(abs_top_builddir)/src/rust/target" \ - HOME="$(abs_top_builddir)/src/rust" \ + CARGO_HOME="$(abs_top_builddir)/src/rust" \ $(CARGO) build --release --quiet $(CARGO_ONLINE) ) FORCE: diff --git a/src/test/test_crypto_slow.c b/src/test/test_crypto_slow.c index 6d676ff9b9..75c6ba9aaa 100644 --- a/src/test/test_crypto_slow.c +++ b/src/test/test_crypto_slow.c @@ -137,7 +137,8 @@ test_libscrypt_eq_openssl(void *arg) uint8_t buf1[64]; uint8_t buf2[64]; - uint64_t N, r, p; + uint64_t N; + uint32_t r, p; uint64_t maxmem = 0; // --> SCRYPT_MAX_MEM in OpenSSL. int libscrypt_retval, openssl_retval; diff --git a/src/test/test_link_handshake.c b/src/test/test_link_handshake.c index 99f47c0344..c5508b0f04 100644 --- a/src/test/test_link_handshake.c +++ b/src/test/test_link_handshake.c @@ -234,6 +234,7 @@ test_link_handshake_certs_ok(void *arg) } channel_tls_process_certs_cell(cell2, chan1); mock_peer_cert_expect_tortls = NULL; + tor_x509_cert_free(mock_peer_cert); mock_peer_cert = NULL; tor_assert(c1->handshake_state->authenticated); @@ -297,7 +298,8 @@ test_link_handshake_certs_ok(void *arg) UNMOCK(tor_tls_get_peer_cert); UNMOCK(tor_tls_get_own_cert); tor_x509_cert_free(mock_own_cert); - mock_own_cert = NULL; + tor_x509_cert_free(mock_peer_cert); + mock_own_cert = mock_peer_cert = NULL; memset(c1->identity_digest, 0, sizeof(c1->identity_digest)); memset(c2->identity_digest, 0, sizeof(c2->identity_digest)); connection_free_(TO_CONN(c1)); diff --git a/src/test/test_rust.sh b/src/test/test_rust.sh index 4427c70f13..d559f94ce0 100755 --- a/src/test/test_rust.sh +++ b/src/test/test_rust.sh @@ -7,7 +7,7 @@ exitcode=0 for crate in $crates; do cd "${abs_top_srcdir:-.}/src/rust/${crate}" - CARGO_TARGET_DIR="${abs_top_builddir}/src/rust/target" HOME="${abs_top_builddir}/src/rust" "${CARGO:-cargo}" test ${CARGO_ONLINE-"--frozen"} || exitcode=1 + CARGO_TARGET_DIR="${abs_top_builddir}/src/rust/target" CARGO_HOME="${abs_top_builddir}/src/rust" "${CARGO:-cargo}" test ${CARGO_ONLINE-"--frozen"} || exitcode=1 done exit $exitcode |