From: Remi Gacogne Date: Tue, 28 Jun 2022 08:32:01 +0000 (+0200) Subject: dnsdist: Fix a bug in SetEDNSOptionAction X-Git-Tag: dnsdist-1.8.0-rc1~290^2~6 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=0d6d240e56629b522e486520171f4f043b2db3c9;p=thirdparty%2Fpdns.git dnsdist: Fix a bug in SetEDNSOptionAction The DNS parser has already converted the "TTL" of the OPT record to the host byte order before providing to us, and unfortunately we do not want that for the meta-OPT record, where the TTL is used to encode the extended rcode, the EDNS version and the DO bits, amongst other things. In other places we do parse the TTL from the DNS payload ourselves and thus do not need to worry about that conversion, but here we need to convert the value back to the network byte order. --- diff --git a/pdns/dnsdist-ecs.cc b/pdns/dnsdist-ecs.cc index e4e3bd6e8b..6fec7240c6 100644 --- a/pdns/dnsdist-ecs.cc +++ b/pdns/dnsdist-ecs.cc @@ -240,9 +240,11 @@ bool slowRewriteEDNSOptionInQueryWithRecords(const PacketBuffer& initialPacket, std::vector> options; getEDNSOptionsFromContent(blob, options); + /* getDnsrecordheader() has helpfully converted the TTL for us, which we do not want in that case */ + uint32_t ttl = htonl(ah.d_ttl); EDNS0Record edns0; - static_assert(sizeof(edns0) == sizeof(ah.d_ttl), "sizeof(EDNS0Record) must match sizeof(uint32_t) AKA RR TTL size"); - memcpy(&edns0, &ah.d_ttl, sizeof(edns0)); + static_assert(sizeof(edns0) == sizeof(ttl), "sizeof(EDNS0Record) must match sizeof(uint32_t) AKA RR TTL size"); + memcpy(&edns0, &ttl, sizeof(edns0)); /* addOrReplaceEDNSOption will set it to false if there is already an existing option */ optionAdded = true;