]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
Make sure we escape 127 in TXT records 7017/head
authorbert hubert <bert.hubert@netherlabs.nl>
Wed, 3 Oct 2018 14:20:45 +0000 (16:20 +0200)
committerbert hubert <bert.hubert@netherlabs.nl>
Wed, 3 Oct 2018 14:20:45 +0000 (16:20 +0200)
It turns out that value 127 (decimal) in TXT records also needs to be escaped as 127 ('DEL') is unprintable. Adds test too, and documents our test infra a bit better.

pdns/dnsparser.cc
pdns/test-dnsrecords_cc.cc

index e26bdf7089b352296034435451e1f1b515929a1e..29bbb43142c8f36e6708cb70a0cb046b5ee68a54 100644 (file)
@@ -445,7 +445,7 @@ static string txtEscape(const string &name)
   char ebuf[5];
 
   for(string::const_iterator i=name.begin();i!=name.end();++i) {
-    if((unsigned char) *i > 127 || (unsigned char) *i < 32) {
+    if((unsigned char) *i >= 127 || (unsigned char) *i < 32) {
       snprintf(ebuf, sizeof(ebuf), "\\%03u", (unsigned char)*i);
       ret += ebuf;
     }
index d13dcb96122a5071b221d8b03a80b97d02940ae7..778fd867a7a38f2bcff204cfff6ba544dab9b0ac 100644 (file)
@@ -21,6 +21,12 @@ namespace {
 // C++11, but only C++14 added the `s` suffix.
 #define BINARY(s) (std::string(s, sizeof(s) - 1))
 
+// CASE_S is the simple case where zonefile format -> dns -> zonefile format roundtrips cleanly
+// CASE_L can be used where this is not the case. See LOC below for a good example why this might happen
+
+/*   (CASE_S(QType::NAME, "zone format", "line format")) */
+/*   (CASE_L(QType::NAME, "zone format", "canonic zone format", "line format")) */
+
 #define _CASE_L(type, inval, zoneval, lineval, broken) case_t(type, BINARY(inval), BINARY(zoneval), BINARY(lineval), broken)
 #define CASE_L(type, inval, zoneval, lineval) _CASE_L(type, inval, zoneval, lineval, broken_marker::WORKING)
 #define CASE_S(type, zoneval, lineval) _CASE_L(type, zoneval, zoneval, lineval, broken_marker::WORKING)
@@ -94,6 +100,7 @@ BOOST_AUTO_TEST_CASE(test_record_types) {
      (CASE_S(QType::TXT, "\"long record test 1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111\" \"2222222222\"", "\xff""long record test 1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111\x0a""2222222222"))
      (CASE_L(QType::TXT, "\"long record test 11111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111112222222222\"", "\"long record test 1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111\" \"2222222222\"", "\xff""long record test 1111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111\x0a""2222222222"))
      (CASE_S(QType::TXT,  "\"\\195\\133LAND ISLANDS\"", "\x0e\xc3\x85LAND ISLANDS"))
+     (CASE_S(QType::TXT,  "\"text with DEL in there: \\127\"", "\x19text with DEL in there: \x7f"))
      (CASE_L(QType::TXT, "\"\xc3\x85LAND ISLANDS\"", "\"\\195\\133LAND ISLANDS\"", "\x0e\xc3\x85LAND ISLANDS"))
      (CASE_S(QType::TXT, "\"nonbreakingtxt\"", "\x0enonbreakingtxt"))
 // local name
@@ -187,8 +194,6 @@ BOOST_AUTO_TEST_CASE(test_record_types) {
      (CASE_S(QType::DLV, "20642 8 2 04443abe7e94c3985196beae5d548c727b044dda5151e60d7cd76a9fd931d00e", "\x50\xa2\x08\x02\x04\x44\x3a\xbe\x7e\x94\xc3\x98\x51\x96\xbe\xae\x5d\x54\x8c\x72\x7b\x04\x4d\xda\x51\x51\xe6\x0d\x7c\xd7\x6a\x9f\xd9\x31\xd0\x0e"))
      (CASE_S((QType::typeenum)65226,"\\# 3 414243","\x41\x42\x43"))
 
-/*   (CASE_S(QType::NAME, "zone format", "line format")) */
-/*   (CASE_L(QType::NAME, "zone format", "canonic zone format", "line format")) */
 ;
 
   int n=0;