]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
dnsdist: Fix a bug in SetEDNSOptionAction
authorRemi Gacogne <remi.gacogne@powerdns.com>
Tue, 28 Jun 2022 08:32:01 +0000 (10:32 +0200)
committerRemi Gacogne <remi.gacogne@powerdns.com>
Sat, 2 Jul 2022 12:17:54 +0000 (14:17 +0200)
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.

pdns/dnsdist-ecs.cc

index e4e3bd6e8bd5b0ba4ba6819b26ed030e84ee55d8..6fec7240c6f79b034ba920693b1102117b976fe5 100644 (file)
@@ -240,9 +240,11 @@ bool slowRewriteEDNSOptionInQueryWithRecords(const PacketBuffer& initialPacket,
       std::vector<std::pair<uint16_t, std::string>> 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;