From: Otto Moerbeek Date: Wed, 28 Sep 2022 09:58:56 +0000 (+0200) Subject: Fix store_truncates_time_t coverity reports. X-Git-Tag: rec-4.9.0-alpha0~10^2~1 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=56b827c5d91b335c753d45694a4909e1d480785b;p=thirdparty%2Fpdns.git Fix store_truncates_time_t coverity reports. 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 --- diff --git a/pdns/dnscrypt.cc b/pdns/dnscrypt.cc index 3a627c8902..539789fdff 100644 --- a/pdns/dnscrypt.cc +++ b/pdns/dnscrypt.cc @@ -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; diff --git a/pdns/dnscrypt.hh b/pdns/dnscrypt.hh index ff4d94c466..356b4c47d4 100644 --- a/pdns/dnscrypt.hh +++ b/pdns/dnscrypt.hh @@ -119,6 +119,7 @@ public: } bool isValid(time_t now) const { + // coverity[store_truncates_time_t] return ntohl(getTSStart()) <= static_cast(now) && static_cast(now) <= ntohl(getTSEnd()); } unsigned char magic[DNSCRYPT_CERT_MAGIC_SIZE]; diff --git a/pdns/dnsdist-cache.cc b/pdns/dnsdist-cache.cc index 7222a29162..c951d7f485 100644 --- a/pdns/dnsdist-cache.cc +++ b/pdns/dnsdist-cache.cc @@ -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(&response[0]), response.size(), age); } else { diff --git a/pdns/dnsdist-protobuf.cc b/pdns/dnsdist-protobuf.cc index 571d8776f2..7dfd0648cb 100644 --- a/pdns/dnsdist-protobuf.cc +++ b/pdns/dnsdist-protobuf.cc @@ -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 { diff --git a/pdns/dnsdist.cc b/pdns/dnsdist.cc index dc67be5ff8..7cc858474d 100644 --- a/pdns/dnsdist.cc +++ b/pdns/dnsdist.cc @@ -1899,6 +1899,7 @@ static void secPollThread() } catch(...) { } + // coverity[store_truncates_time_t] sleep(g_secPollInterval); } } diff --git a/pdns/dnsdistdist/dnsdist-dynblocks.cc b/pdns/dnsdistdist/dnsdist-dynblocks.cc index 75f6d688b4..d6d84c0b99 100644 --- a/pdns/dnsdistdist/dnsdist-dynblocks.cc +++ b/pdns/dnsdistdist/dnsdist-dynblocks.cc @@ -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 { diff --git a/pdns/dnsdistdist/dnsdist-rules.hh b/pdns/dnsdistdist/dnsdist-rules.hh index 92b1a150aa..d43f9dbfd6 100644 --- a/pdns/dnsdistdist/dnsdist-rules.hh +++ b/pdns/dnsdistdist/dnsdist-rules.hh @@ -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; } } diff --git a/pdns/ednscookies.cc b/pdns/ednscookies.cc index 5992b13f86..501f0b84f2 100644 --- a/pdns/ednscookies.cc +++ b/pdns/ednscookies.cc @@ -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(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(time(nullptr))); server += string(reinterpret_cast(&now), sizeof(now)); server.resize(8);