2
0
mirror of https://gitlab.isc.org/isc-projects/bind9 synced 2025-08-31 14:35:26 +00:00

Fix the assertion failure in the isc_hashmap iterator

When the round robin hashing reorders the map entries on deletion, we
were adjusting the iterator table size only when the reordering was
happening at the internal table boundary.  The iterator table size had
to be reduced by one to prevent seeing the entry that resized on
position [0] twice because it migrated to [iter->size - 1] position.

However, the same thing could happen when the same entry migrates a
second time from [iter->size - 1] to [iter->size - 2] position (and so
on) because the check that we are manipulating the entry just in the [0]
position was insufficient.  Instead of checking the position [pos == 0],
we now check that the [pos % iter->size == 0], thus ignoring all the
entries that might have moved back to the end of the internal table.
This commit is contained in:
Ondřej Surý
2024-08-12 15:17:00 +02:00
parent 482eed2e31
commit acdc57259f

View File

@@ -310,7 +310,8 @@ isc_hashmap_find(const isc_hashmap_t *hashmap, const uint32_t hashval,
static bool
hashmap_delete_node(isc_hashmap_t *hashmap, hashmap_node_t *entry,
uint32_t hashval, uint32_t psl, const uint8_t idx) {
uint32_t hashval, uint32_t psl, const uint8_t idx,
size_t size) {
uint32_t pos;
uint32_t hash;
bool last = false;
@@ -318,7 +319,7 @@ hashmap_delete_node(isc_hashmap_t *hashmap, hashmap_node_t *entry,
hashmap->count--;
hash = isc_hash_bits32(hashval, hashmap->tables[idx].hashbits);
pos = hash + psl;
pos = (hash + psl) & hashmap->tables[idx].hashmask;
while (true) {
hashmap_node_t *node = NULL;
@@ -332,7 +333,7 @@ hashmap_delete_node(isc_hashmap_t *hashmap, hashmap_node_t *entry,
break;
}
if (pos == 0) {
if ((pos % size) == 0) {
last = true;
}
@@ -373,7 +374,7 @@ hashmap_rehash_one(isc_hashmap_t *hashmap) {
node = oldtable[hashmap->hiter];
(void)hashmap_delete_node(hashmap, &oldtable[hashmap->hiter],
node.hashval, node.psl, oldidx);
node.hashval, node.psl, oldidx, UINT32_MAX);
isc_result_t result = hashmap_add(hashmap, node.hashval, NULL, node.key,
node.value, NULL, hashmap->hindex);
@@ -470,7 +471,8 @@ isc_hashmap_delete(isc_hashmap_t *hashmap, const uint32_t hashval,
node = hashmap_find(hashmap, hashval, match, key, &psl, &idx);
if (node != NULL) {
INSIST(node->key != NULL);
(void)hashmap_delete_node(hashmap, node, hashval, psl, idx);
(void)hashmap_delete_node(hashmap, node, hashval, psl, idx,
UINT32_MAX);
result = ISC_R_SUCCESS;
}
@@ -682,7 +684,7 @@ isc_hashmap_iter_delcurrent_next(isc_hashmap_iter_t *iter) {
&iter->hashmap->tables[iter->hindex].table[iter->i];
if (hashmap_delete_node(iter->hashmap, node, node->hashval, node->psl,
iter->hindex))
iter->hindex, iter->size))
{
/*
* We have seen the new last element so reduce the size