diff options
author | Nick Mathewson <nickm@torproject.org> | 2018-10-30 09:05:42 -0400 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2018-10-30 09:05:42 -0400 |
commit | 084924360aa937014aa4b86de1131e0a413e81de (patch) | |
tree | 565b4421c0df2d485e6dc1e7439ec8fa9382a807 /src/lib/net | |
parent | c19bb4d62e9bf3d969a6950e529a95e2f98b7e1c (diff) | |
parent | 1425549ca61cab8aa9476a25be0a31f726672bcc (diff) | |
download | tor-084924360aa937014aa4b86de1131e0a413e81de.tar.gz tor-084924360aa937014aa4b86de1131e0a413e81de.zip |
Merge branch 'ticket23082_squashed'
Diffstat (limited to 'src/lib/net')
-rw-r--r-- | src/lib/net/address.c | 12 | ||||
-rw-r--r-- | src/lib/net/inaddr.c | 8 |
2 files changed, 17 insertions, 3 deletions
diff --git a/src/lib/net/address.c b/src/lib/net/address.c index 03767e2950..c97a17037a 100644 --- a/src/lib/net/address.c +++ b/src/lib/net/address.c @@ -1187,14 +1187,22 @@ 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]) + + size_t len = strlen(src); + + if (len && src[0] == '[' && src[len - 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 { diff --git a/src/lib/net/inaddr.c b/src/lib/net/inaddr.c index dcd8fcdd65..0960d323c5 100644 --- a/src/lib/net/inaddr.c +++ b/src/lib/net/inaddr.c @@ -168,6 +168,13 @@ tor_inet_pton(int af, const char *src, void *dst) if (af == AF_INET) { return tor_inet_aton(src, dst); } else if (af == AF_INET6) { + ssize_t len = strlen(src); + + /* Reject if src has needless trailing ':'. */ + if (len > 2 && src[len - 1] == ':' && src[len - 2] != ':') { + return 0; + } + struct in6_addr *out = dst; uint16_t words[8]; int gapPos = -1, i, setWords=0; @@ -207,7 +214,6 @@ tor_inet_pton(int af, const char *src, void *dst) return 0; if (TOR_ISXDIGIT(*src)) { char *next; - ssize_t len; long r = strtol(src, &next, 16); if (next == NULL || next == src) { /* The 'next == src' error case can happen on versions of openbsd |