From: Pieter Lexis Date: Tue, 1 Dec 2015 16:19:56 +0000 (+0100) Subject: Add a `lenField` option to xfrText() X-Git-Tag: dnsdist-1.0.0-beta1~98^2~3 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=84e1142d448827a7c89e26032b9b43cad9079c4b;p=thirdparty%2Fpdns.git Add a `lenField` option to xfrText() This option (true by default) tells the writer/parser to add/read a byte that is the length of the data following. --- diff --git a/pdns/dnsparser.cc b/pdns/dnsparser.cc index 499ddea211..405933c83a 100644 --- a/pdns/dnsparser.cc +++ b/pdns/dnsparser.cc @@ -439,7 +439,7 @@ static string txtEscape(const string &name) } // exceptions thrown here do not result in logging in the main pdns auth server - just so you know! -string PacketReader::getText(bool multi) +string PacketReader::getText(bool multi, bool lenField) { string ret; ret.reserve(40); @@ -447,7 +447,11 @@ string PacketReader::getText(bool multi) if(!ret.empty()) { ret.append(1,' '); } - unsigned char labellen=d_content.at(d_pos++); + uint16_t labellen; + if(lenField) + labellen=d_content.at(d_pos++); + else + labellen=d_recordlen - (d_pos - d_startrecordpos); ret.append(1,'"'); if(labellen) { // no need to do anything for an empty string diff --git a/pdns/dnsparser.hh b/pdns/dnsparser.hh index 88e02d3ddf..96f0906c0a 100644 --- a/pdns/dnsparser.hh +++ b/pdns/dnsparser.hh @@ -124,9 +124,9 @@ public: name=getName(); } - void xfrText(string &text, bool multi=false) + void xfrText(string &text, bool multi=false, bool lenField=true) { - text=getText(multi); + text=getText(multi, lenField); } void xfrBlob(string& blob); @@ -141,7 +141,7 @@ public: void copyRecord(unsigned char* dest, uint16_t len); DNSName getName(); - string getText(bool multi); + string getText(bool multi, bool lenField); uint16_t d_pos; diff --git a/pdns/dnswriter.cc b/pdns/dnswriter.cc index 8dd1dbb99e..06dc3b9804 100644 --- a/pdns/dnswriter.cc +++ b/pdns/dnswriter.cc @@ -146,14 +146,19 @@ void DNSPacketWriter::xfr8BitInt(uint8_t val) /* input: + if lenField is true "" -> 0 "blah" -> 4blah "blah" "blah" -> output 4blah4blah "verylongstringlongerthan256....characters" \xffverylongstring\x23characters (autosplit) "blah\"blah" -> 9blah"blah "blah\97" -> 5blahb + + if lenField is false + "blah" -> blah + "blah\"blah" -> blah"blah */ -void DNSPacketWriter::xfrText(const string& text, bool) +void DNSPacketWriter::xfrText(const string& text, bool, bool lenField) { if(text.empty()) { d_record.push_back(0); @@ -161,7 +166,8 @@ void DNSPacketWriter::xfrText(const string& text, bool) } vector segments = segmentDNSText(text); for(const string& str : segments) { - d_record.push_back(str.length()); + if(lenField) + d_record.push_back(str.length()); d_record.insert(d_record.end(), str.c_str(), str.c_str() + str.length()); } } diff --git a/pdns/dnswriter.hh b/pdns/dnswriter.hh index c5554ef7e4..2936890e41 100644 --- a/pdns/dnswriter.hh +++ b/pdns/dnswriter.hh @@ -87,7 +87,7 @@ public: void xfr8BitInt(uint8_t val); void xfrName(const DNSName& label, bool compress=false, bool noDot=false); - void xfrText(const string& text, bool multi=false); + void xfrText(const string& text, bool multi=false, bool lenField=true); void xfrBlob(const string& blob, int len=-1); void xfrBlobNoSpaces(const string& blob, int len=-1); void xfrHexBlob(const string& blob, bool keepReading=false); diff --git a/pdns/rcpgenerator.cc b/pdns/rcpgenerator.cc index dd34186de3..495d88972e 100644 --- a/pdns/rcpgenerator.cc +++ b/pdns/rcpgenerator.cc @@ -333,7 +333,7 @@ void RecordTextWriter::xfrBase32HexBlob(const string& val) } -void RecordTextReader::xfrText(string& val, bool multi) +void RecordTextReader::xfrText(string& val, bool multi, bool lenField) { val.clear(); val.reserve(d_end - d_pos); @@ -547,7 +547,7 @@ void RecordTextWriter::xfrHexBlob(const string& val, bool) } } -void RecordTextWriter::xfrText(const string& val, bool multi) +void RecordTextWriter::xfrText(const string& val, bool multi, bool lenField) { if(!d_string.empty()) d_string.append(1,' '); diff --git a/pdns/rcpgenerator.hh b/pdns/rcpgenerator.hh index f5af2ea640..5b33a01b40 100644 --- a/pdns/rcpgenerator.hh +++ b/pdns/rcpgenerator.hh @@ -53,7 +53,7 @@ public: void xfrTime(uint32_t& val); void xfrName(DNSName& val, bool compress=false, bool noDot=false); - void xfrText(string& val, bool multi=false); + void xfrText(string& val, bool multi=false, bool lenField=true); void xfrHexBlob(string& val, bool keepReading=false); void xfrBase32HexBlob(string& val); @@ -84,7 +84,7 @@ public: void xfrType(const uint16_t& val); void xfrName(const DNSName& val, bool compress=false, bool noDot=false); - void xfrText(const string& val, bool multi=false); + void xfrText(const string& val, bool multi=false, bool lenField=true); void xfrBlobNoSpaces(const string& val, int len=-1); void xfrBlob(const string& val, int len=-1); void xfrHexBlob(const string& val, bool keepReading=false);