2
0
mirror of https://gitlab.isc.org/isc-projects/bind9 synced 2025-08-29 13:38:26 +00:00

Fix off-by-one error when calculating new hashtable size

When calculating the new hashtable bitsize, there was an off-by-one
error that would allow the new bitsize to be larger than maximum allowed
causing assertion failure in the rehash() function.
This commit is contained in:
Ondřej Surý 2020-08-28 09:30:29 +02:00
parent 25d35029eb
commit 78543ad5a7

View File

@ -2330,10 +2330,9 @@ inithash(dns_rbt_t *rbt) {
static uint32_t static uint32_t
rehash_bits(dns_rbt_t *rbt, size_t newcount) { rehash_bits(dns_rbt_t *rbt, size_t newcount) {
uint32_t oldbits = rbt->hashbits; uint32_t newbits = rbt->hashbits;
uint32_t newbits = oldbits;
while (newcount >= HASHSIZE(newbits) && newbits <= rbt->maxhashbits) { while (newcount >= HASHSIZE(newbits) && newbits < rbt->maxhashbits) {
newbits += 1; newbits += 1;
} }
@ -2380,7 +2379,7 @@ rehash(dns_rbt_t *rbt, uint32_t newbits) {
static void static void
maybe_rehash(dns_rbt_t *rbt, size_t newcount) { maybe_rehash(dns_rbt_t *rbt, size_t newcount) {
uint32_t newbits = rehash_bits(rbt, newcount); uint32_t newbits = rehash_bits(rbt, newcount);
if (rbt->hashbits < newbits && newbits <= RBT_HASH_MAX_BITS) { if (rbt->hashbits < newbits && newbits <= rbt->maxhashbits) {
rehash(rbt, newbits); rehash(rbt, newbits);
} }
} }