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 **********/
* 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
}
}
- 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;
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";
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);
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);