From 1e2527a6fede996a429bd44b30a15e76ee293437 Mon Sep 17 00:00:00 2001 From: Tom Gundersen Date: Sun, 4 Oct 2015 01:59:06 +0200 Subject: hashmap: hash_funcs - make inputs unambiguous Make sure all variable-length inputs are properly terminated or that their length is encoded in some way. This avoids ambiguity of adjacent inputs. E.g., in case of a hash function taking two strings, compressing "ab" followed by "c" is now distinct from "a" followed by "bc". --- src/shared/dns-domain.c | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'src/shared/dns-domain.c') diff --git a/src/shared/dns-domain.c b/src/shared/dns-domain.c index 1517443736..5680f01bd9 100644 --- a/src/shared/dns-domain.c +++ b/src/shared/dns-domain.c @@ -399,11 +399,17 @@ void dns_name_hash_func(const void *s, struct siphash *state) { if (k > 0) r = k; + if (r == 0) + break; + label[r] = 0; ascii_strlower(label); string_hash_func(label, state); } + + /* enforce that all names are terminated by the empty label */ + string_hash_func("", state); } int dns_name_compare_func(const void *a, const void *b) { -- cgit v1.2.3-54-g00ecf