diff options
author | Nick Mathewson <nickm@torproject.org> | 2007-07-20 16:25:27 +0000 |
---|---|---|
committer | Nick Mathewson <nickm@torproject.org> | 2007-07-20 16:25:27 +0000 |
commit | 8ba42a3bdecdc7301e37504758c892d322ce8207 (patch) | |
tree | 551351528ea4147289820b9194fba84ff1f8af00 /src/common | |
parent | 6223160ab7a5e6d20fcbd7095e4d154d0c1e0316 (diff) | |
download | tor-8ba42a3bdecdc7301e37504758c892d322ce8207.tar.gz tor-8ba42a3bdecdc7301e37504758c892d322ce8207.zip |
r13850@catbus: nickm | 2007-07-20 12:25:24 -0400
Fix some bugs in ntop/pton.
svn:r10891
Diffstat (limited to 'src/common')
-rw-r--r-- | src/common/compat.c | 9 |
1 files changed, 6 insertions, 3 deletions
diff --git a/src/common/compat.c b/src/common/compat.c index b32c0b115c..ef95ba0c13 100644 --- a/src/common/compat.c +++ b/src/common/compat.c @@ -834,7 +834,8 @@ tor_inet_ntop(int af, const void *src, char *dst, size_t len) words[i] = (((uint16_t)addr->s6_addr[2*i])<<8) + addr->s6_addr[2*i+1]; } if (words[0] == 0 && words[1] == 0 && words[2] == 0 && words[3] == 0 && - words[4] == 0 && (words[5] == 0 || words[5] == 0xffff) && words[6]) { + words[4] == 0 && ((words[5] == 0 && (words[6] || words[7])) || + (words[5] == 0xffff))) { /* This is an IPv4 address. */ if (words[5] == 0) { tor_snprintf(buf, sizeof(buf), "::%d.%d.%d.%d", @@ -965,7 +966,7 @@ tor_inet_pton(int af, const char *src, void *dst) } else if (*src == ':' && i > 0 && gapPos==-1) { gapPos = i; ++src; - } else if (*src == ':' && i == 0 && src[1] == ':') { + } else if (*src == ':' && i == 0 && src[1] == ':' && gapPos==-1) { gapPos = i; src += 2; } else { @@ -973,7 +974,9 @@ tor_inet_pton(int af, const char *src, void *dst) } } - if (setWords > 8 || (setWords < 8 && gapPos == -1)) + if (setWords > 8 || + (setWords == 8 && gapPos != -1) || + (setWords < 8 && gapPos == -1)) return 0; if (gapPos >= 0) { |