Skip to content

Commit 63e365d

Browse files
author
Peter van Dijk
committed
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
1 parent b4fbe59 commit 63e365d

File tree

3 files changed

+12
-10
lines changed

3 files changed

+12
-10
lines changed

pdns/dnspacket.cc

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -393,18 +393,20 @@ DNSPacket *DNSPacket::replyPacket() const
393393
return r;
394394
}
395395

396-
void DNSPacket::spoofQuestion(const string &qd)
396+
void DNSPacket::spoofQuestion(const DNSPacket *qd)
397397
{
398-
string label=simpleCompress(qd);
399398
d_wrapped=true; // if we do this, don't later on wrapup
400399

401-
if(label.size() + sizeof(d) > d_rawpacket.size()) { // probably superfluous
402-
return;
400+
int labellen;
401+
string::size_type i=sizeof(d);
402+
403+
for(;;) {
404+
labellen = qd->d_rawpacket[i];
405+
if(!labellen) break;
406+
i++;
407+
d_rawpacket.replace(i, labellen, qd->d_rawpacket, i, labellen);
408+
i = i + labellen;
403409
}
404-
405-
for(string::size_type i=0; i < label.size(); ++i)
406-
d_rawpacket[i+sizeof(d)]=label[i];
407-
408410
}
409411

410412
int DNSPacket::noparse(const char *mesg, int length)

pdns/dnspacket.hh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ public:
123123

124124
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
125125
void wrapup(); // writes out queued rrs, and generates the binary packet. also shuffles. also rectifies dnsheader 'd', and copies it to the stringbuffer
126-
void spoofQuestion(const string &qd); //!< paste in the exact right case of the question. Useful for PacketCache
126+
void spoofQuestion(const DNSPacket *qd); //!< paste in the exact right case of the question. Useful for PacketCache
127127
unsigned int getMinTTL(); //!< returns lowest TTL of any record in the packet
128128

129129
vector<DNSResourceRecord*> getAPRecords(); //!< get a vector with DNSResourceRecords that need additional processing

pdns/packetcache.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ int PacketCache::get(DNSPacket *p, DNSPacket *cached)
9292
if(cached->noparse(value.c_str(), value.size()) < 0) {
9393
return 0;
9494
}
95-
cached->spoofQuestion(p->qdomain); // for correct case
95+
cached->spoofQuestion(p); // for correct case
9696
return 1;
9797
}
9898

0 commit comments

Comments
 (0)