aboutsummaryrefslogtreecommitdiff
path: root/src/lib
diff options
context:
space:
mode:
authorrl1987 <rl1987@sdf.lonestar.org>2018-09-01 20:56:33 +0300
committerNick Mathewson <nickm@torproject.org>2018-10-30 09:05:11 -0400
commit742cd1564993faefded2d33b6839428a1fe4412a (patch)
treee1342212d387ccccedf2940dd3a48b316ca8e5f3 /src/lib
parent1baa2703c36cf964d5fc1f07433196e8ccc0e55a (diff)
downloadtor-742cd1564993faefded2d33b6839428a1fe4412a.tar.gz
tor-742cd1564993faefded2d33b6839428a1fe4412a.zip
Move a check for trailing colon to tor_inet_pton()
That way, string_is_valid_ipv6_address() can benefit from it
Diffstat (limited to 'src/lib')
-rw-r--r--src/lib/net/address.c5
-rw-r--r--src/lib/net/inaddr.c8
2 files changed, 8 insertions, 5 deletions
diff --git a/src/lib/net/address.c b/src/lib/net/address.c
index 336693b464..17f4b1cf7a 100644
--- a/src/lib/net/address.c
+++ b/src/lib/net/address.c
@@ -1198,10 +1198,7 @@ tor_addr_parse(tor_addr_t *addr, const char *src)
len -= 2;
}
- /* 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) {
+ if (tor_inet_pton(AF_INET6, src, &in6_tmp) > 0) {
result = AF_INET6;
tor_addr_from_in6(addr, &in6_tmp);
} else if (!brackets_detected &&
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