mirror of
https://gitlab.torproject.org/tpo/core/tor.git
synced 2025-02-25 23:21:38 +01:00
Short-circuit the no-decompression-needed case, for clarity
This commit is mostly just deindentation.
This commit is contained in:
parent
c0e9698fca
commit
9018da06c7
1 changed files with 76 additions and 73 deletions
|
@ -2205,88 +2205,91 @@ dir_client_decompress_response_body(char **bodyp, size_t *bodylenp,
|
||||||
conn->base_.purpose == DIR_PURPOSE_FETCH_MICRODESC);
|
conn->base_.purpose == DIR_PURPOSE_FETCH_MICRODESC);
|
||||||
|
|
||||||
int plausible = body_is_plausible(body, body_len, conn->base_.purpose);
|
int plausible = body_is_plausible(body, body_len, conn->base_.purpose);
|
||||||
if (compression != NO_METHOD || !plausible) {
|
|
||||||
int severity = LOG_DEBUG;
|
|
||||||
char *new_body = NULL;
|
|
||||||
size_t new_len = 0;
|
|
||||||
const char *description1, *description2;
|
|
||||||
int want_to_try_both = 0;
|
|
||||||
int tried_both = 0;
|
|
||||||
compress_method_t guessed = detect_compression_method(body, body_len);
|
|
||||||
|
|
||||||
description1 = compression_method_get_human_name(compression);
|
if (plausible && compression == NO_METHOD) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
if (BUG(description1 == NULL))
|
int severity = LOG_DEBUG;
|
||||||
description1 = compression_method_get_human_name(UNKNOWN_METHOD);
|
char *new_body = NULL;
|
||||||
|
size_t new_len = 0;
|
||||||
|
const char *description1, *description2;
|
||||||
|
int want_to_try_both = 0;
|
||||||
|
int tried_both = 0;
|
||||||
|
compress_method_t guessed = detect_compression_method(body, body_len);
|
||||||
|
|
||||||
if (guessed == UNKNOWN_METHOD && !plausible)
|
description1 = compression_method_get_human_name(compression);
|
||||||
description2 = "confusing binary junk";
|
|
||||||
else
|
|
||||||
description2 = compression_method_get_human_name(guessed);
|
|
||||||
|
|
||||||
/* Tell the user if we don't believe what we're told about compression.*/
|
if (BUG(description1 == NULL))
|
||||||
want_to_try_both = (compression == UNKNOWN_METHOD ||
|
description1 = compression_method_get_human_name(UNKNOWN_METHOD);
|
||||||
guessed != compression);
|
|
||||||
if (want_to_try_both) {
|
|
||||||
severity = LOG_INFO;
|
|
||||||
}
|
|
||||||
|
|
||||||
tor_log(severity, LD_HTTP,
|
if (guessed == UNKNOWN_METHOD && !plausible)
|
||||||
"HTTP body from server '%s:%d' was labeled as %s, "
|
description2 = "confusing binary junk";
|
||||||
"%s it seems to be %s.%s",
|
else
|
||||||
conn->base_.address, conn->base_.port, description1,
|
description2 = compression_method_get_human_name(guessed);
|
||||||
guessed != compression?"but":"and",
|
|
||||||
description2,
|
|
||||||
(compression>0 && guessed>0 && want_to_try_both)?
|
|
||||||
" Trying both.":"");
|
|
||||||
|
|
||||||
/* Try declared compression first if we can.
|
/* Tell the user if we don't believe what we're told about compression.*/
|
||||||
* tor_compress_supports_method() also returns true for NO_METHOD.
|
want_to_try_both = (compression == UNKNOWN_METHOD ||
|
||||||
* Ensure that the server is not sending us data compressed using a
|
guessed != compression);
|
||||||
* compression method that is not allowed for anonymous connections. */
|
if (want_to_try_both) {
|
||||||
if (anonymized_connection &&
|
severity = LOG_INFO;
|
||||||
! allowed_anonymous_connection_compression_method(compression)) {
|
}
|
||||||
warn_disallowed_anonymous_compression_method(compression);
|
|
||||||
rv = -1;
|
|
||||||
goto done;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (tor_compress_supports_method(compression))
|
tor_log(severity, LD_HTTP,
|
||||||
tor_uncompress(&new_body, &new_len, body, body_len, compression,
|
"HTTP body from server '%s:%d' was labeled as %s, "
|
||||||
!allow_partial, LOG_PROTOCOL_WARN);
|
"%s it seems to be %s.%s",
|
||||||
|
conn->base_.address, conn->base_.port, description1,
|
||||||
|
guessed != compression?"but":"and",
|
||||||
|
description2,
|
||||||
|
(compression>0 && guessed>0 && want_to_try_both)?
|
||||||
|
" Trying both.":"");
|
||||||
|
|
||||||
/* Okay, if that didn't work, and we think that it was compressed
|
/* Try declared compression first if we can.
|
||||||
* differently, try that. */
|
* tor_compress_supports_method() also returns true for NO_METHOD.
|
||||||
if (anonymized_connection &&
|
* Ensure that the server is not sending us data compressed using a
|
||||||
! allowed_anonymous_connection_compression_method(guessed)) {
|
* compression method that is not allowed for anonymous connections. */
|
||||||
warn_disallowed_anonymous_compression_method(guessed);
|
if (anonymized_connection &&
|
||||||
rv = -1;
|
! allowed_anonymous_connection_compression_method(compression)) {
|
||||||
goto done;
|
warn_disallowed_anonymous_compression_method(compression);
|
||||||
}
|
rv = -1;
|
||||||
|
goto done;
|
||||||
|
}
|
||||||
|
|
||||||
if (!new_body && tor_compress_supports_method(guessed) &&
|
if (tor_compress_supports_method(compression))
|
||||||
compression != guessed) {
|
tor_uncompress(&new_body, &new_len, body, body_len, compression,
|
||||||
tor_uncompress(&new_body, &new_len, body, body_len, guessed,
|
!allow_partial, LOG_PROTOCOL_WARN);
|
||||||
!allow_partial, LOG_PROTOCOL_WARN);
|
|
||||||
tried_both = 1;
|
/* Okay, if that didn't work, and we think that it was compressed
|
||||||
}
|
* differently, try that. */
|
||||||
/* If we're pretty sure that we have a compressed directory, and
|
if (anonymized_connection &&
|
||||||
* we didn't manage to uncompress it, then warn and bail. */
|
! allowed_anonymous_connection_compression_method(guessed)) {
|
||||||
if (!plausible && !new_body) {
|
warn_disallowed_anonymous_compression_method(guessed);
|
||||||
log_fn(LOG_PROTOCOL_WARN, LD_HTTP,
|
rv = -1;
|
||||||
"Unable to decompress HTTP body (tried %s%s%s, server '%s:%d').",
|
goto done;
|
||||||
description1,
|
}
|
||||||
tried_both?" and ":"",
|
|
||||||
tried_both?description2:"",
|
if (!new_body && tor_compress_supports_method(guessed) &&
|
||||||
conn->base_.address, conn->base_.port);
|
compression != guessed) {
|
||||||
rv = -1;
|
tor_uncompress(&new_body, &new_len, body, body_len, guessed,
|
||||||
goto done;
|
!allow_partial, LOG_PROTOCOL_WARN);
|
||||||
}
|
tried_both = 1;
|
||||||
if (new_body) {
|
}
|
||||||
tor_free(*bodyp);
|
/* If we're pretty sure that we have a compressed directory, and
|
||||||
*bodyp = new_body;
|
* we didn't manage to uncompress it, then warn and bail. */
|
||||||
*bodylenp = new_len;
|
if (!plausible && !new_body) {
|
||||||
}
|
log_fn(LOG_PROTOCOL_WARN, LD_HTTP,
|
||||||
|
"Unable to decompress HTTP body (tried %s%s%s, server '%s:%d').",
|
||||||
|
description1,
|
||||||
|
tried_both?" and ":"",
|
||||||
|
tried_both?description2:"",
|
||||||
|
conn->base_.address, conn->base_.port);
|
||||||
|
rv = -1;
|
||||||
|
goto done;
|
||||||
|
}
|
||||||
|
if (new_body) {
|
||||||
|
tor_free(*bodyp);
|
||||||
|
*bodyp = new_body;
|
||||||
|
*bodylenp = new_len;
|
||||||
}
|
}
|
||||||
|
|
||||||
done:
|
done:
|
||||||
|
|
Loading…
Add table
Reference in a new issue