]> granicus.if.org Git - pdns/commitdiff
escape TXTs when writing them out - half fixes #541
authorPeter van Dijk <peter.van.dijk@netherlabs.nl>
Mon, 17 Dec 2012 14:18:35 +0000 (14:18 +0000)
committerPeter van Dijk <peter.van.dijk@netherlabs.nl>
Mon, 17 Dec 2012 14:18:35 +0000 (14:18 +0000)
git-svn-id: svn://svn.powerdns.com/pdns/trunk/pdns@2993 d19b8d6e-7fed-0310-83ef-9ca221ded41b

pdns/dnsparser.cc
regression-tests/8bit-txt/command [new file with mode: 0755]
regression-tests/8bit-txt/description [new file with mode: 0644]
regression-tests/8bit-txt/expected_result [new file with mode: 0644]
regression-tests/ent-axfr/expected_result
regression-tests/test.com

index d03aaea5226aba41d3f71334500acde09975aee9..52820458e96202ca5fae2fda1ef0bca298f8e235 100644 (file)
@@ -20,6 +20,7 @@
 #include "dnswriter.hh"
 #include <boost/lexical_cast.hpp>
 #include <boost/algorithm/string.hpp>
+#include <boost/format.hpp>
 
 #include "namespaces.hh"
 
@@ -388,17 +389,23 @@ string PacketReader::getLabel(unsigned int recurs)
 static string txtEscape(const string &name)
 {
   string ret;
+  char ebuf[5];
 
-  for(string::const_iterator i=name.begin();i!=name.end();++i)
+  for(string::const_iterator i=name.begin();i!=name.end();++i) {
     if(*i=='\n') {  // XXX FIXME this should do a way better job!
       ret += "\\010";
     }
+    else if((unsigned char) *i > 127) {
+      snprintf(ebuf, sizeof(ebuf), "\\%03u", (unsigned char)*i);
+      ret += ebuf;
+    }
     else if(*i=='"' || *i=='\\'){
       ret += '\\';
       ret += *i;
     }
     else
       ret += *i;
+  }
   return ret;
 }
 
diff --git a/regression-tests/8bit-txt/command b/regression-tests/8bit-txt/command
new file mode 100755 (executable)
index 0000000..2d38db8
--- /dev/null
@@ -0,0 +1,3 @@
+#!/bin/sh
+cleandig aland.test.com TXT
+
diff --git a/regression-tests/8bit-txt/description b/regression-tests/8bit-txt/description
new file mode 100644 (file)
index 0000000..993fdba
--- /dev/null
@@ -0,0 +1 @@
+TXT record with 8-bit (UTF-8) content.
diff --git a/regression-tests/8bit-txt/expected_result b/regression-tests/8bit-txt/expected_result
new file mode 100644 (file)
index 0000000..e71c33d
--- /dev/null
@@ -0,0 +1,3 @@
+0      aland.test.com. IN      TXT     3600    "\195\133LAND ISLANDS"
+Rcode: 0, RD: 0, QR: 1, TC: 0, AA: 1, opcode: 0
+Reply to question for qname='aland.test.com.', qtype=TXT
index ae79b66e324e696f102f86f05390871fe65df163..716b4b1e53bd02707b64f43dde8099487b0093c9 100644 (file)
@@ -2,7 +2,8 @@
 *.test.test.com.       86400   IN      NSEC    sub.test.test.com. CNAME RRSIG NSEC 
 _double._tcp.dc.test.com.      86400   IN      NSEC    _ldap._tcp.dc.test.com. SRV RRSIG NSEC 
 _ldap._tcp.dc.test.com.        86400   IN      NSEC    enum.test.com. SRV RRSIG NSEC 
-_underscore.test.com.  86400   IN      NSEC    blah.test.com. TXT RRSIG NSEC 
+_underscore.test.com.  86400   IN      NSEC    aland.test.com. TXT RRSIG NSEC 
+aland.test.com.        86400   IN      NSEC    blah.test.com. TXT RRSIG NSEC 
 b.c.test.com.  86400   IN      NSEC    *.a.b.c.test.com. A RRSIG NSEC 
 blah.test.com. 86400   IN      NSEC    b.c.test.com. NS RRSIG NSEC 
 counter.test.com.      86400   IN      NSEC    _double._tcp.dc.test.com. A RRSIG NSEC 
index ba1f0a25553d331842ed97871b6598507886e4dc..c36b7b2bc23a93bf074060429f11ee53b2dc4df6 100644 (file)
@@ -33,3 +33,4 @@ within-server         IN      CNAME   outpost.example.com.
 _underscore            IN      TXT     "underscores are terrible"
 b.c                    IN      A       5.6.7.8
 *.a.b.c                        IN      A       8.7.6.5
+aland          IN TXT "\195\133LAND ISLANDS"