]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
Move the logic of validDNSName to DNSName::has8bitBytes() 8907/head 8951/head
authorRemi Gacogne <remi.gacogne@powerdns.com>
Mon, 17 Feb 2020 14:08:21 +0000 (15:08 +0100)
committerPeter van Dijk <peter.van.dijk@powerdns.com>
Thu, 5 Mar 2020 20:09:31 +0000 (21:09 +0100)
(cherry picked from commit bf7ef5b4ee0ce310db0a3761a8250f86a5fea20d)

pdns/dnsname.cc
pdns/dnsname.hh
pdns/packethandler.cc

index c262d282023b6362f19bc86f8bcfe517b38ee1b7..7ebc2c4f5be07adebedb714261e2f9cdb6db4c77 100644 (file)
@@ -456,3 +456,25 @@ void DNSName::appendEscapedLabel(std::string& appendTo, const char* orig, size_t
     ++pos;
   }
 }
+
+bool DNSName::has8bitBytes() const
+{
+  const auto& s = d_storage;
+  string::size_type pos = 0;
+  uint8_t length = s.at(pos);
+  while (length > 0) {
+    for (size_t idx = 0; idx < length; idx++) {
+      ++pos;
+      char c = s.at(pos);
+      if(!((c >= 'a' && c <= 'z') ||
+           (c >= 'A' && c <= 'Z') ||
+           (c >= '0' && c <= '9') ||
+           c =='-' || c == '_' || c=='*' || c=='.' || c=='/' || c=='@' || c==' ' || c=='\\' || c==':'))
+        return true;
+    }
+    ++pos;
+    length = s.at(pos);
+  }
+
+  return false;
+}
index 1f8ddf49a107f066060d4afa005b045c11496f25..f933a62252c1c44281498414c187534248ee982c 100644 (file)
@@ -148,6 +148,9 @@ public:
   const string_t& getStorage() const {
     return d_storage;
   }
+
+  bool has8bitBytes() const; /* returns true if at least one byte of the labels forming the name is not included in [A-Za-z0-9_*./@ \\:-] */
+
 private:
   string_t d_storage;
 
index 2a955664c11c2181e60bb3b33af560bcced8cd49..197bab40a55d99a5c124b01353a6240938753978 100644 (file)
@@ -942,25 +942,10 @@ int PacketHandler::processNotify(const DNSPacket& p)
   return 0;
 }
 
-static bool validDNSName(const DNSName &name)
+static bool validDNSName(const DNSNamename)
 {
   if (!g_8bitDNS) {
-    const auto& s = name.getStorage();
-    string::size_type pos = 0;
-    uint8_t length = s.at(pos);
-    while (length > 0) {
-      for (size_t idx = 0; idx < length; idx++) {
-        ++pos;
-        char c = s.at(pos);
-        if(!((c >= 'a' && c <= 'z') ||
-             (c >= 'A' && c <= 'Z') ||
-             (c >= '0' && c <= '9') ||
-             c =='-' || c == '_' || c=='*' || c=='.' || c=='/' || c=='@' || c==' ' || c=='\\' || c==':'))
-          return false;
-      }
-      ++pos;
-      length = s.at(pos);
-    }
+    return name.has8bitBytes() == false;
   }
   return true;
 }