From 6de06c8ea9053eaa08140ab19327c917a94b78ce Mon Sep 17 00:00:00 2001 From: Remi Gacogne Date: Fri, 29 Oct 2021 15:10:03 +0200 Subject: [PATCH] dnsdist: Only update 'ednsAdded' and 'optionAdded' if we process the query --- pdns/dnsdist-ecs.cc | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/pdns/dnsdist-ecs.cc b/pdns/dnsdist-ecs.cc index 0eda3ab993..e4e3bd6e8b 100644 --- a/pdns/dnsdist-ecs.cc +++ b/pdns/dnsdist-ecs.cc @@ -154,9 +154,6 @@ bool slowRewriteEDNSOptionInQueryWithRecords(const PacketBuffer& initialPacket, assert(initialPacket.size() >= sizeof(dnsheader)); const struct dnsheader* dh = reinterpret_cast(initialPacket.data()); - optionAdded = false; - ednsAdded = true; - if (ntohs(dh->qdcount) == 0) { return false; } @@ -165,6 +162,9 @@ bool slowRewriteEDNSOptionInQueryWithRecords(const PacketBuffer& initialPacket, throw std::runtime_error(std::string(__PRETTY_FUNCTION__) + " should not be called for queries that have no records"); } + optionAdded = false; + ednsAdded = true; + PacketReader pr(pdns_string_view(reinterpret_cast(initialPacket.data()), initialPacket.size())); size_t idx = 0; @@ -589,8 +589,6 @@ bool handleEDNSClientSubnet(PacketBuffer& packet, const size_t maximumSize, cons newContent.reserve(packet.size()); if (!slowRewriteEDNSOptionInQueryWithRecords(packet, newContent, ednsAdded, EDNSOptionCode::ECS, ecsAdded, overrideExisting, newECSOption)) { - ednsAdded = false; - ecsAdded = false; return false; } -- 2.47.2