diff options
author | rl1987 <rl1987@sdf.lonestar.org> | 2018-08-31 18:55:36 +0300 |
---|---|---|
committer | rl1987 <rl1987@sdf.lonestar.org> | 2018-08-31 18:55:36 +0300 |
commit | 23ed863da4f66d9e07f578118f328b9f1898fe52 (patch) | |
tree | 69bef9572c20759e3b810ab7b9de765f0265ff91 /src/lib/net/address.c | |
parent | 1c62adb65baa99c92f937318c452955306301643 (diff) | |
download | tor-23ed863da4f66d9e07f578118f328b9f1898fe52.tar.gz tor-23ed863da4f66d9e07f578118f328b9f1898fe52.zip |
Improve bracket handling in tor_addr_parse()
* Actually check for second bracket
* Only attempt parsing IPv4 address when no brackets found
Diffstat (limited to 'src/lib/net/address.c')
-rw-r--r-- | src/lib/net/address.c | 9 |
1 files changed, 7 insertions, 2 deletions
diff --git a/src/lib/net/address.c b/src/lib/net/address.c index 619fa13e9b..14c086a5b0 100644 --- a/src/lib/net/address.c +++ b/src/lib/net/address.c @@ -1187,14 +1187,19 @@ tor_addr_parse(tor_addr_t *addr, const char *src) int result; struct in_addr in_tmp; struct in6_addr in6_tmp; + int brackets_detected = 0; + tor_assert(addr && src); - if (src[0] == '[' && src[1]) + if (src[0] == '[' && src[1] && src[strlen(src)-1] == ']') { + brackets_detected = 1; src = tmp = tor_strndup(src+1, strlen(src)-2); + } if (tor_inet_pton(AF_INET6, src, &in6_tmp) > 0) { result = AF_INET6; tor_addr_from_in6(addr, &in6_tmp); - } else if (tor_inet_pton(AF_INET, src, &in_tmp) > 0) { + } else if (!brackets_detected && + tor_inet_pton(AF_INET, src, &in_tmp) > 0) { result = AF_INET; tor_addr_from_in(addr, &in_tmp); } else { |