]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
rec: check bounds of rcode stats counter index (safe right now)
authorOtto Moerbeek <otto.moerbeek@open-xchange.com>
Tue, 11 Feb 2025 09:19:29 +0000 (10:19 +0100)
committerOtto Moerbeek <otto.moerbeek@open-xchange.com>
Tue, 11 Feb 2025 09:35:20 +0000 (10:35 +0100)
Safe right now as LWResult::d_rcode gets assigned from the 4 bit
rcode in the header.  But that might change one day. I'd rather
make LWResult::d_rcode an uint8_t, but that causes a conflict with
the OOB resolving code that does not make a difference between res
and d_rcode.

pdns/recursordist/lwres.hh
pdns/recursordist/rec-tcounters.hh
pdns/recursordist/syncres.cc

index 58d43535e32c5e9540a991731a31c12ce82ec653..3b2bc43a1d0209b2f9fdae0f4a1b928319c06ffc 100644 (file)
@@ -79,10 +79,10 @@ public:
   }
 
   vector<DNSRecord> d_records;
+  uint32_t d_usec{0};
   int d_rcode{0};
   bool d_validpacket{false};
   bool d_aabit{false}, d_tcbit{false};
-  uint32_t d_usec{0};
   bool d_haveEDNS{false};
 };
 
index 80f7e41353d20a1eaa7210268baec3330a74ea42..feeba0d6ab4ee7ac0d4c299e6c33829a65286e25 100644 (file)
@@ -195,8 +195,8 @@ struct Counters
       }
       return *this;
     }
-    static const size_t numberoOfRCodes = 16;
-    std::array<uint64_t, numberoOfRCodes> rcodeCounters;
+    static const size_t numberOfRCodes = 16;
+    std::array<uint64_t, numberOfRCodes> rcodeCounters;
   };
   // An RCodes histogram
   RCodeCounters auth{};
index 3e4f5a941d65a5efb4ebf39936907a0c5032a40d..fd16be3007772d457681b80d784be68a474985f3 100644 (file)
@@ -5552,7 +5552,9 @@ bool SyncRes::doResolveAtThisIP(const std::string& prefix, const DNSName& qname,
   }
 
   accountAuthLatency(lwr.d_usec, remoteIP.sin4.sin_family);
-  ++t_Counters.at(rec::RCode::auth).rcodeCounters.at(static_cast<uint8_t>(lwr.d_rcode));
+  if (lwr.d_rcode >= 0 && lwr.d_rcode < static_cast<decltype(lwr.d_rcode)>(rec::Counters::RCodeCounters::numberOfRCodes)) {
+    ++t_Counters.at(rec::RCode::auth).rcodeCounters.at(static_cast<uint8_t>(lwr.d_rcode));
+  }
 
   if (!dontThrottle) {
     dontThrottle = shouldNotThrottle(&nsName, &remoteIP);