diff options
author | Tom Gundersen <teg@jklm.no> | 2015-10-04 01:59:06 +0200 |
---|---|---|
committer | Tom Gundersen <teg@jklm.no> | 2015-10-05 19:21:02 +0200 |
commit | 1e2527a6fede996a429bd44b30a15e76ee293437 (patch) | |
tree | 3cfdbc2314a6b3c26b63807e5575dac906734942 /src/shared | |
parent | hashmap: refactor hash_func (diff) | |
download | systemd-1e2527a6fede996a429bd44b30a15e76ee293437.tar.xz systemd-1e2527a6fede996a429bd44b30a15e76ee293437.zip |
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".
Diffstat (limited to 'src/shared')
-rw-r--r-- | src/shared/dns-domain.c | 6 |
1 files changed, 6 insertions, 0 deletions
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) { |