From: Miod Vallat Date: Wed, 1 Jul 2026 09:06:02 +0000 (+0200) Subject: Introduce a symbolic constexpr for maximum label length. NFC X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=6ca877cfbf1facd12710326cbdff54f67ac5355b;p=thirdparty%2Fpdns.git Introduce a symbolic constexpr for maximum label length. NFC Signed-off-by: Miod Vallat --- diff --git a/pdns/dnsname.cc b/pdns/dnsname.cc index 70c3d3e3e9..6efa3771d1 100644 --- a/pdns/dnsname.cc +++ b/pdns/dnsname.cc @@ -96,7 +96,7 @@ DNSName::DNSName(const std::string_view sw) d_storage.append(begiter,iter); if(iter != pend) ++iter; - if(labellen > 63) + if(labellen > s_maxDNSLabelLength) throwSafeRangeError("label too long to append: ", p, length); if(iter-pbegin > static_cast(s_maxDNSNameLength - 1)) // reserve two bytes, one for length and one for the root label @@ -134,7 +134,7 @@ static void checkLabelLength(uint8_t length) if (length == 0) { throw std::range_error("no such thing as an empty label to append"); } - if (length > 63) { + if (length > DNSName::s_maxDNSLabelLength) { throw std::range_error("label too long to append"); } } @@ -361,7 +361,7 @@ bool DNSName::isPartOf(const DNSName& parent) const } return true; } - if (static_cast(*us) > 63) { + if (static_cast(*us) > s_maxDNSLabelLength) { throw std::out_of_range("illegal label length in DNSName"); } } diff --git a/pdns/dnsname.hh b/pdns/dnsname.hh index 2dd3cec651..fae6f1f8ae 100644 --- a/pdns/dnsname.hh +++ b/pdns/dnsname.hh @@ -88,7 +88,8 @@ class ZoneName; class DNSName { public: - static const size_t s_maxDNSNameLength = 255; + static constexpr size_t s_maxDNSNameLength = 255; + static constexpr size_t s_maxDNSLabelLength = 63; DNSName() = default; //!< Constructs an *empty* DNSName, NOT the root! // Work around assertion in some boost versions that do not like self-assignment of boost::container::string