summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNick Mathewson <nickm@torproject.org>2017-08-08 10:10:52 -0400
committerNick Mathewson <nickm@torproject.org>2017-08-08 10:10:52 -0400
commitcbcff6759d98928d9d252aaf6268f2f679f8b00e (patch)
tree341e3381a1e8d3da3cf3eca203c67e8d2796402a
parentf248a4a38ee74663a1223dc2f1d083d50dc1f18d (diff)
parent5368eaf62b2b4804e75fc301757f843d64ef941d (diff)
downloadtor-cbcff6759d98928d9d252aaf6268f2f679f8b00e.tar.gz
tor-cbcff6759d98928d9d252aaf6268f2f679f8b00e.zip
Merge branch 'maint-0.3.1' into release-0.3.1
-rw-r--r--changes/bug222863
-rw-r--r--src/common/compress.h2
-rw-r--r--src/common/compress_lzma.c10
-rw-r--r--src/common/compress_zstd.c16
-rw-r--r--src/test/test_util.c7
5 files changed, 33 insertions, 5 deletions
diff --git a/changes/bug22286 b/changes/bug22286
new file mode 100644
index 0000000000..f72e8fe2c7
--- /dev/null
+++ b/changes/bug22286
@@ -0,0 +1,3 @@
+ o Minor features (tests):
+ - Add a couple more tests for compression backend initialization.
+ Closes ticket 22286.
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..d453d9f718 100644
--- a/src/common/compress_lzma.c
+++ b/src/common/compress_lzma.c
@@ -144,9 +144,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 +159,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 +191,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 +213,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;
diff --git a/src/common/compress_zstd.c b/src/common/compress_zstd.c
index 94974dec06..0808bcd9ab 100644
--- a/src/common/compress_zstd.c
+++ b/src/common/compress_zstd.c
@@ -196,31 +196,41 @@ tor_zstd_compress_new(int compress,
result->u.compress_stream = ZSTD_createCStream();
if (result->u.compress_stream == NULL) {
- log_warn(LD_GENERAL, "Error while creating Zstandard stream");
+ // LCOV_EXCL_START
+ log_warn(LD_GENERAL, "Error while creating Zstandard compression "
+ "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) {
- log_warn(LD_GENERAL, "Error while creating Zstandard stream");
+ // LCOV_EXCL_START
+ log_warn(LD_GENERAL, "Error while creating Zstandard decompression "
+ "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 +238,7 @@ tor_zstd_compress_new(int compress,
return result;
err:
+ // LCOV_EXCL_START
if (compress) {
ZSTD_freeCStream(result->u.compress_stream);
} else {
@@ -236,6 +247,7 @@ tor_zstd_compress_new(int compress,
tor_free(result);
return NULL;
+ // LCOV_EXCL_STOP
#else // HAVE_ZSTD.
(void)compress;
(void)method;
diff --git a/src/test/test_util.c b/src/test/test_util.c
index 7db93324d1..c6c0f1cd6a 100644
--- a/src/test/test_util.c
+++ b/src/test/test_util.c
@@ -2250,6 +2250,11 @@ test_util_compress_impl(compress_method_t method)
tt_assert(tor_compress_supports_method(method));
+ if (method != NO_METHOD) {
+ tt_assert(tor_compress_version_str(method) != NULL);
+ tt_assert(tor_compress_header_version_str(method) != NULL);
+ }
+
buf1 = tor_strdup("AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAZAAAAAAAAAAAAAAAAAAAZ");
tt_assert(detect_compression_method(buf1, strlen(buf1)) == UNKNOWN_METHOD);
@@ -2353,6 +2358,8 @@ test_util_compress_stream_impl(compress_method_t method,
tt_assert(cp1 > cp2); /* Make sure we really added something. */
}
+ tt_int_op(tor_compress_state_size(state), OP_GT, 0);
+
tt_assert(!tor_uncompress(&buf3, &len2, buf1, 1024-len1,
method, 1, LOG_WARN));
/* Make sure it compressed right. */