]> granicus.if.org Git - pdns/commitdiff
report TCP connection handover errors from client, delete memory in that case
authorbert hubert <bert.hubert@powerdns.com>
Thu, 5 Nov 2015 15:59:07 +0000 (16:59 +0100)
committerbert hubert <bert.hubert@powerdns.com>
Thu, 5 Nov 2015 15:59:07 +0000 (16:59 +0100)
pdns/dnsdist-tcp.cc

index 2ebbbf00907165fe55ebc11390f42f52152f4d94..e42d9daa7de06cce5b5bae3fe4b5eb6849eda62e 100644 (file)
@@ -131,8 +131,6 @@ void* tcpClientThread(int pipefd)
             dh->qr=false;
           }
         }
-
-       
        
        DNSAction::Action action=DNSAction::Action::None;
        for(const auto& lr : *localRulactions) {
@@ -173,10 +171,8 @@ void* tcpClientThread(int pipefd)
          putMsgLen(ci.fd, qlen);
          writen2(ci.fd, query, rlen);
          goto drop;
-
        }
 
-
        {
          std::lock_guard<std::mutex> lock(g_luamutex);
          ds = localPolicy->policy(getDownstreamCandidates(g_dstates.getCopy(), pool), ci.remote, qname, qtype, dh);
@@ -226,7 +222,7 @@ void* tcpClientThread(int pipefd)
 
   drop:;
     
-    vinfolog("Closing client connection with %s", ci.remote.toStringWithPort());
+    vinfolog("Closing TCP client connection with %s", ci.remote.toStringWithPort());
     close(ci.fd); 
     ci.fd=-1;
     if(ds)
@@ -250,14 +246,18 @@ void* tcpAcceptorThread(void* p)
 
   auto acl = g_ACL.getLocal();
   for(;;) {
+    ConnectionInfo* ci;
     try {
-      ConnectionInfo* ci = new ConnectionInfo;
+      ci=0;
+      ci = new ConnectionInfo;
+      ci->fd = -1;
       ci->fd = SAccept(cs->tcpFD, remote);
       
       if(!acl->match(remote)) {
        g_stats.aclDrops++;
        close(ci->fd);
        delete ci;
+       ci=0;
        vinfolog("Dropped TCP connection from %s because of ACL", remote.toStringWithPort());
        continue;
       }
@@ -267,6 +267,12 @@ void* tcpAcceptorThread(void* p)
       ci->remote = remote;
       writen2(g_tcpclientthreads.getThread(), &ci, sizeof(ci));
     }
+    catch(std::exception& e) {
+      errlog("While reading a TCP question: %s", e.what());
+      if(ci && ci->fd >= 0) 
+       close(ci->fd);
+      delete ci;
+    }
     catch(...){}
   }