From b6798866d058cd7ce69fc3c7944aff85a1693170 Mon Sep 17 00:00:00 2001 From: Nick Mathewson Date: Wed, 8 Sep 2004 06:47:33 +0000 Subject: Idiot-proof uncompress; make sure it always nul-terminates its output. Also, make all compression methods nonzero. svn:r2334 --- src/common/torgzip.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'src/common/torgzip.c') diff --git a/src/common/torgzip.c b/src/common/torgzip.c index 1b3fce2e88..b64d5f60f1 100644 --- a/src/common/torgzip.c +++ b/src/common/torgzip.c @@ -10,7 +10,6 @@ #include "orconfig.h" - #include #include #include @@ -74,7 +73,6 @@ tor_gzip_compress(char **out, size_t *out_len, if (deflateInit2(stream, Z_BEST_COMPRESSION, Z_DEFLATED, method_bits(method), 8, Z_DEFAULT_STRATEGY) != Z_OK) { - printf("Z"); log_fn(LOG_WARN, "Error from deflateInit2: %s", stream->msg?stream->msg:""); goto err; @@ -200,6 +198,11 @@ tor_gzip_uncompress(char **out, size_t *out_len, } tor_free(stream); + /* NUL-terminate output. */ + if (out_size == *out_len) + *out = tor_realloc(*out, out_size + 1); + (*out)[*out_len] = '\0'; + return 0; err: if (stream) { -- cgit v1.2.3-54-g00ecf