Hash table: check hash array size when inserting element

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.
pull/3104/head
Pierre Chifflier 11 years ago committed by Victor Julien
parent 3bf098e52f
commit bf166420fa

@ -125,6 +125,11 @@ int HashTableAdd(HashTable *ht, void *data, uint16_t datalen)
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 {
@ -192,6 +197,11 @@ void *HashTableLookup(HashTable *ht, void *data, uint16_t datalen)
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;

Loading…
Cancel
Save