]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
Fix store_truncates_time_t coverity reports.
authorOtto Moerbeek <otto.moerbeek@open-xchange.com>
Wed, 28 Sep 2022 09:58:56 +0000 (11:58 +0200)
committerOtto Moerbeek <otto.moerbeek@open-xchange.com>
Wed, 28 Sep 2022 10:15:51 +0000 (12:15 +0200)
A few instances of store_truncates_time_t, almost all due to DNS specific protocol properties

Coverity 380097, 380099, 380100, 380101, 380105, 380108, 380114, 380115, 380116, 380118

pdns/dnscrypt.cc
pdns/dnscrypt.hh
pdns/dnsdist-cache.cc
pdns/dnsdist-protobuf.cc
pdns/dnsdist.cc
pdns/dnsdistdist/dnsdist-dynblocks.cc
pdns/dnsdistdist/dnsdist-rules.hh
pdns/ednscookies.cc

index 3a627c890250717ed3b5114a2740dc6afcf4c60e..539789fdff6e98b7853e85a3af50b99869d21137 100644 (file)
@@ -215,7 +215,9 @@ void DNSCryptContext::generateCertificate(uint32_t serial, time_t begin, time_t
   memcpy(cert.signedData.resolverPK, pubK, sizeof(cert.signedData.resolverPK));
   memcpy(cert.signedData.clientMagic, pubK, sizeof(cert.signedData.clientMagic));
   cert.signedData.serial = htonl(serial);
+  // coverity[store_truncates_time_t]
   cert.signedData.tsStart = htonl((uint32_t) begin);
+  // coverity[store_truncates_time_t]
   cert.signedData.tsEnd = htonl((uint32_t) end);
 
   unsigned long long signatureSize = 0;
index ff4d94c4663965861c140ac4218e7253dbd191b3..356b4c47d4c3b810e7726a183e7fd72e1b915f0b 100644 (file)
@@ -119,6 +119,7 @@ public:
   }
   bool isValid(time_t now) const
   {
+    // coverity[store_truncates_time_t]
     return ntohl(getTSStart()) <= static_cast<uint32_t>(now) && static_cast<uint32_t>(now) <= ntohl(getTSEnd());
   }
   unsigned char magic[DNSCRYPT_CERT_MAGIC_SIZE];
index 7222a29162b0e47d897330802fcb62ef8c162673..c951d7f485fd3d8241954df51d6682c6e54de87d 100644 (file)
@@ -275,6 +275,7 @@ bool DNSDistPacketCache::get(DNSQuestion& dq, uint16_t queryId, uint32_t* keyOut
 
   if (!d_dontAge && !skipAging) {
     if (!stale) {
+      // coverity[store_truncates_time_t]
       ageDNSPacket(reinterpret_cast<char *>(&response[0]), response.size(), age);
     }
     else {
index 571d8776f23f357066c9a6d82d6dc42b7f5dbc33..7dfd0648cb428fd136c0c0feee5e2e1f6ade9b8e 100644 (file)
@@ -160,6 +160,7 @@ void DNSDistProtoBufMessage::serialize(std::string& data) const
 
   m.startResponse();
   if (d_queryTime) {
+    // coverity[store_truncates_time_t]
     m.setQueryTime(d_queryTime->first, d_queryTime->second);
   }
   else {
index dc67be5ff87ebd94e83e8687c307dd2bb2261c8e..7cc858474d8663bf1bce6dd9cb0d8592390354e6 100644 (file)
@@ -1899,6 +1899,7 @@ static void secPollThread()
     }
     catch(...) {
     }
+    // coverity[store_truncates_time_t]
     sleep(g_secPollInterval);
   }
 }
index 75f6d688b4c252f8a3262085b00c2939f275ca5b..d6d84c0b9935f4dc449276e51361a4201f2384ca 100644 (file)
@@ -709,6 +709,7 @@ void DynBlockMaintenance::run()
     sleepDelay = std::min(sleepDelay, (nextMetricsCollect - now));
     sleepDelay = std::min(sleepDelay, (nextMetricsGeneration - now));
 
+    // coverity[store_truncates_time_t]
     sleep(sleepDelay);
 
     try {
index 92b1a150aa3e986deceba25f968beda4a97e7ac5..d43f9dbfd6ff066f3eeb8ec2b81b778300635ed8 100644 (file)
@@ -271,6 +271,7 @@ public:
     else {
       auto res = d_ip6s.write_lock()->insert({{ca}, ttd});
       if (!res.second && (time_t)res.first->second < ttd) {
+        // coverity[store_truncates_time_t]
         res.first->second = (uint32_t)ttd;
       }
     }
index 5992b13f86dbad7219781c2c55ecb6fa1bd1b8f7..501f0b84f2b896cb6980cf08c8142b29bd85ca97 100644 (file)
@@ -121,6 +121,7 @@ bool EDNSCookiesOpt::shouldRefresh() const
   uint32_t ts;
   memcpy(&ts, &server[4], sizeof(ts));
   ts = ntohl(ts);
+  // coverity[store_truncates_time_t]
   uint32_t now = static_cast<uint32_t>(time(nullptr));
   // RFC 9018 section 4.3:
   //    The DNS server
@@ -154,6 +155,7 @@ bool EDNSCookiesOpt::makeServerCookie(const string& secret, const ComboAddress&
   server.reserve(16);
   server = "\x01"; // Version
   server.resize(4, '\0'); // 3 reserved bytes
+  // coverity[store_truncates_time_t]
   uint32_t now = htonl(static_cast<uint32_t>(time(nullptr)));
   server += string(reinterpret_cast<const char*>(&now), sizeof(now));
   server.resize(8);