From 2f230033794fafdf10822568e763d4db68cf6c6b Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sat, 13 Apr 2024 23:14:49 +0200 Subject: Merging upstream version 1.9.3. Signed-off-by: Daniel Baumann --- dnsdist-cache.cc | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) (limited to 'dnsdist-cache.cc') diff --git a/dnsdist-cache.cc b/dnsdist-cache.cc index 7ca9be2..86c900b 100644 --- a/dnsdist-cache.cc +++ b/dnsdist-cache.cc @@ -119,9 +119,10 @@ void DNSDistPacketCache::insertLocked(CacheShard& shard, std::unordered_map& subnet, uint16_t queryFlags, bool dnssecOK, const DNSName& qname, uint16_t qtype, uint16_t qclass, const PacketBuffer& response, bool receivedOverUDP, uint8_t rcode, boost::optional tempFailureTTL) { - if (response.size() < sizeof(dnsheader)) { + if (response.size() < sizeof(dnsheader) || response.size() > getMaximumEntrySize()) { return; } + if (qtype == QType::AXFR || qtype == QType::IXFR) { return; } @@ -252,7 +253,7 @@ bool DNSDistPacketCache::get(DNSQuestion& dq, uint16_t queryId, uint32_t* keyOut } /* check for collision */ - if (!cachedValueMatches(value, *(getFlagsFromDNSHeader(dq.getHeader())), dq.ids.qname, dq.ids.qtype, dq.ids.qclass, receivedOverUDP, dnssecOK, subnet)) { + if (!cachedValueMatches(value, *(getFlagsFromDNSHeader(dq.getHeader().get())), dq.ids.qname, dq.ids.qtype, dq.ids.qclass, receivedOverUDP, dnssecOK, subnet)) { ++d_lookupCollisions; return false; } @@ -472,12 +473,12 @@ uint64_t DNSDistPacketCache::getEntriesCount() uint64_t DNSDistPacketCache::dump(int fd) { - auto fp = std::unique_ptr(fdopen(dup(fd), "w"), fclose); - if (fp == nullptr) { + auto filePtr = pdns::UniqueFilePtr(fdopen(dup(fd), "w")); + if (filePtr == nullptr) { return 0; } - fprintf(fp.get(), "; dnsdist's packet cache dump follows\n;\n"); + fprintf(filePtr.get(), "; dnsdist's packet cache dump follows\n;\n"); uint64_t count = 0; time_t now = time(nullptr); @@ -496,10 +497,10 @@ uint64_t DNSDistPacketCache::dump(int fd) rcode = dh.rcode; } - fprintf(fp.get(), "%s %" PRId64 " %s ; rcode %" PRIu8 ", key %" PRIu32 ", length %" PRIu16 ", received over UDP %d, added %" PRId64 "\n", value.qname.toString().c_str(), static_cast(value.validity - now), QType(value.qtype).toString().c_str(), rcode, entry.first, value.len, value.receivedOverUDP, static_cast(value.added)); + fprintf(filePtr.get(), "%s %" PRId64 " %s ; rcode %" PRIu8 ", key %" PRIu32 ", length %" PRIu16 ", received over UDP %d, added %" PRId64 "\n", value.qname.toString().c_str(), static_cast(value.validity - now), QType(value.qtype).toString().c_str(), rcode, entry.first, value.len, static_cast(value.receivedOverUDP), static_cast(value.added)); } catch(...) { - fprintf(fp.get(), "; error printing '%s'\n", value.qname.empty() ? "EMPTY" : value.qname.toString().c_str()); + fprintf(filePtr.get(), "; error printing '%s'\n", value.qname.empty() ? "EMPTY" : value.qname.toString().c_str()); } } } @@ -620,3 +621,8 @@ std::set DNSDistPacketCache::getRecordsForDomain(const DNSName& do return addresses; } + +void DNSDistPacketCache::setMaximumEntrySize(size_t maxSize) +{ + d_maximumEntrySize = maxSize; +} -- cgit v1.2.3