]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
rec: Prevent a crash when exiting nicely 15332/head
authorRemi Gacogne <remi.gacogne@powerdns.com>
Thu, 20 Mar 2025 13:15:47 +0000 (14:15 +0100)
committerRemi Gacogne <remi.gacogne@powerdns.com>
Thu, 20 Mar 2025 13:15:47 +0000 (14:15 +0100)
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

index d7cd3685ba6bcd70067c45330db6b5941dbf5f1b..0bea53d9168e0608e4e3986342e2e88ec000b317 100644 (file)
@@ -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;