From: Otto Moerbeek Date: Tue, 5 Nov 2024 12:07:07 +0000 (+0100) Subject: rec: don't drop partial result on exception in cache lookup X-Git-Tag: rec-5.2.0-alpha1~4^2~1 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=7dc3324bc150595f7278817c0c5e7709d0fe6995;p=thirdparty%2Fpdns.git rec: don't drop partial result on exception in cache lookup Fixes #14310 Should be checked for unwanted side-effects, which is pretty tricky. --- diff --git a/pdns/recursordist/syncres.cc b/pdns/recursordist/syncres.cc index 753ed5a553..9951f91a50 100644 --- a/pdns/recursordist/syncres.cc +++ b/pdns/recursordist/syncres.cc @@ -1721,22 +1721,22 @@ int SyncRes::doResolve(const DNSName& qname, const QType qtype, vector retq; bool old = setCacheOnly(true); bool fromCache = false; // For cache peeking, we tell doResolveNoQNameMinimization not to consider the (non-recursive) forward case. // Otherwise all queries in a forward domain will be forwarded, while we want to consult the cache. - int res = doResolveNoQNameMinimization(qname, qtype, retq, depth, beenthere, context, &fromCache, nullptr); + const auto retSizeBeforeCall = ret.size(); + int res = doResolveNoQNameMinimization(qname, qtype, ret, depth, beenthere, context, &fromCache, nullptr); setCacheOnly(old); if (fromCache) { LOG(prefix << qname << ": Step0 Found in cache" << endl); if (d_appliedPolicy.d_type != DNSFilterEngine::PolicyType::None && (d_appliedPolicy.d_kind == DNSFilterEngine::PolicyKind::NXDOMAIN || d_appliedPolicy.d_kind == DNSFilterEngine::PolicyKind::NODATA)) { ret.clear(); } - ret.insert(ret.end(), retq.begin(), retq.end()); - return res; } + // Erase unwanted cache lookup preliminary results in the returned records + ret.resize(retSizeBeforeCall); LOG(prefix << qname << ": Step0 Not cached" << endl); const unsigned int qnamelen = qname.countLabels(); @@ -1833,7 +1833,7 @@ int SyncRes::doResolve(const DNSName& qname, const QType qtype, vector retq; StopAtDelegation stopAtDelegation = Stop; res = doResolveNoQNameMinimization(child, QType::A, retq, depth, beenthere, context, nullptr, &stopAtDelegation); d_followCNAME = oldFollowCNAME;