File 0001-Fix-off-by-one-error-when-calculating-new-hashtable.patch of Package bind.20642
From 2b08ff879a445584ca39201523c161048f4c79cd Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Ond=C5=99ej=20Sur=C3=BD?= <ondrej@sury.org>
Date: Fri, 28 Aug 2020 09:30:29 +0200
Subject: [PATCH] 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.
(cherry picked from commit 78543ad5a7731e5f3a309c73e90a552df1a44af1)
---
lib/dns/rbt.c | 7 +++----
1 file changed, 3 insertions(+), 4 deletions(-)
diff --git a/lib/dns/rbt.c b/lib/dns/rbt.c
index ab5453e78c..69b847c6d1 100644
--- a/lib/dns/rbt.c
+++ b/lib/dns/rbt.c
@@ -2331,10 +2331,9 @@ inithash(dns_rbt_t *rbt) {
static uint32_t
rehash_bits(dns_rbt_t *rbt, size_t newcount) {
- uint32_t oldbits = rbt->hashbits;
- uint32_t newbits = oldbits;
+ uint32_t newbits = rbt->hashbits;
- while (newcount >= HASHSIZE(newbits) && newbits <= rbt->maxhashbits) {
+ while (newcount >= HASHSIZE(newbits) && newbits < rbt->maxhashbits) {
newbits += 1;
}
@@ -2381,7 +2380,7 @@ rehash(dns_rbt_t *rbt, uint32_t newbits) {
static void
maybe_rehash(dns_rbt_t *rbt, size_t 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);
}
}
--
2.26.2