From b0541889168cec62b4567ab889816f6e4b2aff45 Mon Sep 17 00:00:00 2001 From: Otto Date: Wed, 13 Jan 2021 10:18:47 +0100 Subject: [PATCH] As found by coverity, origTTL can be left uninitialized if all the entries found are expired. In that case the loop exits without setting origTTL via handleHit(). --- pdns/recursor_cache.cc | 6 ++++-- pdns/recursor_cache.hh | 2 +- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/pdns/recursor_cache.cc b/pdns/recursor_cache.cc index bc63003ffe..32f6e35738 100644 --- a/pdns/recursor_cache.cc +++ b/pdns/recursor_cache.cc @@ -318,7 +318,7 @@ int32_t MemRecursorCache::get(time_t now, const DNSName &qname, const QType& qt, else { auto entry = getEntryUsingECSIndex(map, now, qname, qtype, requireAuth, who); if (entry != map.d_map.end()) { - int32_t ret = handleHit(map, entry, qname, origTTL, res, signatures, authorityRecs, variable, cachedState, wasAuth, fromAuthZone); + int32_t ret = handleHit(map, entry, qname, origTTL, res, signatures, authorityRecs, variable, cachedState, wasAuth, fromAuthZone); if (state && cachedState) { *state = *cachedState; } @@ -336,6 +336,7 @@ int32_t MemRecursorCache::get(time_t now, const DNSName &qname, const QType& qt, for (auto i=entries.first; i != entries.second; ++i) { firstIndexIterator = map.d_map.project(i); + origTTL = firstIndexIterator->d_orig_ttl; if (i->d_ttd <= now) { moveCacheItemToFront(map.d_map, firstIndexIterator); continue; @@ -365,6 +366,7 @@ int32_t MemRecursorCache::get(time_t now, const DNSName &qname, const QType& qt, for (auto i=entries.first; i != entries.second; ++i) { firstIndexIterator = map.d_map.project(i); + origTTL = firstIndexIterator->d_orig_ttl; if (i->d_ttd <= now) { moveCacheItemToFront(map.d_map, firstIndexIterator); continue; @@ -392,7 +394,7 @@ void MemRecursorCache::replace(time_t now, const DNSName &qname, const QType& qt { auto& map = getMap(qname); const lock l(map); - + map.d_cachecachevalid = false; if (ednsmask) { ednsmask = ednsmask->getNormalized(); diff --git a/pdns/recursor_cache.hh b/pdns/recursor_cache.hh index f9ab3601ae..df46c728d1 100644 --- a/pdns/recursor_cache.hh +++ b/pdns/recursor_cache.hh @@ -75,7 +75,7 @@ private: struct CacheEntry { CacheEntry(const boost::tuple& key, bool auth): - d_qname(key.get<0>()), d_netmask(key.get<3>().getNormalized()), d_rtag(key.get<2>()), d_state(vState::Indeterminate), d_ttd(0), d_qtype(key.get<1>()), d_auth(auth) + d_qname(key.get<0>()), d_netmask(key.get<3>().getNormalized()), d_rtag(key.get<2>()), d_state(vState::Indeterminate), d_ttd(0), d_qtype(key.get<1>()), d_auth(auth), d_submitted(false) { } -- 2.47.2