summaryrefslogtreecommitdiff
path: root/src/common
diff options
context:
space:
mode:
authorNick Mathewson <nickm@torproject.org>2017-06-20 12:26:57 -0400
committerNick Mathewson <nickm@torproject.org>2017-06-20 12:26:57 -0400
commit9328bd524e38befe240fd729a9febb4dfe8b5be4 (patch)
tree93510123bf30cf23af636cb7f9c4a62b7e84970d /src/common
parent945256188ab3a9b5842455f714d51e1871b0bf69 (diff)
downloadtor-9328bd524e38befe240fd729a9febb4dfe8b5be4.tar.gz
tor-9328bd524e38befe240fd729a9febb4dfe8b5be4.zip
Enforce the rule that COMPRESS_OK means progress was made.
If COMPRESS_OK occurs but data is neither consumed nor generated, treat it as a BUG and a COMPRESS_ERROR. This change is meant to prevent infinite loops in the case where we've made a mistake in one of our compression backends. Closes ticket 22672.
Diffstat (limited to 'src/common')
-rw-r--r--src/common/compress.c36
1 files changed, 25 insertions, 11 deletions
diff --git a/src/common/compress.c b/src/common/compress.c
index c16d1b51ee..46aa1d52ba 100644
--- a/src/common/compress.c
+++ b/src/common/compress.c
@@ -548,28 +548,42 @@ tor_compress_process(tor_compress_state_t *state,
int finish)
{
tor_assert(state != NULL);
+ const size_t in_len_orig = *in_len;
+ const size_t out_len_orig = *out_len;
+ tor_compress_output_t rv;
switch (state->method) {
case GZIP_METHOD:
case ZLIB_METHOD:
- return tor_zlib_compress_process(state->u.zlib_state,
- out, out_len, in, in_len,
- finish);
+ rv = tor_zlib_compress_process(state->u.zlib_state,
+ out, out_len, in, in_len,
+ finish);
+ break;
case LZMA_METHOD:
- return tor_lzma_compress_process(state->u.lzma_state,
- out, out_len, in, in_len,
- finish);
+ rv =tor_lzma_compress_process(state->u.lzma_state,
+ out, out_len, in, in_len,
+ finish);
+ break;
case ZSTD_METHOD:
- return tor_zstd_compress_process(state->u.zstd_state,
- out, out_len, in, in_len,
- finish);
+ rv = tor_zstd_compress_process(state->u.zstd_state,
+ out, out_len, in, in_len,
+ finish);
+ break;
case NO_METHOD:
- return tor_cnone_compress_process(out, out_len, in, in_len,
- finish);
+ rv = tor_cnone_compress_process(out, out_len, in, in_len,
+ finish);
+ break;
+ default:
case UNKNOWN_METHOD:
goto err;
}
+ if (BUG((rv == TOR_COMPRESS_OK) &&
+ *in_len == in_len_orig &&
+ *out_len == out_len_orig)) {
+ return TOR_COMPRESS_ERROR;
+ }
+ return rv;
err:
return TOR_COMPRESS_ERROR;
}