]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
Coverity reports of time_t truncation, all because of protocol uses unsigned 32 bit...
authorOtto Moerbeek <otto.moerbeek@open-xchange.com>
Wed, 21 Sep 2022 07:41:24 +0000 (09:41 +0200)
committerOtto Moerbeek <otto.moerbeek@open-xchange.com>
Wed, 21 Sep 2022 07:41:24 +0000 (09:41 +0200)
Coverity 149824914912731491268149126714912661491265

pdns/dnssecinfra.cc
pdns/protozero.hh
pdns/rcpgenerator.cc
pdns/recursor_cache.cc

index 95693838ea63c369faf5e83fac138edd280089d4..ef12e9826cbcbd12286ff6b77dee09dc8e4cbeda 100644 (file)
@@ -519,6 +519,7 @@ static DNSKEYRecordContent makeDNSKEYFromDNSCryptoKeyEngine(const std::shared_pt
 
 uint32_t getStartOfWeek()
 {
+  // coverity[store_truncated_time_t]
   uint32_t now = time(nullptr);
   now -= (now % (7*86400));
   return now;
index 4b3438d85bb0fdbf0ffb7dac0903b613cbe73993..ecdec1d55ad31e62ee274498ef4fcb9ca23cf628 100644 (file)
@@ -108,6 +108,7 @@ namespace pdns {
 
       void setTime(time_t sec, uint32_t usec)
       {
+        // coverity[store_truncated_time_t]
         add_uint32(d_message, Field::timeSec, sec);
         add_uint32(d_message, Field::timeUsec, usec);
       }
index 3d3dd073ff2a19388badd49e17d33284eafc8e34..4d54f23f6b4d8a67ce776ae98f11085e4dc4064b 100644 (file)
@@ -123,6 +123,7 @@ void RecordTextReader::xfrTime(uint32_t &val)
 
   tm.tm_year-=1900;
   tm.tm_mon-=1;
+  // coverity[store_truncated_time_t]
   val=(uint32_t)Utility::timegm(&tm);
 }
 
index 1420279bc48cddd601f6f4b208eb86dc685589d6..22e7bff2b270d7f0685e023774bffc2326612722 100644 (file)
@@ -158,7 +158,8 @@ time_t MemRecursorCache::handleHit(MapCombo::LockedContent& content, MemRecursor
       dr.d_type = entry->d_qtype;
       dr.d_class = QClass::IN;
       dr.d_content = k;
-      dr.d_ttl = static_cast<uint32_t>(entry->d_ttd); // XXX truncation
+      // coverity[store_truncated_time_t]
+      dr.d_ttl = static_cast<uint32_t>(entry->d_ttd);
       dr.d_place = DNSResourceRecord::ANSWER;
       res->push_back(std::move(dr));
     }
@@ -327,6 +328,7 @@ time_t MemRecursorCache::fakeTTD(MemRecursorCache::OrderedTagIterator_t& entry,
   }
   if (ttl > 0 && SyncRes::s_refresh_ttlperc > 0) {
     const uint32_t deadline = origTTL * SyncRes::s_refresh_ttlperc / 100;
+    // coverity[store_truncated_time_t]
     const bool almostExpired = static_cast<uint32_t>(ttl) <= deadline;
     if (almostExpired && qname != g_rootdnsname) {
       if (refresh) {
@@ -511,6 +513,7 @@ bool MemRecursorCache::CacheEntry::shouldReplace(time_t now, bool auth, vState s
     const time_t ttl = d_ttd - now;
     const uint32_t lockline = d_orig_ttl * percentage / 100;
     // We know ttl is > 0 as d_ttd > now
+    // coverity[store_truncated_time_t]
     const bool locked = static_cast<uint32_t>(ttl) > lockline;
     if (locked) {
       return false;