From 5a99e22ff53f2151268c8923e04d73106e6f1cc0 Mon Sep 17 00:00:00 2001 From: Remi Gacogne Date: Sun, 4 Dec 2016 21:09:37 +0100 Subject: [PATCH] dnsdist: Add the TCP socket to the map only if the connection succeeds Otherwise we create a value-initialized (to 0) entry in the map and try to use it later. --- pdns/dnsdist-tcp.cc | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/pdns/dnsdist-tcp.cc b/pdns/dnsdist-tcp.cc index 2e01da518d..9d9f956872 100644 --- a/pdns/dnsdist-tcp.cc +++ b/pdns/dnsdist-tcp.cc @@ -340,7 +340,8 @@ void* tcpClientThread(int pipefd) int dsock = -1; if(sockets.count(ds->remote) == 0) { - dsock=sockets[ds->remote]=setupTCPDownstream(ds); + dsock=setupTCPDownstream(ds); + sockets[ds->remote]=dsock; } else dsock=sockets[ds->remote]; @@ -369,7 +370,8 @@ void* tcpClientThread(int pipefd) close(dsock); dsock=-1; sockets.erase(ds->remote); - sockets[ds->remote]=dsock=setupTCPDownstream(ds); + dsock=setupTCPDownstream(ds); + sockets[ds->remote]=dsock; downstream_failures++; goto retry; } @@ -387,7 +389,8 @@ void* tcpClientThread(int pipefd) close(dsock); dsock=-1; sockets.erase(ds->remote); - sockets[ds->remote]=dsock=setupTCPDownstream(ds); + dsock=setupTCPDownstream(ds); + sockets[ds->remote]=dsock; downstream_failures++; goto retry; } @@ -405,7 +408,8 @@ void* tcpClientThread(int pipefd) close(dsock); dsock=-1; sockets.erase(ds->remote); - sockets[ds->remote]=dsock=setupTCPDownstream(ds); + dsock=setupTCPDownstream(ds); + sockets[ds->remote]=dsock; downstream_failures++; if(xfrStarted) { goto drop; -- 2.47.2