]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
rohash: fix codeql warnings
authorVictor Julien <vjulien@oisf.net>
Wed, 24 Apr 2024 07:40:32 +0000 (09:40 +0200)
committerVictor Julien <victor@inliniac.net>
Fri, 26 Apr 2024 18:59:42 +0000 (20:59 +0200)
Suspicious pointer scaling to void

src/util-rohash.c

index 35c4e151eac5d493495617f6361987e6f3c9284a..b74deefa117ec5b35952ac0662ca863d6dbbe7f3 100644 (file)
@@ -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 */