Skip to content

Commit

Permalink
allocate TCP buffer dynamically, decreasing our stack usage
Browse files Browse the repository at this point in the history
(cherry picked from commit c2b4ccc)
  • Loading branch information
ahupowerdns authored and James-TR committed Mar 3, 2015
1 parent 27aa8de commit 9e6b24f
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions pdns/tcpreceiver.cc
Expand Up @@ -253,7 +253,8 @@ void *TCPNameserver::doConnection(void *data)
pthread_detach(pthread_self()); pthread_detach(pthread_self());
Utility::setNonBlocking(fd); Utility::setNonBlocking(fd);
try { try {
char mesg[65535]; int mesgsize=65535;
scoped_array<char> mesg(new char[mesgsize]);


DLOG(L<<"TCP Connection accepted on fd "<<fd<<endl); DLOG(L<<"TCP Connection accepted on fd "<<fd<<endl);
bool logDNSQueries= ::arg().mustDo("log-dns-queries"); bool logDNSQueries= ::arg().mustDo("log-dns-queries");
Expand All @@ -278,19 +279,19 @@ void *TCPNameserver::doConnection(void *data)


// do not remove this check as it will catch if someone // do not remove this check as it will catch if someone
// decreases the mesg buffer size for some reason. // decreases the mesg buffer size for some reason.
if(pktlen>sizeof(mesg)) { if(pktlen > mesgsize) {
L<<Logger::Error<<"Received an overly large question from "<<remote.toString()<<", dropping"<<endl; L<<Logger::Error<<"Received an overly large question from "<<remote.toString()<<", dropping"<<endl;
break; break;
} }


getQuestion(fd, mesg, pktlen, remote); getQuestion(fd, mesg.get(), pktlen, remote);
S.inc("tcp-queries"); S.inc("tcp-queries");


packet=shared_ptr<DNSPacket>(new DNSPacket); packet=shared_ptr<DNSPacket>(new DNSPacket);
packet->setRemote(&remote); packet->setRemote(&remote);
packet->d_tcp=true; packet->d_tcp=true;
packet->setSocket(fd); packet->setSocket(fd);
if(packet->parse(mesg, pktlen)<0) if(packet->parse(mesg.get(), pktlen)<0)
break; break;


if(packet->qtype.getCode()==QType::AXFR) { if(packet->qtype.getCode()==QType::AXFR) {
Expand Down

0 comments on commit 9e6b24f

Please sign in to comment.