mirror of
https://gitlab.torproject.org/tpo/core/tor.git
synced 2024-11-11 05:33:47 +01:00
Tweak addressmap_rewrite a little more
This resolves a loop warning on "MapAddress *.example.com example.com", makes the rewrite log messages correct, and fixes the behavior of "MapAddress *.a *.b" when just given "a" as an input.
This commit is contained in:
parent
66859e2d4a
commit
e8d598c4ac
@ -1087,23 +1087,38 @@ addressmap_rewrite(char *address, size_t maxlen, time_t *expires_out)
|
|||||||
{
|
{
|
||||||
addressmap_entry_t *ent;
|
addressmap_entry_t *ent;
|
||||||
int rewrites;
|
int rewrites;
|
||||||
char *cp;
|
|
||||||
time_t expires = TIME_MAX;
|
time_t expires = TIME_MAX;
|
||||||
|
|
||||||
for (rewrites = 0; rewrites < 16; rewrites++) {
|
for (rewrites = 0; rewrites < 16; rewrites++) {
|
||||||
|
int exact_match = 0;
|
||||||
|
char *addr_orig = tor_strdup(escaped_safe_str_client(address));
|
||||||
|
|
||||||
ent = strmap_get(addressmap, address);
|
ent = strmap_get(addressmap, address);
|
||||||
|
|
||||||
if (!ent || !ent->new_address)
|
if (!ent || !ent->new_address) {
|
||||||
ent = addressmap_match_superdomains(address);
|
ent = addressmap_match_superdomains(address);
|
||||||
|
} else {
|
||||||
|
if (ent->src_wildcard && !ent->dst_wildcard &&
|
||||||
|
!strcasecmp(address, ent->new_address)) {
|
||||||
|
/* This is a rule like *.example.com example.com, and we just got
|
||||||
|
* "example.com" */
|
||||||
|
tor_free(addr_orig);
|
||||||
|
if (expires_out)
|
||||||
|
*expires_out = expires;
|
||||||
|
return rewrites > 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
exact_match = 1;
|
||||||
|
}
|
||||||
|
|
||||||
if (!ent || !ent->new_address) {
|
if (!ent || !ent->new_address) {
|
||||||
|
tor_free(addr_orig);
|
||||||
if (expires_out)
|
if (expires_out)
|
||||||
*expires_out = expires;
|
*expires_out = expires;
|
||||||
return (rewrites > 0); /* done, no rewrite needed */
|
return (rewrites > 0); /* done, no rewrite needed */
|
||||||
}
|
}
|
||||||
|
|
||||||
cp = tor_strdup(escaped_safe_str_client(address));
|
if (ent->dst_wildcard && !exact_match) {
|
||||||
if (ent->dst_wildcard) {
|
|
||||||
strlcat(address, ".", maxlen);
|
strlcat(address, ".", maxlen);
|
||||||
strlcat(address, ent->new_address, maxlen);
|
strlcat(address, ent->new_address, maxlen);
|
||||||
} else {
|
} else {
|
||||||
@ -1111,10 +1126,10 @@ addressmap_rewrite(char *address, size_t maxlen, time_t *expires_out)
|
|||||||
}
|
}
|
||||||
|
|
||||||
log_info(LD_APP, "Addressmap: rewriting %s to %s",
|
log_info(LD_APP, "Addressmap: rewriting %s to %s",
|
||||||
cp, escaped_safe_str_client(address));
|
addr_orig, escaped_safe_str_client(address));
|
||||||
if (ent->expires > 1 && ent->expires < expires)
|
if (ent->expires > 1 && ent->expires < expires)
|
||||||
expires = ent->expires;
|
expires = ent->expires;
|
||||||
tor_free(cp);
|
tor_free(addr_orig);
|
||||||
}
|
}
|
||||||
log_warn(LD_CONFIG,
|
log_warn(LD_CONFIG,
|
||||||
"Loop detected: we've rewritten %s 16 times! Using it as-is.",
|
"Loop detected: we've rewritten %s 16 times! Using it as-is.",
|
||||||
|
Loading…
Reference in New Issue
Block a user