From 83afafc0c3daa92857254e283a27192948c68d59 Mon Sep 17 00:00:00 2001 From: wadyankaw Date: Sun, 28 Dec 2025 03:54:55 +0300 Subject: [PATCH] Skip invalid socket when accept() fails When Acceptor.accept() returns an error (e.g., "Too many open files"), the server was continuing to process an invalid socket, causing resource leaks and potential infinite error loops. Add continue statement to skip processing when accept() fails, allowing the server to retry on the next iteration instead of crashing. Fixes resource exhaustion DoS vulnerability where server would enter error loop instead of handling gracefully. --- src/TNetwork.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/TNetwork.cpp b/src/TNetwork.cpp index 76ae3eb..b6bb27f 100644 --- a/src/TNetwork.cpp +++ b/src/TNetwork.cpp @@ -243,10 +243,11 @@ void TNetwork::TCPServerMain() { ip::tcp::socket ClientSocket = Acceptor.accept(ClientEp, ec); if (ec) { beammp_errorf("Failed to accept() new client: {}", ec.message()); + continue; } TConnection Conn { std::move(ClientSocket), ClientEp }; std::thread ID(&TNetwork::Identify, this, std::move(Conn)); - ID.detach(); // TODO: Add to a queue and attempt to join periodically + ID.detach(); } catch (const std::exception& e) { beammp_errorf("Exception in accept routine: {}", e.what()); }