From: bert hubert Date: Wed, 3 Oct 2018 14:20:45 +0000 (+0200) Subject: Make sure we escape 127 in TXT records X-Git-Tag: dnsdist-1.3.3~63^2 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=refs%2Fpull%2F7017%2Fhead;p=thirdparty%2Fpdns.git Make sure we escape 127 in TXT records 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. --- diff --git a/pdns/dnsparser.cc b/pdns/dnsparser.cc index e26bdf7089..29bbb43142 100644 --- a/pdns/dnsparser.cc +++ b/pdns/dnsparser.cc @@ -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; } diff --git a/pdns/test-dnsrecords_cc.cc b/pdns/test-dnsrecords_cc.cc index d13dcb9612..778fd867a7 100644 --- a/pdns/test-dnsrecords_cc.cc +++ b/pdns/test-dnsrecords_cc.cc @@ -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;