From 1cf3dc3b104d715570b4c93452a5f26727793891 Mon Sep 17 00:00:00 2001 From: Remi Gacogne Date: Thu, 20 Mar 2025 14:15:47 +0100 Subject: [PATCH] rec: Prevent a crash when exiting nicely If a TCP connection is alive when we are exiting, we might dereference a `null` pointer when the TCP connection destructor is called after the thread-local `t_tcpClientCounts` object has been destroyed. --- pdns/recursordist/rec-tcp.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pdns/recursordist/rec-tcp.cc b/pdns/recursordist/rec-tcp.cc index d7cd3685ba..0bea53d916 100644 --- a/pdns/recursordist/rec-tcp.cc +++ b/pdns/recursordist/rec-tcp.cc @@ -108,7 +108,7 @@ TCPConnection::~TCPConnection() g_slogtcpin->error(Logr::Error, e.reason, "Error closing TCPConnection socket", "exception", Logging::Loggable("PDNSException"))); } - if (t_tcpClientCounts->count(d_remote) != 0 && (*t_tcpClientCounts)[d_remote]-- == 0) { + if (t_tcpClientCounts && t_tcpClientCounts->count(d_remote) != 0 && (*t_tcpClientCounts)[d_remote]-- == 0) { t_tcpClientCounts->erase(d_remote); } --s_currentConnections; -- 2.47.2