diff options
author | Nick Mathewson <nickm@torproject.org> | 2017-08-08 10:03:08 -0400 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2017-08-08 10:03:08 -0400 |
commit | 6121ca16bc83cf74f0c4bc3f71b3150cd18aa43c (patch) | |
tree | 00814d8a6981e2765f4b711a70d3e8a0e30b7190 /src/common | |
parent | 1168e21b45cb981463fa77a45c2e697bb75d573c (diff) | |
parent | fcf836d239d3545ff02df63d47e1b23b000138e0 (diff) | |
download | tor-6121ca16bc83cf74f0c4bc3f71b3150cd18aa43c.tar.gz tor-6121ca16bc83cf74f0c4bc3f71b3150cd18aa43c.zip |
Merge remote-tracking branch 'ahf/bugs/22286' into maint-0.3.1
Diffstat (limited to 'src/common')
-rw-r--r-- | src/common/compress.h | 2 | ||||
-rw-r--r-- | src/common/compress_lzma.c | 14 | ||||
-rw-r--r-- | src/common/compress_zstd.c | 16 |
3 files changed, 29 insertions, 3 deletions
diff --git a/src/common/compress.h b/src/common/compress.h index 7c0dc14061..59c8b7b9b5 100644 --- a/src/common/compress.h +++ b/src/common/compress.h @@ -49,7 +49,7 @@ int tor_compress_is_compression_bomb(size_t size_in, size_t size_out); int tor_compress_supports_method(compress_method_t method); unsigned tor_compress_get_supported_method_bitmask(void); -const char * compression_method_get_name(compress_method_t method); +const char *compression_method_get_name(compress_method_t method); const char *compression_method_get_human_name(compress_method_t method); compress_method_t compression_method_get_by_name(const char *name); diff --git a/src/common/compress_lzma.c b/src/common/compress_lzma.c index b5393a6ba6..30d5920ca8 100644 --- a/src/common/compress_lzma.c +++ b/src/common/compress_lzma.c @@ -46,6 +46,7 @@ memory_level(compression_level_t level) static const char * lzma_error_str(lzma_ret error) { + // LCOV_EXCL_START switch (error) { case LZMA_OK: return "Operation completed successfully"; @@ -74,6 +75,7 @@ lzma_error_str(lzma_ret error) default: return "Unknown LZMA error"; } + // LCOV_EXCL_STOP } #endif // HAVE_LZMA. @@ -144,9 +146,11 @@ tor_lzma_state_size_precalc(int compress, compression_level_t level) memory_usage = lzma_easy_decoder_memusage(memory_level(level)); if (memory_usage == UINT64_MAX) { + // LCOV_EXCL_START log_warn(LD_GENERAL, "Unsupported compression level passed to LZMA %s", compress ? "encoder" : "decoder"); goto err; + // LCOV_EXCL_STOP } if (memory_usage + sizeof(tor_lzma_compress_state_t) > SIZE_MAX) @@ -157,7 +161,7 @@ tor_lzma_state_size_precalc(int compress, compression_level_t level) return (size_t)memory_usage; err: - return 0; + return 0; // LCOV_EXCL_LINE } #endif // HAVE_LZMA. @@ -189,17 +193,21 @@ tor_lzma_compress_new(int compress, retval = lzma_alone_encoder(&result->stream, &stream_options); if (retval != LZMA_OK) { + // LCOV_EXCL_START log_warn(LD_GENERAL, "Error from LZMA encoder: %s (%u).", lzma_error_str(retval), retval); goto err; + // LCOV_EXCL_STOP } } else { retval = lzma_alone_decoder(&result->stream, MEMORY_LIMIT); if (retval != LZMA_OK) { + // LCOV_EXCL_START log_warn(LD_GENERAL, "Error from LZMA decoder: %s (%u).", lzma_error_str(retval), retval); goto err; + // LCOV_EXCL_STOP } } @@ -207,7 +215,7 @@ tor_lzma_compress_new(int compress, return result; err: - tor_free(result); + tor_free(result); // LCOV_EXCL_LINE return NULL; #else // HAVE_LZMA. (void)compress; @@ -295,10 +303,12 @@ tor_lzma_compress_process(tor_lzma_compress_state_t *state, case LZMA_DATA_ERROR: case LZMA_PROG_ERROR: default: + // LCOV_EXCL_START log_warn(LD_GENERAL, "LZMA %s didn't finish: %s.", state->compress ? "compression" : "decompression", lzma_error_str(retval)); return TOR_COMPRESS_ERROR; + // LCOV_EXCL_STOP } #else // HAVE_LZMA. (void)state; diff --git a/src/common/compress_zstd.c b/src/common/compress_zstd.c index 94974dec06..5c5026c37d 100644 --- a/src/common/compress_zstd.c +++ b/src/common/compress_zstd.c @@ -196,31 +196,39 @@ tor_zstd_compress_new(int compress, result->u.compress_stream = ZSTD_createCStream(); if (result->u.compress_stream == NULL) { + // LCOV_EXCL_START log_warn(LD_GENERAL, "Error while creating Zstandard stream"); goto err; + // LCOV_EXCL_STOP } retval = ZSTD_initCStream(result->u.compress_stream, preset); if (ZSTD_isError(retval)) { + // LCOV_EXCL_START log_warn(LD_GENERAL, "Zstandard stream initialization error: %s", ZSTD_getErrorName(retval)); goto err; + // LCOV_EXCL_STOP } } else { result->u.decompress_stream = ZSTD_createDStream(); if (result->u.decompress_stream == NULL) { + // LCOV_EXCL_START log_warn(LD_GENERAL, "Error while creating Zstandard stream"); goto err; + // LCOV_EXCL_STOP } retval = ZSTD_initDStream(result->u.decompress_stream); if (ZSTD_isError(retval)) { + // LCOV_EXCL_START log_warn(LD_GENERAL, "Zstandard stream initialization error: %s", ZSTD_getErrorName(retval)); goto err; + // LCOV_EXCL_STOP } } @@ -228,6 +236,7 @@ tor_zstd_compress_new(int compress, return result; err: + // LCOV_EXCL_START if (compress) { ZSTD_freeCStream(result->u.compress_stream); } else { @@ -236,6 +245,7 @@ tor_zstd_compress_new(int compress, tor_free(result); return NULL; + // LCOV_EXCL_STOP #else // HAVE_ZSTD. (void)compress; (void)method; @@ -303,10 +313,12 @@ tor_zstd_compress_process(tor_zstd_compress_state_t *state, } if (ZSTD_isError(retval)) { + // LCOV_EXCL_START log_warn(LD_GENERAL, "Zstandard %s didn't finish: %s.", state->compress ? "compression" : "decompression", ZSTD_getErrorName(retval)); return TOR_COMPRESS_ERROR; + // LCOV_EXCL_STOP } if (state->compress && !state->have_called_end) { @@ -316,9 +328,11 @@ tor_zstd_compress_process(tor_zstd_compress_state_t *state, *out_len = output.size - output.pos; if (ZSTD_isError(retval)) { + // LCOV_EXCL_START log_warn(LD_GENERAL, "Zstandard compression unable to flush: %s.", ZSTD_getErrorName(retval)); return TOR_COMPRESS_ERROR; + // LCOV_EXCL_STOP } // ZSTD_flushStream returns 0 if the frame is done, or >0 if it @@ -345,10 +359,12 @@ tor_zstd_compress_process(tor_zstd_compress_state_t *state, *out_len = output.size - output.pos; if (ZSTD_isError(retval)) { + // LCOV_EXCL_START log_warn(LD_GENERAL, "Zstandard compression unable to write " "epilogue: %s.", ZSTD_getErrorName(retval)); return TOR_COMPRESS_ERROR; + // LCOV_EXCL_STOP } // endStream returns the number of bytes that is needed to write the |