From: Remi Gacogne Date: Wed, 3 Mar 2021 09:33:12 +0000 (+0100) Subject: dnsdist: Prevent an infinite loop when a cache shard is below the limit X-Git-Tag: dnsdist-1.6.0-alpha2~1^2~3 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=af9f7f64eef86dfe7d438ff418969c86a37c5fa7;p=thirdparty%2Fpdns.git dnsdist: Prevent an infinite loop when a cache shard is below the limit --- diff --git a/pdns/dnsdist-cache.cc b/pdns/dnsdist-cache.cc index 8bb38c2ff7..a5a3865662 100644 --- a/pdns/dnsdist-cache.cc +++ b/pdns/dnsdist-cache.cc @@ -305,6 +305,7 @@ size_t DNSDistPacketCache::purgeExpired(size_t upTo, const time_t now) do { uint32_t shardIndex = (d_expungeIndex++ % d_shardCount); + scannedMaps++; WriteLock w(&d_shards.at(shardIndex).d_lock); auto& map = d_shards.at(shardIndex).d_map; @@ -325,8 +326,6 @@ size_t DNSDistPacketCache::purgeExpired(size_t upTo, const time_t now) ++it; } } - - scannedMaps++; } while (scannedMaps < d_shardCount); diff --git a/pdns/test-dnsdistpacketcache_cc.cc b/pdns/test-dnsdistpacketcache_cc.cc index c39a304d11..3ac48628aa 100644 --- a/pdns/test-dnsdistpacketcache_cc.cc +++ b/pdns/test-dnsdistpacketcache_cc.cc @@ -112,6 +112,9 @@ BOOST_AUTO_TEST_CASE(test_PacketCacheSimple) { auto removed = PC.expungeByName(DNSName(" hello"), QType::ANY, true); BOOST_CHECK_EQUAL(PC.getSize(), 0U); BOOST_CHECK_EQUAL(removed, remaining); + + /* nothing to remove */ + BOOST_CHECK_EQUAL(PC.purgeExpired(0, now), 0U); } catch (const PDNSException& e) { cerr<<"Had error: "<