]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
dnsdist: Prevent reading an uninitialized rcode in cache inspection
authorRemi Gacogne <remi.gacogne@powerdns.com>
Tue, 29 Mar 2022 11:25:04 +0000 (13:25 +0200)
committerRemi Gacogne <remi.gacogne@powerdns.com>
Thu, 22 Sep 2022 13:07:22 +0000 (15:07 +0200)
Entries smaller than a dnsheader should not make it into the cache
anyway, but better safe than sorry.

pdns/dnsdist-cache.cc

index b884df5002ea6ded0601ccf81ae27bf0e97a7cb2..1da937ea539711ea8ec6d8f8fdd8b7f652ce772f 100644 (file)
@@ -502,9 +502,11 @@ std::set<DNSName> DNSDistPacketCache::getDomainsContainingRecords(const ComboAdd
 
       try {
         dnsheader dh;
-        if (value.len >= sizeof(dnsheader)) {
-          memcpy(&dh, value.value.data(), sizeof(dnsheader));
+        if (value.len < sizeof(dnsheader)) {
+          continue;
         }
+
+        memcpy(&dh, value.value.data(), sizeof(dnsheader));
         if (dh.rcode != RCode::NoError || (dh.ancount == 0 && dh.nscount == 0 && dh.arcount == 0)) {
           continue;
         }
@@ -563,9 +565,11 @@ std::set<ComboAddress> DNSDistPacketCache::getRecordsForDomain(const DNSName& do
         }
 
         dnsheader dh;
-        if (value.len >= sizeof(dnsheader)) {
-          memcpy(&dh, value.value.data(), sizeof(dnsheader));
+        if (value.len < sizeof(dnsheader)) {
+          continue;
         }
+
+        memcpy(&dh, value.value.data(), sizeof(dnsheader));
         if (dh.rcode != RCode::NoError || (dh.ancount == 0 && dh.nscount == 0 && dh.arcount == 0)) {
           continue;
         }