Fix a possible negative shift in address comparison. May fix bug 845 and bug 811

svn:r17169
This commit is contained in:
Nick Mathewson 2008-10-29 13:29:54 +00:00
parent accb4a680f
commit 361086005c
2 changed files with 4 additions and 0 deletions

View File

@ -41,6 +41,8 @@ Changes in version 0.2.1.7-alpha - 2008-10-xx
prevent possible guess-the-streamid injection attacks from prevent possible guess-the-streamid injection attacks from
intermediate hops. Fixes another case of bug 446. Based on patch intermediate hops. Fixes another case of bug 446. Based on patch
from rovv. from rovv.
- Avoid using a negative right-shift when comparing 32-bit
addresses. Possible fix for bug 845 and bug 811.
Changes in version 0.2.1.6-alpha - 2008-09-30 Changes in version 0.2.1.6-alpha - 2008-09-30

View File

@ -686,6 +686,8 @@ tor_addr_compare_masked(const tor_addr_t *addr1, const tor_addr_t *addr2,
case AF_INET: { case AF_INET: {
uint32_t a1 = ntohl(addr1->addr.in_addr.s_addr); uint32_t a1 = ntohl(addr1->addr.in_addr.s_addr);
uint32_t a2 = ntohl(addr2->addr.in_addr.s_addr); uint32_t a2 = ntohl(addr2->addr.in_addr.s_addr);
if (mbits > 32)
mbits = 32;
a1 >>= (32-mbits); a1 >>= (32-mbits);
a2 >>= (32-mbits); a2 >>= (32-mbits);
return (a1 < a2) ? -1 : (a1 == a2) ? 0 : 1; return (a1 < a2) ? -1 : (a1 == a2) ? 0 : 1;