]> granicus.if.org Git - pdns/commitdiff
allocate TCP buffer dynamically, decreasing our stack usage
authorbert hubert <bert.hubert@netherlabs.nl>
Sat, 10 Jan 2015 22:06:38 +0000 (23:06 +0100)
committerbert hubert <bert.hubert@netherlabs.nl>
Sat, 10 Jan 2015 22:06:38 +0000 (23:06 +0100)
pdns/tcpreceiver.cc

index f90bf906e75a4c9a25713e3cd61691435f537fe5..6356d343b8432ae146172e7a4ca7285d0784380b 100644 (file)
@@ -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) {