If the hash function returns an index greater than the array size of the
hash table, the index is not checked. Even if this is the responsibility
of the caller, add a safety check to avoid errors.
hb->size = datalen;
hb->next = NULL;
+ if (hash >= ht->array_size) {
+ SCLogWarning(SC_ERR_INVALID_VALUE, "attempt to insert element out of hash array\n");
+ goto error;
+ }
+
if (ht->array[hash] == NULL) {
ht->array[hash] = hb;
} else {
hash = ht->Hash(ht, data, datalen);
+ if (hash >= ht->array_size) {
+ SCLogWarning(SC_ERR_INVALID_VALUE, "attempt to access element out of hash array\n");
+ return NULL;
+ }
+
if (ht->array[hash] == NULL)
return NULL;