From: Peter van Dijk Date: Fri, 12 Apr 2013 11:18:04 +0000 (+0000) Subject: don't mess up encoding when copying qname from question to answer in packetcache... X-Git-Tag: rec-3.5~2 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=63e365db8884838184cfc61b26be62469589f404;p=thirdparty%2Fpdns.git don't mess up encoding when copying qname from question to answer in packetcache. Based on reports&debugging by Jimmy Bergman (sigint), Daniel Norman (Loopia) and the fine people at ISC git-svn-id: svn://svn.powerdns.com/pdns/trunk/pdns@3155 d19b8d6e-7fed-0310-83ef-9ca221ded41b --- diff --git a/pdns/dnspacket.cc b/pdns/dnspacket.cc index 70ea974c73..e38edd72f4 100644 --- a/pdns/dnspacket.cc +++ b/pdns/dnspacket.cc @@ -393,18 +393,20 @@ DNSPacket *DNSPacket::replyPacket() const return r; } -void DNSPacket::spoofQuestion(const string &qd) +void DNSPacket::spoofQuestion(const DNSPacket *qd) { - string label=simpleCompress(qd); d_wrapped=true; // if we do this, don't later on wrapup - if(label.size() + sizeof(d) > d_rawpacket.size()) { // probably superfluous - return; + int labellen; + string::size_type i=sizeof(d); + + for(;;) { + labellen = qd->d_rawpacket[i]; + if(!labellen) break; + i++; + d_rawpacket.replace(i, labellen, qd->d_rawpacket, i, labellen); + i = i + labellen; } - - for(string::size_type i=0; i < label.size(); ++i) - d_rawpacket[i+sizeof(d)]=label[i]; - } int DNSPacket::noparse(const char *mesg, int length) diff --git a/pdns/dnspacket.hh b/pdns/dnspacket.hh index b52bd49744..91c44bddec 100644 --- a/pdns/dnspacket.hh +++ b/pdns/dnspacket.hh @@ -123,7 +123,7 @@ public: DTime d_dt; //!< the time this packet was created. replyPacket() copies this in for you, so d_dt becomes the time spent processing the question+answer void wrapup(); // writes out queued rrs, and generates the binary packet. also shuffles. also rectifies dnsheader 'd', and copies it to the stringbuffer - void spoofQuestion(const string &qd); //!< paste in the exact right case of the question. Useful for PacketCache + void spoofQuestion(const DNSPacket *qd); //!< paste in the exact right case of the question. Useful for PacketCache unsigned int getMinTTL(); //!< returns lowest TTL of any record in the packet vector getAPRecords(); //!< get a vector with DNSResourceRecords that need additional processing diff --git a/pdns/packetcache.cc b/pdns/packetcache.cc index 75ba26d1b1..0acbf725dd 100644 --- a/pdns/packetcache.cc +++ b/pdns/packetcache.cc @@ -92,7 +92,7 @@ int PacketCache::get(DNSPacket *p, DNSPacket *cached) if(cached->noparse(value.c_str(), value.size()) < 0) { return 0; } - cached->spoofQuestion(p->qdomain); // for correct case + cached->spoofQuestion(p); // for correct case return 1; }