From 0289784e98a58d9a30da74d3b174a685b8e71677 Mon Sep 17 00:00:00 2001 From: Miod Vallat Date: Mon, 4 Aug 2025 15:42:19 +0200 Subject: [PATCH] More uses cases for lookupEnd(). Signed-off-by: Miod Vallat --- pdns/auth-secondarycommunicator.cc | 3 +-- pdns/dnsbackend.cc | 8 ++++---- pdns/rfc2136handler.cc | 11 ++++++----- pdns/ueberbackend.cc | 6 +----- pdns/ws-auth.cc | 4 +--- 5 files changed, 13 insertions(+), 19 deletions(-) diff --git a/pdns/auth-secondarycommunicator.cc b/pdns/auth-secondarycommunicator.cc index 1e1815f495..24b8321f7b 100644 --- a/pdns/auth-secondarycommunicator.cc +++ b/pdns/auth-secondarycommunicator.cc @@ -1319,8 +1319,7 @@ void CommunicatorClass::secondaryRefresh(PacketHandler* P) hasSOA = B->get(zr); if (hasSOA) { fillSOAData(zr, sd); - while (B->get(zr)) - ; + B->lookupEnd(); } } catch (...) { diff --git a/pdns/dnsbackend.cc b/pdns/dnsbackend.cc index 2edbde4ee9..8d46a6f28e 100644 --- a/pdns/dnsbackend.cc +++ b/pdns/dnsbackend.cc @@ -93,7 +93,9 @@ bool DNSBackend::searchRecords(const string& pattern, size_t maxResults, vector< DNSResourceRecord rec; while (get(rec)) { if (maxResults == 0) { - continue; + // No need to look any further + lookupEnd(); + break; } if (simpleMatch.match(rec.qname) || simpleMatch.match(rec.content)) { result.emplace_back(rec); @@ -315,9 +317,7 @@ bool DNSBackend::getSOA(const ZoneName& domain, domainid_t zoneId, SOAData& soaD } } catch (...) { - while (this->get(resourceRecord)) { - ; - } + this->lookupEnd(); throw; } diff --git a/pdns/rfc2136handler.cc b/pdns/rfc2136handler.cc index 80e896d4c8..4dcd444fa9 100644 --- a/pdns/rfc2136handler.cc +++ b/pdns/rfc2136handler.cc @@ -41,8 +41,11 @@ int PacketHandler::checkUpdatePrerequisites(const DNSRecord *rr, DomainInfo *di) while(di->backend->get(rec)) { if (!rec.qtype.getCode()) continue; - if ((rr->d_type != QType::ANY && rec.qtype == rr->d_type) || rr->d_type == QType::ANY) + if ((rr->d_type != QType::ANY && rec.qtype == rr->d_type) || rr->d_type == QType::ANY) { foundRecord=true; + di->backend->lookupEnd(); + break; + } } // Section 3.2.1 @@ -952,8 +955,7 @@ int PacketHandler::processUpdate(DNSPacket& packet) { // NOLINT(readability-func while (di.backend->get(rec)) { if (rec.qtype != QType::CNAME && rec.qtype != QType::ENT && rec.qtype != QType::RRSIG) { // leave database handle in a consistent state - while (di.backend->get(rec)) - ; + di.backend->lookupEnd(); g_log<d_name << "/" << QType(rr->d_type).toString() << ": Data other than CNAME exists for the same name"<abortTransaction(); return RCode::Refused; @@ -967,8 +969,7 @@ int PacketHandler::processUpdate(DNSPacket& packet) { // NOLINT(readability-func while (di.backend->get(rec)) { if (rec.qtype == QType::CNAME && rr->d_type != QType::RRSIG) { // leave database handle in a consistent state - while (di.backend->get(rec)) - ; + di.backend->lookupEnd(); g_log<d_name << "/" << QType(rr->d_type).toString() << ": CNAME exists for the same name"<abortTransaction(); return RCode::Refused; diff --git a/pdns/ueberbackend.cc b/pdns/ueberbackend.cc index 7a835c8b11..064219410f 100644 --- a/pdns/ueberbackend.cc +++ b/pdns/ueberbackend.cc @@ -427,11 +427,7 @@ bool UeberBackend::fillSOAFromZoneRecord(ZoneName& shorter, const domainid_t zon } catch (...) { g_log << Logger::Warning << "Backend returned a broken SOA for zone '" << shorter.toLogString() << "'" << endl; - - while (get(zoneRecord)) { - ; - } - + lookupEnd(); return false; } diff --git a/pdns/ws-auth.cc b/pdns/ws-auth.cc index 47ac61eecd..d9644fcfa1 100644 --- a/pdns/ws-auth.cc +++ b/pdns/ws-auth.cc @@ -2448,9 +2448,7 @@ static void patchZone(UeberBackend& backend, const ZoneName& zonename, DomainInf || exclusiveEntryTypes.count(resourceRecord.qtype.getCode()) != 0)) { // leave database handle in a consistent state - while (domainInfo.backend->get(resourceRecord)) { - ; - } + domainInfo.backend->lookupEnd(); throw ApiException("RRset " + qname.toString() + " IN " + qtype.toString() + ": Conflicts with pre-existing RRset"); } -- 2.47.2