From: Otto Moerbeek Date: Wed, 21 Sep 2022 07:41:24 +0000 (+0200) Subject: Coverity reports of time_t truncation, all because of protocol uses unsigned 32 bit... X-Git-Tag: rec-4.8.0-alpha1^2~1 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=ced61da951936102b26bbcf4716ddfce8733f17d;p=thirdparty%2Fpdns.git Coverity reports of time_t truncation, all because of protocol uses unsigned 32 bit time Coverity 1498249, 1491273, 1491268, 1491267, 1491266, 1491265 --- diff --git a/pdns/dnssecinfra.cc b/pdns/dnssecinfra.cc index 95693838ea..ef12e9826c 100644 --- a/pdns/dnssecinfra.cc +++ b/pdns/dnssecinfra.cc @@ -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; diff --git a/pdns/protozero.hh b/pdns/protozero.hh index 4b3438d85b..ecdec1d55a 100644 --- a/pdns/protozero.hh +++ b/pdns/protozero.hh @@ -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); } diff --git a/pdns/rcpgenerator.cc b/pdns/rcpgenerator.cc index 3d3dd073ff..4d54f23f6b 100644 --- a/pdns/rcpgenerator.cc +++ b/pdns/rcpgenerator.cc @@ -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); } diff --git a/pdns/recursor_cache.cc b/pdns/recursor_cache.cc index 1420279bc4..22e7bff2b2 100644 --- a/pdns/recursor_cache.cc +++ b/pdns/recursor_cache.cc @@ -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(entry->d_ttd); // XXX truncation + // coverity[store_truncated_time_t] + dr.d_ttl = static_cast(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(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(ttl) > lockline; if (locked) { return false;