Permalink
Browse files

allocate TCP buffer dynamically, decreasing our stack usage

(cherry picked from commit c2b4ccc)
  • Loading branch information...
1 parent 27aa8de commit 9e6b24fbd2ae98ffcf48770d8ab329c9504fe53c @ahupowerdns ahupowerdns committed with James-TR Jan 10, 2015
Showing with 5 additions and 4 deletions.
  1. +5 −4 pdns/tcpreceiver.cc
View
@@ -253,7 +253,8 @@ void *TCPNameserver::doConnection(void *data)
pthread_detach(pthread_self());
Utility::setNonBlocking(fd);
try {
- char mesg[65535];
+ int mesgsize=65535;
+ scoped_array<char> mesg(new char[mesgsize]);
DLOG(L<<"TCP Connection accepted on fd "<<fd<<endl);
bool logDNSQueries= ::arg().mustDo("log-dns-queries");
@@ -278,19 +279,19 @@ void *TCPNameserver::doConnection(void *data)
// do not remove this check as it will catch if someone
// 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;
break;
}
- getQuestion(fd, mesg, pktlen, remote);
+ getQuestion(fd, mesg.get(), pktlen, remote);
S.inc("tcp-queries");
packet=shared_ptr<DNSPacket>(new DNSPacket);
packet->setRemote(&remote);
packet->d_tcp=true;
packet->setSocket(fd);
- if(packet->parse(mesg, pktlen)<0)
+ if(packet->parse(mesg.get(), pktlen)<0)
break;
if(packet->qtype.getCode()==QType::AXFR) {

0 comments on commit 9e6b24f

Please sign in to comment.