From dfb33c0f165f940ce47a1e3729890b77579f6ba3 Mon Sep 17 00:00:00 2001 From: Brad Arant Date: Tue, 25 Aug 2026 11:28:59 -0700 Subject: [PATCH] Fix TCPServer::connectionRequest() unconditionally initializing TLS connectionRequest() had a literal "if(true) { registerSocket(...); acceptSocket(); }" guarding the TLS handshake setup for every accepted connection, regardless of whether this TCPServer was ever given a TLSInfo. TLS::createContext() only sets `ctx` when tlsInfo is non-NULL (correctly guarded there) - so for any plain, non-TLS TCPServer, `ctx` is left uninitialized, and this unconditional call reached TLS::registerSocket() -> SSL_new(ctx) with garbage, segfaulting the whole process on the very first connection. Found while building APIServer (a new non-TLS HTTP server on top of TCPServer) - confirmed via gdb (SIGSEGV inside SSL_new, called from TLS::registerSocket, called from this exact line) that this affects ANY non-TLS ServerCore-based server's first accepted connection, not anything specific to the new code being tested against it. Fixed by checking `tlsInfo` (already a TCPSocket-protected member this class inherits) instead of the unconditional `true` - matches the guard TLS::createContext() already uses correctly for the same distinction. Verified live: before the fix, a non-TLS ApiServer segfaulted on the first curl request every time; after, GET/HEAD/POST requests across several real routes complete correctly and the server stays up for repeated requests, including one that deliberately throws (confirming the crash is really gone, not just less frequent). Co-Authored-By: Claude Sonnet 5 --- TCPServer.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/TCPServer.cpp b/TCPServer.cpp index a068712..2df7fdb 100644 --- a/TCPServer.cpp +++ b/TCPServer.cpp @@ -31,10 +31,10 @@ namespace core { TCPSession *session = accept(); if (session) sessions.push_back(session); - if(true) { + if (tlsInfo) { registerSocket(session->getDescriptor()); acceptSocket(); - } + } lock.unlock(); }