aboutsummaryrefslogtreecommitdiff
path: root/src/app/config
diff options
context:
space:
mode:
authorDavid Goulet <dgoulet@torproject.org>2020-11-12 11:22:02 -0500
committerDavid Goulet <dgoulet@torproject.org>2020-11-13 08:38:22 -0500
commitd425dbf04a6bbac7eae832bf51c2bfe061e2c426 (patch)
tree3f598f329955ff14d40e9dcb7d11ee39997d2e05 /src/app/config
parent46ccde66a97d7985388eb54bc74a025402fb0a19 (diff)
downloadtor-d425dbf04a6bbac7eae832bf51c2bfe061e2c426.tar.gz
tor-d425dbf04a6bbac7eae832bf51c2bfe061e2c426.zip
port: Don't ignore ports of a different family
Commit c3a0f757964de0e8a24911d72abff5df20bb323c added this feature for ORPort that we ignore any port that is not the family of our default address when parsing the port. So if port_parse_config() was called with an IPv4 default address, all IPv6 address would be ignored. That makes sense for ORPort since we call twice port_parse_config() for 0.0.0.0 and [::] but for the rest of the ports, it is not good since a perfectly valid configuration can be: SocksPort 9050 SocksPort [::1]:9050 Any non-ORPort only binds by default to an IPv4 except the ORPort that binds to both IPv4 and IPv6 by default. The fix here is to always parse all ports within port_parse_config() and then, specifically for ORPort, remove the duplicates or superseding ones. The warning is only emitted when a port supersedes another. A unit tests is added to make sure SocksPort of different family always exists together. Fixes #40183 Signed-off-by: David Goulet <dgoulet@torproject.org>
Diffstat (limited to 'src/app/config')
-rw-r--r--src/app/config/config.c16
1 files changed, 4 insertions, 12 deletions
diff --git a/src/app/config/config.c b/src/app/config/config.c
index 458067af4d..04a82a5c43 100644
--- a/src/app/config/config.c
+++ b/src/app/config/config.c
@@ -5934,13 +5934,12 @@ port_parse_config(smartlist_t *out,
char *unix_socket_path = NULL;
port_cfg_t *cfg = NULL;
bool addr_is_explicit = false;
- int family = -1;
-
- /* Parse default address. This can fail for Unix socket for instance so
- * family can be -1 and the default_addr will be made UNSPEC. */
tor_addr_t default_addr = TOR_ADDR_NULL;
+
+ /* Parse default address. This can fail for Unix socket so the default_addr
+ * will simply be made UNSPEC. */
if (defaultaddr) {
- family = tor_addr_parse(&default_addr, defaultaddr);
+ tor_addr_parse(&default_addr, defaultaddr);
}
/* If there's no FooPort, then maybe make a default one. */
@@ -6018,7 +6017,6 @@ port_parse_config(smartlist_t *out,
port = 1;
} else if (!strcasecmp(addrport, "auto")) {
port = CFG_AUTO_PORT;
- tor_assert(family >= 0);
tor_addr_copy(&addr, &default_addr);
} else if (!strcasecmpend(addrport, ":auto")) {
char *addrtmp = tor_strndup(addrport, strlen(addrport)-5);
@@ -6035,18 +6033,12 @@ port_parse_config(smartlist_t *out,
"9050" might be a valid address. */
port = (int) tor_parse_long(addrport, 10, 0, 65535, &ok, NULL);
if (ok) {
- tor_assert(family >= 0);
tor_addr_copy(&addr, &default_addr);
} else if (tor_addr_port_lookup(addrport, &addr, &ptmp) == 0) {
if (ptmp == 0) {
log_warn(LD_CONFIG, "%sPort line has address but no port", portname);
goto err;
}
- if (family != -1 && tor_addr_family(&addr) != family) {
- /* This means we are parsing another ORPort family but we are
- * attempting to find the default address' family ORPort. */
- goto ignore;
- }
port = ptmp;
addr_is_explicit = true;
} else {