diff options
author | Nick Mathewson <nickm@torproject.org> | 2014-04-05 14:41:37 -0400 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2014-04-05 14:41:37 -0400 |
commit | b3469e4207d12821993f1d2d381c5d27918a4c01 (patch) | |
tree | d95b0114a8f96ae504fc6fe49707e9cb25426939 /src | |
parent | eefa3ebc786fdfd3a642698822f8a0ade583996e (diff) | |
download | tor-b3469e4207d12821993f1d2d381c5d27918a4c01.tar tor-b3469e4207d12821993f1d2d381c5d27918a4c01.tar.gz |
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.)
Diffstat (limited to 'src')
-rw-r--r-- | src/common/address.c | 9 | ||||
-rw-r--r-- | src/test/test_addr.c | 25 |
2 files changed, 34 insertions, 0 deletions
diff --git a/src/common/address.c b/src/common/address.c index 3e898611d..84565582e 100644 --- a/src/common/address.c +++ b/src/common/address.c @@ -1488,9 +1488,18 @@ int tor_addr_port_split(int severity, const char *addrport, char **address_out, uint16_t *port_out) { + tor_addr_t a_tmp; tor_assert(addrport); tor_assert(address_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); } diff --git a/src/test/test_addr.c b/src/test/test_addr.c index 6228fabad..c75f8e6a1 100644 --- a/src/test/test_addr.c +++ b/src/test/test_addr.c @@ -741,6 +741,14 @@ test_addr_parse(void) test_streq(buf, "192.0.2.1"); 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. */ r= tor_addr_port_parse(LOG_DEBUG, "torproject.org:1234", @@ -759,6 +767,17 @@ test_addr_parse(void) test_assert(r == 0); 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. */ r= tor_addr_port_parse(LOG_DEBUG, "192.0.2.2:66666", @@ -793,6 +812,12 @@ test_addr_parse(void) test_assert(r == 0); 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: ; } |