From 5dba9d254f3bc97ade939bc8b344394cd469daf4 Mon Sep 17 00:00:00 2001 From: Peter van Dijk Date: Mon, 17 Dec 2012 14:18:35 +0000 Subject: [PATCH] escape TXTs when writing them out - half fixes #541 git-svn-id: svn://svn.powerdns.com/pdns/trunk/pdns@2993 d19b8d6e-7fed-0310-83ef-9ca221ded41b --- pdns/dnsparser.cc | 9 ++++++++- regression-tests/8bit-txt/command | 3 +++ regression-tests/8bit-txt/description | 1 + regression-tests/8bit-txt/expected_result | 3 +++ regression-tests/ent-axfr/expected_result | 3 ++- regression-tests/test.com | 1 + 6 files changed, 18 insertions(+), 2 deletions(-) create mode 100755 regression-tests/8bit-txt/command create mode 100644 regression-tests/8bit-txt/description create mode 100644 regression-tests/8bit-txt/expected_result diff --git a/pdns/dnsparser.cc b/pdns/dnsparser.cc index d03aaea52..52820458e 100644 --- a/pdns/dnsparser.cc +++ b/pdns/dnsparser.cc @@ -20,6 +20,7 @@ #include "dnswriter.hh" #include #include +#include #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 index 000000000..2d38db82b --- /dev/null +++ b/regression-tests/8bit-txt/command @@ -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 index 000000000..993fdba79 --- /dev/null +++ b/regression-tests/8bit-txt/description @@ -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 index 000000000..e71c33d2f --- /dev/null +++ b/regression-tests/8bit-txt/expected_result @@ -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 diff --git a/regression-tests/ent-axfr/expected_result b/regression-tests/ent-axfr/expected_result index ae79b66e3..716b4b1e5 100644 --- a/regression-tests/ent-axfr/expected_result +++ b/regression-tests/ent-axfr/expected_result @@ -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 diff --git a/regression-tests/test.com b/regression-tests/test.com index ba1f0a255..c36b7b2bc 100644 --- a/regression-tests/test.com +++ b/regression-tests/test.com @@ -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" -- 2.40.0