Permalink
Browse files

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
  • Loading branch information...
1 parent b4fbe59 commit 63e365db8884838184cfc61b26be62469589f404 @Habbie Habbie committed Apr 12, 2013
Showing with 12 additions and 10 deletions.
  1. +10 −8 pdns/dnspacket.cc
  2. +1 −1 pdns/dnspacket.hh
  3. +1 −1 pdns/packetcache.cc
View
@@ -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)
View
@@ -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<DNSResourceRecord*> getAPRecords(); //!< get a vector with DNSResourceRecords that need additional processing
View
@@ -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;
}

0 comments on commit 63e365d

Please sign in to comment.