]> git.ipfire.org Git - thirdparty/tor.git/commitdiff
Idiot-proof uncompress; make sure it always nul-terminates its output. Also, make...
authorNick Mathewson <nickm@torproject.org>
Wed, 8 Sep 2004 06:47:33 +0000 (06:47 +0000)
committerNick Mathewson <nickm@torproject.org>
Wed, 8 Sep 2004 06:47:33 +0000 (06:47 +0000)
svn:r2334

src/common/torgzip.c
src/common/torgzip.h

index 1b3fce2e8839addcc491e92133e856685609035e..b64d5f60f1b0cd529194c9f046bf24fefb21aefe 100644 (file)
@@ -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) {
index 61bb6adbcf94fb6fb92df4c9b5ad6ee3d6dc6b89..6c88f69275b6cb580299596688ed7732ec859369 100644 (file)
@@ -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,