diff options
author | Dimitri Staessens <dimitri@ouroboros.rocks> | 2022-02-17 20:22:33 +0100 |
---|---|---|
committer | Sander Vrijders <sander@ouroboros.rocks> | 2022-02-18 08:43:15 +0100 |
commit | 5b61e1f163afcb292185ede20c4682ef5ea92081 (patch) | |
tree | db93bac402d8c06a39183a1344ad4c351e05e5a9 /src/ipcpd/unicast/pff/pft.c | |
parent | c8d38bc1d9d578a884d4aa661a928c53c18d77fd (diff) | |
download | ouroboros-5b61e1f163afcb292185ede20c4682ef5ea92081.tar.gz ouroboros-5b61e1f163afcb292185ede20c4682ef5ea92081.zip |
ipcpd: Fix hashing and overlapping memcpy in pff
The pft hash function assumed mem_hash allocates memory, but it does
not. There was also a memcpy with potentially overlapping memory
regions, which is undefined behaviour.
Signed-off-by: Dimitri Staessens <dimitri@ouroboros.rocks>
Signed-off-by: Sander Vrijders <sander@ouroboros.rocks>
Diffstat (limited to 'src/ipcpd/unicast/pff/pft.c')
-rw-r--r-- | src/ipcpd/unicast/pff/pft.c | 14 |
1 files changed, 3 insertions, 11 deletions
diff --git a/src/ipcpd/unicast/pff/pft.c b/src/ipcpd/unicast/pff/pft.c index e42b4a98..6a7cc11d 100644 --- a/src/ipcpd/unicast/pff/pft.c +++ b/src/ipcpd/unicast/pff/pft.c @@ -115,19 +115,11 @@ void pft_flush(struct pft * pft) static uint64_t hash(uint64_t key) { - void * res; - uint64_t ret; - uint8_t keys[4]; + uint64_t res[2]; - memcpy(keys, &key, 4); + mem_hash(HASH_MD5, res, (uint8_t *) &key, sizeof(key)); - mem_hash(HASH_MD5, &res, keys, 4); - - ret = (* (uint64_t *) res); - - free(res); - - return ret; + return res[0]; } static uint64_t calc_key(struct pft * pft, |