]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
Expose and tidy txtEscape
authorOtto Moerbeek <otto.moerbeek@open-xchange.com>
Thu, 12 Jun 2025 09:43:20 +0000 (11:43 +0200)
committerOtto Moerbeek <otto.moerbeek@open-xchange.com>
Thu, 12 Jun 2025 09:43:20 +0000 (11:43 +0200)
pdns/dnsparser.cc
pdns/dnsparser.hh
pdns/rcpgenerator.cc

index 4cda7b6d54dde5ebcb475196c1ac35702d15684e..670cede5468c38f86bd5620895af2c60a7dc6127 100644 (file)
@@ -470,22 +470,24 @@ DNSName PacketReader::getName()
   throw PDNSException("PacketReader::getName(): name is empty");
 }
 
-static string txtEscape(const string &name)
+string txtEscape(const string &name)
 {
   string ret;
-  char ebuf[5];
+  std::array<char, 5> ebuf{};
 
-  for(char i : name) {
-    if((unsigned char) i >= 127 || (unsigned char) i < 32) {
-      snprintf(ebuf, sizeof(ebuf), "\\%03u", (unsigned char)i);
-      ret += ebuf;
+  for (char letter : name) {
+    const unsigned uch = static_cast<unsigned char>(letter);
+    if (uch >= 127 || uch < 32) {
+      snprintf(ebuf.data(), ebuf.size(), "\\%03u", uch);
+      ret += ebuf.data();
     }
-    else if(i=='"' || i=='\\'){
+    else if (letter == '"' || letter == '\\'){
       ret += '\\';
-      ret += i;
+      ret += letter;
+    }
+    else {
+      ret += letter;
     }
-    else
-      ret += i;
   }
   return ret;
 }
index 947ba6c77c5193d3233a920245ee6f9c32fad333..e3f777452ba6689aeb83b427075204f084f51346 100644 (file)
@@ -670,3 +670,5 @@ private:
   uint32_t d_notyouroffset;  // only 'moveOffset' can touch this
   const uint32_t&  d_offset; // look.. but don't touch
 };
+
+string txtEscape(const string &name);
index bdb14bf148305b771598984e2829d603804b68e4..ba16af7346b2818b1624d1bb3b71ce95a3b17eed 100644 (file)
@@ -838,27 +838,6 @@ void RecordTextWriter::xfrHexBlob(const string& val, bool)
   }
 }
 
-// FIXME copied from dnsparser.cc, see #6010 and #3503 if you want a proper solution
-static string txtEscape(const string &name)
-{
-  string ret;
-  char ebuf[5];
-
-  for(char i : name) {
-    if((unsigned char) i >= 127 || (unsigned char) i < 32) {
-      snprintf(ebuf, sizeof(ebuf), "\\%03u", (unsigned char)i);
-      ret += ebuf;
-    }
-    else if(i=='"' || i=='\\'){
-      ret += '\\';
-      ret += i;
-    }
-    else
-      ret += i;
-  }
-  return ret;
-}
-
 void RecordTextWriter::xfrSVCBValueList(const vector<string> &val) {
   bool shouldQuote{false};
   vector<string> escaped;