From: Miod Vallat Date: Fri, 25 Jul 2025 13:00:13 +0000 (+0200) Subject: Do not use countLabels() in chopOff() loop conditions. X-Git-Tag: auth-5.1.0-alpha0^2 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=refs%2Fpull%2F15922%2Fhead;p=thirdparty%2Fpdns.git Do not use countLabels() in chopOff() loop conditions. Instead, compute it once outside of the loop in a local variable and decrement that variable. Signed-off-by: Miod Vallat --- diff --git a/pdns/dnsname.cc b/pdns/dnsname.cc index 4316b3939..dcad68f93 100644 --- a/pdns/dnsname.cc +++ b/pdns/dnsname.cc @@ -632,8 +632,8 @@ unsigned int DNSName::countLabels() const void DNSName::trimToLabels(unsigned int to) { - while(countLabels() > to && chopOff()) { - ; + for (auto nlabels = countLabels(); nlabels > to; --nlabels) { + chopOff(); } } diff --git a/pdns/dnssecinfra.cc b/pdns/dnssecinfra.cc index 53309fbc4..d6826db6c 100644 --- a/pdns/dnssecinfra.cc +++ b/pdns/dnssecinfra.cc @@ -526,7 +526,7 @@ string getMessageForRRSET(const DNSName& qname, const RRSIGRecordContent& rrc, c if (rrsig_labels < fqdn_labels) { DNSName choppedQname(qname); - while (choppedQname.countLabels() > rrsig_labels) { + for (auto nlabels = fqdn_labels; nlabels > rrsig_labels; --nlabels) { choppedQname.chopOff(); } nameToHash = "\x01*" + choppedQname.toDNSStringLC();