aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorNeel Chauhan <neel@neelc.org>2019-05-07 11:24:53 -0400
committerNeel Chauhan <neel@neelc.org>2019-05-07 11:52:56 -0400
commit3cafdeb8c0f1dfa60a964e4fba04b54d1ad97d15 (patch)
tree3655cd091d3c85ed77b7ba68454217906bcec26d /src
parentb72f5da03d12e0ac2212d18e3dea309d23ded79c (diff)
downloadtor-3cafdeb8c0f1dfa60a964e4fba04b54d1ad97d15.tar.gz
tor-3cafdeb8c0f1dfa60a964e4fba04b54d1ad97d15.zip
Only call tor_addr_parse() in circuit_is_acceptable() when needed
Diffstat (limited to 'src')
-rw-r--r--src/core/or/circuituse.c17
1 files changed, 10 insertions, 7 deletions
diff --git a/src/core/or/circuituse.c b/src/core/or/circuituse.c
index 2f27cf996f..226295425e 100644
--- a/src/core/or/circuituse.c
+++ b/src/core/or/circuituse.c
@@ -178,7 +178,6 @@ circuit_is_acceptable(const origin_circuit_t *origin_circ,
purpose == CIRCUIT_PURPOSE_S_HSDIR_POST ||
purpose == CIRCUIT_PURPOSE_C_HSDIR_GET) {
tor_addr_t addr;
- const int family = tor_addr_parse(&addr, conn->socks_request->address);
if (!exitnode && !build_state->onehop_tunnel) {
log_debug(LD_CIRC,"Not considering circuit with unknown router.");
return 0; /* this circuit is screwed and doesn't know it yet,
@@ -199,6 +198,8 @@ circuit_is_acceptable(const origin_circuit_t *origin_circ,
return 0; /* this is a circuit to somewhere else */
if (tor_digest_is_zero(digest)) {
/* we don't know the digest; have to compare addr:port */
+ const int family = tor_addr_parse(&addr,
+ conn->socks_request->address);
if (family < 0 ||
!tor_addr_eq(&build_state->chosen_exit->addr, &addr) ||
build_state->chosen_exit->port != conn->socks_request->port)
@@ -211,12 +212,14 @@ circuit_is_acceptable(const origin_circuit_t *origin_circ,
return 0;
}
}
- if (origin_circ->prepend_policy && family != -1) {
- int r = compare_tor_addr_to_addr_policy(&addr,
- conn->socks_request->port,
- origin_circ->prepend_policy);
- if (r == ADDR_POLICY_REJECTED)
- return 0;
+ if (origin_circ->prepend_policy) {
+ if (tor_addr_parse(&addr, conn->socks_request->address) != -1) {
+ int r = compare_tor_addr_to_addr_policy(&addr,
+ conn->socks_request->port,
+ origin_circ->prepend_policy);
+ if (r == ADDR_POLICY_REJECTED)
+ return 0;
+ }
}
if (exitnode && !connection_ap_can_use_exit(conn, exitnode)) {
/* can't exit from this router */