]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
dnsdist: Prevent dangling TCP fd in case setupTCPDownstream() fails 3634/head
authorRemi Gacogne <remi.gacogne@powerdns.com>
Tue, 29 Mar 2016 12:49:50 +0000 (14:49 +0200)
committerRemi Gacogne <remi.gacogne@powerdns.com>
Tue, 29 Mar 2016 12:49:50 +0000 (14:49 +0200)
Remove the closed socket descriptor from the sockets map.
Otherwise, if an exception occurs in setupTCPDownstream(), we might
try to use it and close it again later, not knowing it has been
reassigned to another socket or, worse, to a TCP acceptor pipe.

pdns/dnsdist-tcp.cc

index 81954a30fc12ba51d847706288e33295ac4a9d42..eaeb974317a030ac3e7b03eae545d182ffdd4643 100644 (file)
@@ -358,6 +358,8 @@ void* tcpClientThread(int pipefd)
         if(!sendNonBlockingMsgLen(dsock, dq.len, ds->tcpSendTimeout, ds->remote, ds->sourceAddr, ds->sourceItf)) {
          vinfolog("Downstream connection to %s died on us, getting a new one!", ds->getName());
           close(dsock);
+          dsock=-1;
+          sockets.erase(ds->remote);
           sockets[ds->remote]=dsock=setupTCPDownstream(ds);
           downstream_failures++;
           goto retry;
@@ -374,6 +376,8 @@ void* tcpClientThread(int pipefd)
         catch(const runtime_error& e) {
           vinfolog("Downstream connection to %s died on us, getting a new one!", ds->getName());
           close(dsock);
+          dsock=-1;
+          sockets.erase(ds->remote);
           sockets[ds->remote]=dsock=setupTCPDownstream(ds);
           downstream_failures++;
           goto retry;
@@ -382,6 +386,8 @@ void* tcpClientThread(int pipefd)
         if(!getNonBlockingMsgLen(dsock, &rlen, ds->tcpRecvTimeout)) {
          vinfolog("Downstream connection to %s died on us phase 2, getting a new one!", ds->getName());
           close(dsock);
+          dsock=-1;
+          sockets.erase(ds->remote);
           sockets[ds->remote]=dsock=setupTCPDownstream(ds);
           downstream_failures++;
           goto retry;