From ddb79bca2940ad1757982f52fdda62c518938a27 Mon Sep 17 00:00:00 2001 From: Aki Tuomi Date: Mon, 8 Jan 2018 12:27:48 +0200 Subject: [PATCH] pdns: Improve error when record data is not consumed Old: "All data was not consumed" New: "When parsing trailing data was not parsed: ''" --- pdns/dnsparser.hh | 3 +++ pdns/dnsrecords.hh | 2 +- pdns/dnswriter.hh | 3 +++ pdns/rcpgenerator.hh | 8 ++++++++ 4 files changed, 15 insertions(+), 1 deletion(-) diff --git a/pdns/dnsparser.hh b/pdns/dnsparser.hh index 78a73f03b..2df65e2ab 100644 --- a/pdns/dnsparser.hh +++ b/pdns/dnsparser.hh @@ -153,6 +153,9 @@ public: uint16_t d_pos; bool eof() { return true; }; + const string getRemaining() const { + return ""; + }; private: uint16_t d_startrecordpos; // needed for getBlob later on diff --git a/pdns/dnsrecords.hh b/pdns/dnsrecords.hh index 55afedbf2..f1154b77d 100644 --- a/pdns/dnsrecords.hh +++ b/pdns/dnsrecords.hh @@ -746,7 +746,7 @@ template \ void RNAME##RecordContent::xfrPacket(Convertor& conv, bool noDot) \ { \ CONV; \ - if (conv.eof() == false) throw MOADNSException("All data was not consumed"); \ + if (conv.eof() == false) throw MOADNSException("When parsing " #RNAME " trailing data was not parsed: '" + conv.getRemaining() + "'"); \ } \ struct EDNSOpts diff --git a/pdns/dnswriter.hh b/pdns/dnswriter.hh index 49cf6955c..0227b920f 100644 --- a/pdns/dnswriter.hh +++ b/pdns/dnswriter.hh @@ -132,6 +132,9 @@ public: } bool eof() { return true; } // we don't know how long the record should be + const string getRemaining() const { + return ""; + } private: uint16_t lookupName(const DNSName& name, uint16_t* matchlen); vector d_namepositions; diff --git a/pdns/rcpgenerator.hh b/pdns/rcpgenerator.hh index 5f61034e9..6fb3abf74 100644 --- a/pdns/rcpgenerator.hh +++ b/pdns/rcpgenerator.hh @@ -59,6 +59,10 @@ public: void xfrBlobNoSpaces(string& val, int len=-1); void xfrBlob(string& val, int len=-1); + const string getRemaining() const { + return d_string.substr(d_pos); + } + bool eof(); private: string d_string; @@ -89,6 +93,10 @@ public: void xfrBlob(const string& val, int len=-1); void xfrHexBlob(const string& val, bool keepReading=false); bool eof() { return true; }; + + const string getRemaining() const { + return ""; + } private: string& d_string; bool d_nodot; -- 2.40.0