aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNick Mathewson <nickm@torproject.org>2004-09-08 06:47:33 +0000
committerNick Mathewson <nickm@torproject.org>2004-09-08 06:47:33 +0000
commitb6798866d058cd7ce69fc3c7944aff85a1693170 (patch)
treec640f4842163dcbc7e22065753c29de65a489168
parent6b9e27f0370f4d37a3aa956fecd01c7d3e9659a1 (diff)
downloadtor-b6798866d058cd7ce69fc3c7944aff85a1693170.tar
tor-b6798866d058cd7ce69fc3c7944aff85a1693170.tar.gz
Idiot-proof uncompress; make sure it always nul-terminates its output. Also, make all compression methods nonzero.
svn:r2334
-rw-r--r--src/common/torgzip.c7
-rw-r--r--src/common/torgzip.h2
2 files changed, 6 insertions, 3 deletions
diff --git a/src/common/torgzip.c b/src/common/torgzip.c
index 1b3fce2e8..b64d5f60f 100644
--- a/src/common/torgzip.c
+++ b/src/common/torgzip.c
@@ -10,7 +10,6 @@
#include "orconfig.h"
-
#include <stdlib.h>
#include <stdio.h>
#include <assert.h>
@@ -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:"<no message>");
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) {
diff --git a/src/common/torgzip.h b/src/common/torgzip.h
index 61bb6adbc..6c88f6927 100644
--- a/src/common/torgzip.h
+++ b/src/common/torgzip.h
@@ -10,7 +10,7 @@
#ifndef __TORGZIP_H
#define __TORGZIP_H
-typedef enum { GZIP_METHOD, ZLIB_METHOD } compress_method_t;
+typedef enum { GZIP_METHOD=1, ZLIB_METHOD=2 } compress_method_t;
int
tor_gzip_compress(char **out, size_t *out_len,