From: Etienne Dechamps Date: Sat, 20 Jul 2013 13:50:28 +0000 (+0100) Subject: Fix hash_function(). X-Git-Tag: release-1.1pre8~26 X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=51c1639884b409a98a4581a7b661ef65b94e9d86;p=oweals%2Ftinc.git Fix hash_function(). The hashing function that tinc uses is currently broken as it only looks at the first 4 bytes of data. This leads to interesting bugs, like the node UDP address cache being subtly broken because two addresses with the same protocol and port (but not the same IP address) will override each other. This is because the first four bytes of sockaddr_in contains the IP protocol and port, while the IP address itself is contained in the four remaining bytes that are never used when the hash is computed. --- diff --git a/src/hash.c b/src/hash.c index 36b510c..a40e799 100644 --- a/src/hash.c +++ b/src/hash.c @@ -29,7 +29,7 @@ static uint32_t hash_function(const void *p, size_t len) { uint32_t hash = 0; while(true) { for(int i = len > 4 ? 4 : len; --i;) - hash += q[i] << (8 * i); + hash += q[len - i] << (8 * i); hash *= 0x9e370001UL; // Golden ratio prime. if(len <= 4) break;