mirror of
https://gitlab.torproject.org/tpo/core/tor.git
synced 2024-11-11 05:33:47 +01:00
Make tor_addr_port_parse handle portless IPv6 addresses correctly.
(Not a bugfix on any Tor release; before 10801_024, it didn't handle portless addresses at all.)
This commit is contained in:
parent
eefa3ebc78
commit
b3469e4207
@ -1488,9 +1488,18 @@ int
|
|||||||
tor_addr_port_split(int severity, const char *addrport,
|
tor_addr_port_split(int severity, const char *addrport,
|
||||||
char **address_out, uint16_t *port_out)
|
char **address_out, uint16_t *port_out)
|
||||||
{
|
{
|
||||||
|
tor_addr_t a_tmp;
|
||||||
tor_assert(addrport);
|
tor_assert(addrport);
|
||||||
tor_assert(address_out);
|
tor_assert(address_out);
|
||||||
tor_assert(port_out);
|
tor_assert(port_out);
|
||||||
|
/* We need to check for IPv6 manually because addr_port_lookup() doesn't
|
||||||
|
* do a good job on IPv6 addresses that lack a port. */
|
||||||
|
if (tor_addr_parse(&a_tmp, addrport) == AF_INET6) {
|
||||||
|
*port_out = 0;
|
||||||
|
*address_out = tor_strdup(addrport);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
return addr_port_lookup(severity, addrport, address_out, NULL, port_out);
|
return addr_port_lookup(severity, addrport, address_out, NULL, port_out);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -741,6 +741,14 @@ test_addr_parse(void)
|
|||||||
test_streq(buf, "192.0.2.1");
|
test_streq(buf, "192.0.2.1");
|
||||||
test_eq(port, 1234);
|
test_eq(port, 1234);
|
||||||
|
|
||||||
|
r= tor_addr_port_parse(LOG_DEBUG,
|
||||||
|
"[::1]:1234",
|
||||||
|
&addr, &port, -1);
|
||||||
|
test_assert(r == 0);
|
||||||
|
tor_addr_to_str(buf, &addr, sizeof(buf), 0);
|
||||||
|
test_streq(buf, "::1");
|
||||||
|
test_eq(port, 1234);
|
||||||
|
|
||||||
/* Domain name. */
|
/* Domain name. */
|
||||||
r= tor_addr_port_parse(LOG_DEBUG,
|
r= tor_addr_port_parse(LOG_DEBUG,
|
||||||
"torproject.org:1234",
|
"torproject.org:1234",
|
||||||
@ -759,6 +767,17 @@ test_addr_parse(void)
|
|||||||
test_assert(r == 0);
|
test_assert(r == 0);
|
||||||
tt_int_op(port,==,200);
|
tt_int_op(port,==,200);
|
||||||
|
|
||||||
|
r= tor_addr_port_parse(LOG_DEBUG,
|
||||||
|
"[::1]",
|
||||||
|
&addr, &port, -1);
|
||||||
|
test_assert(r == -1);
|
||||||
|
|
||||||
|
r= tor_addr_port_parse(LOG_DEBUG,
|
||||||
|
"[::1]",
|
||||||
|
&addr, &port, 400);
|
||||||
|
test_assert(r == 0);
|
||||||
|
tt_int_op(port,==,400);
|
||||||
|
|
||||||
/* Bad port. */
|
/* Bad port. */
|
||||||
r= tor_addr_port_parse(LOG_DEBUG,
|
r= tor_addr_port_parse(LOG_DEBUG,
|
||||||
"192.0.2.2:66666",
|
"192.0.2.2:66666",
|
||||||
@ -793,6 +812,12 @@ test_addr_parse(void)
|
|||||||
test_assert(r == 0);
|
test_assert(r == 0);
|
||||||
tt_int_op(port,==,1337);
|
tt_int_op(port,==,1337);
|
||||||
|
|
||||||
|
r= tor_addr_port_parse(LOG_DEBUG,
|
||||||
|
"[::1]:1369",
|
||||||
|
&addr, &port, 200);
|
||||||
|
test_assert(r == 0);
|
||||||
|
tt_int_op(port,==,1369);
|
||||||
|
|
||||||
done:
|
done:
|
||||||
;
|
;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user