multi: avoid reading whole struct pointer from pointer

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
This commit is contained in:
Daniel Stenberg 2024-09-26 16:05:20 +02:00
parent 6f2a1666a1
commit d08d16cac3
No known key found for this signature in database
GPG Key ID: 5CC908FDB71E12C2

View 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)