]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
dnsdist: Raise the number of entries in a packet cache to at least 1 11546/head
authorRemi Gacogne <remi.gacogne@powerdns.com>
Fri, 15 Apr 2022 10:46:44 +0000 (12:46 +0200)
committerRemi Gacogne <remi.gacogne@powerdns.com>
Fri, 15 Apr 2022 10:46:44 +0000 (12:46 +0200)
And make sure that we cannot create such an object.

pdns/dnsdist-cache.cc
pdns/dnsdistdist/dnsdist-lua-bindings-packetcache.cc

index cdf02ad7626900824d37fc151261118a1863c8df..d6b99a079006d18bb5da7ac7313a79e4325c2454 100644 (file)
 
 DNSDistPacketCache::DNSDistPacketCache(size_t maxEntries, uint32_t maxTTL, uint32_t minTTL, uint32_t tempFailureTTL, uint32_t maxNegativeTTL, uint32_t staleTTL, bool dontAge, uint32_t shards, bool deferrableInsertLock, bool parseECS): d_maxEntries(maxEntries), d_shardCount(shards), d_maxTTL(maxTTL), d_tempFailureTTL(tempFailureTTL), d_maxNegativeTTL(maxNegativeTTL), d_minTTL(minTTL), d_staleTTL(staleTTL), d_dontAge(dontAge), d_deferrableInsertLock(deferrableInsertLock), d_parseECS(parseECS)
 {
+  if (d_maxEntries == 0) {
+    throw std::runtime_error("Trying to create a 0-sized packet-cache");
+  }
+
   d_shards.resize(d_shardCount);
 
   /* we reserve maxEntries + 1 to avoid rehashing from occurring
index b77cd7f204920e41fd7e3b59335fcbc8216f95f5..892de27f121d446b71b9f031fb7763b9795d1423 100644 (file)
@@ -101,6 +101,12 @@ void setupLuaBindingsPacketCache(LuaContext& luaCtx, bool client)
         }
       }
 
+      if (maxEntries == 0) {
+        warnlog("The number of entries in the packet cache is set to 0, raising to 1");
+        g_outputBuffer += "The number of entries in the packet cache is set to 0, raising to 1";
+        maxEntries = 1;
+      }
+
       if (maxEntries < numberOfShards) {
         warnlog("The number of entries (%d) in the packet cache is smaller than the number of shards (%d), decreasing the number of shards to %d", maxEntries, numberOfShards, maxEntries);
         g_outputBuffer += "The number of entries (" + std::to_string(maxEntries) + " in the packet cache is smaller than the number of shards (" + std::to_string(numberOfShards) + "), decreasing the number of shards to " + std::to_string(maxEntries);