summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/or/directory.c28
-rw-r--r--src/or/test.c3
2 files changed, 19 insertions, 12 deletions
diff --git a/src/or/directory.c b/src/or/directory.c
index 881c85e20a..4aedbf8b6f 100644
--- a/src/or/directory.c
+++ b/src/or/directory.c
@@ -48,7 +48,7 @@ directory_send_command(connection_t *conn, const char *platform,
int purpose, const char *resource,
const char *payload, size_t payload_len);
static int directory_handle_command(connection_t *conn);
-static int body_is_plausible(const char *body, size_t body_len);
+static int body_is_plausible(const char *body, size_t body_len, int purpose);
/********* START VARIABLES **********/
@@ -552,21 +552,25 @@ parse_http_response(const char *headers, int *code, time_t *date,
* running-list or directory opening. This is a sign of possible compression.
**/
static int
-body_is_plausible(const char *body, size_t len)
+body_is_plausible(const char *body, size_t len, int purpose)
{
int i;
if (len < 32)
return 0;
- if (!strcmpstart(body,"router") ||
- !strcmpstart(body,"signed-directory") ||
- !strcmpstart(body,"network-status") ||
- !strcmpstart(body,"running-routers"))
+ if (purpose != DIR_PURPOSE_FETCH_RENDDESC) {
+ if (!strcmpstart(body,"router") ||
+ !strcmpstart(body,"signed-directory") ||
+ !strcmpstart(body,"network-status") ||
+ !strcmpstart(body,"running-routers"))
+ return 1;
+ for (i=0;i<32;++i) {
+ if (!isprint(body[i]) && !isspace(body[i]))
+ return 0;
+ }
+ return 1;
+ } else {
return 1;
- for (i=0;i<32;++i) {
- if (!isprint(body[i]) && !isspace(body[i]))
- return 0;
}
- return 1;
}
/** We are a client, and we've finished reading the server's
@@ -618,7 +622,7 @@ connection_dir_client_reached_eof(connection_t *conn)
}
}
- plausible = body_is_plausible(body, body_len);
+ plausible = body_is_plausible(body, body_len, conn->purpose);
if (compression || !plausible) {
char *new_body = NULL;
size_t new_len = 0;
@@ -628,7 +632,7 @@ connection_dir_client_reached_eof(connection_t *conn)
const char *description1, *description2;
if (compression == ZLIB_METHOD)
description1 = "as deflated";
- else if (compression = GZIP_METHOD)
+ else if (compression == GZIP_METHOD)
description1 = "as gzipped";
else if (compression == 0)
description1 = "as uncompressed";
diff --git a/src/or/test.c b/src/or/test.c
index c2538fb157..632968ba2a 100644
--- a/src/or/test.c
+++ b/src/or/test.c
@@ -802,11 +802,13 @@ test_gzip(void)
size_t len1, len2;
buf1 = tor_strdup("AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA");
+ test_eq(detect_compression_method(buf1, strlen(buf1)), 0);
if (is_gzip_supported()) {
test_assert(!tor_gzip_compress(&buf2, &len1, buf1, strlen(buf1)+1,
GZIP_METHOD));
test_assert(buf2);
test_assert(!memcmp(buf2, "\037\213", 2)); /* Gzip magic. */
+ test_eq(detect_compression_method(buf2, strlen(buf1)), GZIP_METHOD);
test_assert(!tor_gzip_uncompress(&buf3, &len2, buf2, len1, GZIP_METHOD));
test_assert(buf3);
@@ -820,6 +822,7 @@ test_gzip(void)
ZLIB_METHOD));
test_assert(buf2);
test_assert(!memcmp(buf2, "\x78\xDA", 2)); /* deflate magic. */
+ test_eq(detect_compression_method(buf2, strlen(buf1)), ZLIB_METHOD);
test_assert(!tor_gzip_uncompress(&buf3, &len2, buf2, len1, ZLIB_METHOD));
test_assert(buf3);