From 3c17e2619b5bb2701bc56c4a382da34aa215503c Mon Sep 17 00:00:00 2001 From: bert hubert Date: Thu, 5 Nov 2015 16:59:07 +0100 Subject: [PATCH] report TCP connection handover errors from client, delete memory in that case --- pdns/dnsdist-tcp.cc | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/pdns/dnsdist-tcp.cc b/pdns/dnsdist-tcp.cc index 2ebbbf009..e42d9daa7 100644 --- a/pdns/dnsdist-tcp.cc +++ b/pdns/dnsdist-tcp.cc @@ -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 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(...){} } -- 2.40.0