summaryrefslogtreecommitdiffstats
path: root/testing/pdns/allocate-tcp-buffer-dynamically.patch
blob: b346a2e9a17d4c9baaf3b420fc3bebeea60ce509 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
From c2b4ccc0d125a30a1970f555f572bf74de27a3d5 Mon Sep 17 00:00:00 2001
From: bert hubert <bert.hubert@netherlabs.nl>
Date: Sat, 10 Jan 2015 23:06:38 +0100
Subject: [PATCH] allocate TCP buffer dynamically, decreasing our stack usage

---
 pdns/tcpreceiver.cc | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/pdns/tcpreceiver.cc b/pdns/tcpreceiver.cc
index f90bf90..6356d34 100644
--- a/pdns/tcpreceiver.cc
+++ b/pdns/tcpreceiver.cc
@@ -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) {