From 98cda0a9caeaa076458f8aeb0a1d94a480df5eda Mon Sep 17 00:00:00 2001 From: bert hubert Date: Sat, 27 Aug 2016 14:53:54 +0200 Subject: [PATCH] add test case for domains with more than 34 parts which our static vector can't compress. Plus deal with that case. --- pdns/dnsrecords.hh | 2 +- pdns/dnswriter.cc | 55 ++++++++++++++++++++++++----------------- pdns/test-dnsname_cc.cc | 24 ++++++++++++++++++ 3 files changed, 58 insertions(+), 23 deletions(-) diff --git a/pdns/dnsrecords.hh b/pdns/dnsrecords.hh index 47c42573c..e00a41ef6 100644 --- a/pdns/dnsrecords.hh +++ b/pdns/dnsrecords.hh @@ -189,7 +189,7 @@ class PTRRecordContent : public DNSRecordContent { public: includeboilerplate(PTR) - + explicit PTRRecordContent(const DNSName& content) : d_content(content){} private: DNSName d_content; }; diff --git a/pdns/dnswriter.cc b/pdns/dnswriter.cc index fb90cc145..a369a8f60 100644 --- a/pdns/dnswriter.cc +++ b/pdns/dnswriter.cc @@ -199,11 +199,18 @@ uint16_t DNSPacketWriter::lookupName(const DNSName& name, uint16_t* matchLen) *matchLen=0; boost::container::static_vector nvect, pvect; - for(auto riter= raw.cbegin(); riter < raw.cend(); ) { - if(!*riter) - break; - nvect.push_back(riter - raw.cbegin()); - riter+=*riter+1; + try { + for(auto riter= raw.cbegin(); riter < raw.cend(); ) { + if(!*riter) + break; + nvect.push_back(riter - raw.cbegin()); + riter+=*riter+1; + } + } + catch(std::bad_alloc& ba) { + if(l_verbose) + cout<<"Domain "< packet; + DNSName loopback("1.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.ip6.arpa"); + DNSPacketWriter dpw(packet, loopback, QType::PTR); + + dpw.startRecord(loopback, QType::PTR); + PTRRecordContent prc(DNSName("localhost")); + prc.toPacket(dpw); + dpw.commit(); + DNSName roundtrip((char*)&packet[0], packet.size(), 12, false); + BOOST_CHECK_EQUAL(loopback,roundtrip); + + packet.clear(); + DNSName longer("1.2.3.4.5.6.7.8.1.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.ip6.arpa"); + DNSPacketWriter dpw2(packet, longer, QType::PTR); + + dpw2.startRecord(DNSName("a.b.c.d.e")+longer, QType::PTR); + PTRRecordContent prc2(DNSName("localhost")); + prc2.toPacket(dpw2); + dpw2.commit(); + +} + -- 2.40.0