[or-cvs] Idiot-proof uncompress; make sure it always nul-terminates ...
Nick Mathewson
nickm at seul.org
Wed Sep 8 06:47:35 UTC 2004
Update of /home/or/cvsroot/src/common
In directory moria.mit.edu:/tmp/cvs-serv28075/src/common
Modified Files:
torgzip.c torgzip.h
Log Message:
Idiot-proof uncompress; make sure it always nul-terminates its output. Also, make all compression methods nonzero.
Index: torgzip.c
===================================================================
RCS file: /home/or/cvsroot/src/common/torgzip.c,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- torgzip.c 2 Sep 2004 18:22:51 -0000 1.1
+++ torgzip.c 8 Sep 2004 06:47:33 -0000 1.2
@@ -10,7 +10,6 @@
#include "orconfig.h"
-
#include <stdlib.h>
#include <stdio.h>
#include <assert.h>
@@ -74,7 +73,6 @@
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_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: torgzip.h
===================================================================
RCS file: /home/or/cvsroot/src/common/torgzip.h,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- torgzip.h 2 Sep 2004 18:22:51 -0000 1.1
+++ torgzip.h 8 Sep 2004 06:47:33 -0000 1.2
@@ -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,
More information about the tor-commits
mailing list