]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
hashmap: hash_funcs - make inputs unambiguous 1465/head
authorTom Gundersen <teg@jklm.no>
Sat, 3 Oct 2015 23:59:06 +0000 (01:59 +0200)
committerTom Gundersen <teg@jklm.no>
Mon, 5 Oct 2015 17:21:02 +0000 (19:21 +0200)
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/basic/hashmap.c
src/libsystemd-network/sd-dhcp-server.c
src/libsystemd-network/sd-lldp.c
src/libsystemd/sd-bus/busctl.c
src/shared/dns-domain.c

index 3c05bee56d7487bdfa135f438f73c52cec16ecc1..3e17ed30df3e1c11c45d80ae0b80fb5be9fd84d0 100644 (file)
@@ -277,7 +277,7 @@ static const struct hashmap_type_info hashmap_type_info[_HASHMAP_TYPE_MAX] = {
 };
 
 void string_hash_func(const void *p, struct siphash *state) {
-        siphash24_compress(p, strlen(p), state);
+        siphash24_compress(p, strlen(p) + 1, state);
 }
 
 int string_compare_func(const void *a, const void *b) {
index 4ea5a29e5c35860713c05085b266d5148b11c093..d941e6c0de76bb3e93e7166b2ce2585dd5c32a97 100644 (file)
@@ -117,6 +117,7 @@ void client_id_hash_func(const void *p, struct siphash *state) {
         assert(id->length);
         assert(id->data);
 
+        siphash24_compress(&id->length, sizeof(id->length), state);
         siphash24_compress(id->data, id->length, state);
 }
 
index b9bf4d3c00aeebd5fc39f199201aa45872fa04dd..0b7d35cdf137d333238d375a8d18271a0c8c3797 100644 (file)
@@ -74,6 +74,7 @@ static void chassis_id_hash_func(const void *p, struct siphash *state) {
         assert(id);
         assert(id->data);
 
+        siphash24_compress(&id->length, sizeof(id->length), state);
         siphash24_compress(id->data, id->length, state);
 }
 
index 496b9a7b4ead5d3ae35581b4874ed09db35580fd..49c97af33909a869051e7f86ca7eda3a62b2b2f3 100644 (file)
@@ -630,12 +630,17 @@ typedef struct Member {
 
 static void member_hash_func(const void *p, struct siphash *state) {
         const Member *m = p;
+        uint64_t arity = 1;
 
         assert(m);
         assert(m->type);
 
         string_hash_func(m->type, state);
 
+        arity += !!m->name + !!m->interface;
+
+        uint64_hash_func(&arity, state);
+
         if (m->name)
                 string_hash_func(m->name, state);
 
index 1517443736d24b70b80a86a5c244368a7ead058e..5680f01bd91ded78a632c107645458685d905077 100644 (file)
@@ -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) {