]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
Introduce a symbolic constexpr for maximum label length. NFC
authorMiod Vallat <miod.vallat@powerdns.com>
Wed, 1 Jul 2026 09:06:02 +0000 (11:06 +0200)
committerMiod Vallat <miod.vallat@powerdns.com>
Wed, 1 Jul 2026 09:06:02 +0000 (11:06 +0200)
Signed-off-by: Miod Vallat <miod.vallat@powerdns.com>
pdns/dnsname.cc
pdns/dnsname.hh

index 70c3d3e3e9ea1c175977ed4ef9aad15f0f454b7e..6efa3771d1f2121c0ba0fab968b004ca877616fc 100644 (file)
@@ -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<ptrdiff_t>(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<uint8_t>(*us) > 63) {
+    if (static_cast<uint8_t>(*us) > s_maxDNSLabelLength) {
       throw std::out_of_range("illegal label length in DNSName");
     }
   }
index 2dd3cec651316d60a7c84bab265cfd3b128c7212..fae6f1f8ae5a2c90ec65598f57d02d2bacf7d43f 100644 (file)
@@ -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