diff options
author | rl1987 <rl1987@sdf.lonestar.org> | 2018-08-31 19:34:14 +0300 |
---|---|---|
committer | rl1987 <rl1987@sdf.lonestar.org> | 2018-08-31 19:34:14 +0300 |
commit | 01eb164574bdcc938509810634dfb0348c484662 (patch) | |
tree | f09888dbb8c1f72bbe75d279e370057438633ebe /src/lib | |
parent | feae813e1bf32e7fc35a14d88ece4a9457cfd172 (diff) | |
download | tor-01eb164574bdcc938509810634dfb0348c484662.tar.gz tor-01eb164574bdcc938509810634dfb0348c484662.zip |
Reject addresses with needless trailing colon
Diffstat (limited to 'src/lib')
-rw-r--r-- | src/lib/net/address.c | 10 |
1 files changed, 8 insertions, 2 deletions
diff --git a/src/lib/net/address.c b/src/lib/net/address.c index 14c086a5b0..336693b464 100644 --- a/src/lib/net/address.c +++ b/src/lib/net/address.c @@ -1189,13 +1189,19 @@ tor_addr_parse(tor_addr_t *addr, const char *src) struct in6_addr in6_tmp; int brackets_detected = 0; + size_t len = strlen(src); + tor_assert(addr && src); - if (src[0] == '[' && src[1] && src[strlen(src)-1] == ']') { + if (src[0] == '[' && src[1] && src[len - 1] == ']') { brackets_detected = 1; src = tmp = tor_strndup(src+1, strlen(src)-2); + len -= 2; } - if (tor_inet_pton(AF_INET6, src, &in6_tmp) > 0) { + /* Reject if src has needless trailing ':'. */ + if (len > 2 && src[len - 1] == ':' && src[len - 2] != ':') { + result = -1; + } else if (tor_inet_pton(AF_INET6, src, &in6_tmp) > 0) { result = AF_INET6; tor_addr_from_in6(addr, &in6_tmp); } else if (!brackets_detected && |