summaryrefslogtreecommitdiff
path: root/src/common/compress.c
diff options
context:
space:
mode:
authorAlexander Færøy <ahf@torproject.org>2017-09-28 16:46:10 +0200
committerAlexander Færøy <ahf@torproject.org>2017-09-28 18:58:15 +0200
commit44dc4b73ec89a4bc442f602f58ad84f5fec5f380 (patch)
tree07a937b17f3a450ecf8c8a51bbaf3adb7205a5e5 /src/common/compress.c
parentc3b7f9d762a8c0245d7df952840412e890245c23 (diff)
downloadtor-44dc4b73ec89a4bc442f602f58ad84f5fec5f380.tar.gz
tor-44dc4b73ec89a4bc442f602f58ad84f5fec5f380.zip
Better error handling when trying to compress/decompress into empty buffer.
This patch ensures that we return TOR_COMPRESS_BUFFER_FULL in case we have a input bytes left to process, but are out of output buffer or in case we need to finish where the compression implementation might need to write an epilogue. See: https://bugs.torproject.org/23551
Diffstat (limited to 'src/common/compress.c')
-rw-r--r--src/common/compress.c7
1 files changed, 7 insertions, 0 deletions
diff --git a/src/common/compress.c b/src/common/compress.c
index 7de3a683a3..bc12a58ad6 100644
--- a/src/common/compress.c
+++ b/src/common/compress.c
@@ -547,6 +547,13 @@ tor_compress_process(tor_compress_state_t *state,
const size_t out_len_orig = *out_len;
tor_compress_output_t rv;
+ if (*out_len == 0 && (*in_len > 0 || finish)) {
+ // If we still have input data, but no space for output data, we might as
+ // well return early and let the caller do the reallocation of the out
+ // variable.
+ return TOR_COMPRESS_BUFFER_FULL;
+ }
+
switch (state->method) {
case GZIP_METHOD:
case ZLIB_METHOD: