From: Victor Julien Date: Wed, 24 Apr 2024 07:40:32 +0000 (+0200) Subject: rohash: fix codeql warnings X-Git-Tag: suricata-8.0.0-beta1~1414 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=60e6d1d77dd41ff7d349b485e413d6e4b918793e;p=thirdparty%2Fsuricata.git rohash: fix codeql warnings Suspicious pointer scaling to void --- diff --git a/src/util-rohash.c b/src/util-rohash.c index 35c4e151ea..b74deefa11 100644 --- a/src/util-rohash.c +++ b/src/util-rohash.c @@ -116,11 +116,11 @@ void *ROHashLookup(ROHashTable *table, void *data, uint16_t size) SCReturnPtr(NULL, "void"); } - uint32_t hash = hashword(data, table->item_size/4, 0) & hashmask(table->hash_bits); + const uint32_t hash = hashword(data, table->item_size / 4, 0) & hashmask(table->hash_bits); /* get offsets start */ - ROHashTableOffsets *os = (void *)table + sizeof(ROHashTable); - ROHashTableOffsets *o = &os[hash]; + const ROHashTableOffsets *os = (ROHashTableOffsets *)((uint8_t *)table + sizeof(ROHashTable)); + const ROHashTableOffsets *o = &os[hash]; /* no matches */ if (o->cnt == 0) { @@ -186,11 +186,13 @@ int ROHashInitFinalize(ROHashTable *table) } ROHashTableItem *item = NULL; - ROHashTableOffsets *os = (void *)table + sizeof(ROHashTable); + ROHashTableOffsets *os = (ROHashTableOffsets *)((uint8_t *)table + sizeof(ROHashTable)); /* count items per hash value */ TAILQ_FOREACH(item, &table->head, next) { - uint32_t hash = hashword((void *)item + sizeof(*item), table->item_size/4, 0) & hashmask(table->hash_bits); + uint32_t hash = + hashword((uint32_t *)((uint8_t *)item + sizeof(*item)), table->item_size / 4, 0) & + hashmask(table->hash_bits); ROHashTableOffsets *o = &os[hash]; item->pos = o->cnt; @@ -225,13 +227,14 @@ int ROHashInitFinalize(ROHashTable *table) /* copy each value into the data block */ TAILQ_FOREACH(item, &table->head, next) { - uint32_t hash = hashword((void *)item + sizeof(*item), table->item_size/4, 0) & hashmask(table->hash_bits); + uint32_t hash = + hashword((uint32_t *)((uint8_t *)item + sizeof(*item)), table->item_size / 4, 0) & + hashmask(table->hash_bits); ROHashTableOffsets *o = &os[hash]; uint32_t offset = (o->offset + item->pos) * table->item_size; - memcpy(table->data + offset, (void *)item + sizeof(*item), table->item_size); - + memcpy(table->data + offset, (uint8_t *)item + sizeof(*item), table->item_size); } /* clean up temp items */