]> git.ipfire.org Git - thirdparty/curl.git/commitdiff
multi: avoid reading whole struct pointer from pointer
authorDaniel Stenberg <daniel@haxx.se>
Thu, 26 Sep 2024 14:05:20 +0000 (16:05 +0200)
committerDaniel Stenberg <daniel@haxx.se>
Thu, 26 Sep 2024 21:37:15 +0000 (23:37 +0200)
The proper alignment is not guaranteed. This function now instead uses
only the first and last byte of the key since they are the ones likely
to change most (one of them, depending on CPU endian) and the hash is
tiny anyway.

Closes #15063

lib/multi.c

index 27b8ef30753b31f2157f37ad28a4c5fc39d4b077..413f4329fbce279c6b8c794c65ade05fba0da005 100644 (file)
@@ -240,12 +240,13 @@ static struct Curl_sh_entry *sh_getentry(struct Curl_hash *sh,
 }
 
 #define TRHASH_SIZE 13
+
+/* the given key here is a struct Curl_easy pointer */
 static size_t trhash(void *key, size_t key_length, size_t slots_num)
 {
-  size_t keyval = (size_t)*(struct Curl_easy **)key;
-  (void) key_length;
-
-  return (keyval % slots_num);
+  unsigned char bytes = ((unsigned char *)key)[key_length - 1] ^
+    ((unsigned char *)key)[0];
+  return (bytes % slots_num);
 }
 
 static size_t trhash_compare(void *k1, size_t k1_len, void *k2, size_t k2_len)