From f5ac6eea568f118dc77e72af7be1d11c5a747fec Mon Sep 17 00:00:00 2001 From: Zwelf Date: Thu, 18 Jun 2020 20:43:19 +0200 Subject: [PATCH] Fix segmentation fault when creating sql tables failed `GameServer()->OnShutdown(true);` (which would wait on running threads to exit) wasn't called if an error occured in the server init. Therefore `CServer` was freed before the init-thread finished executing, causing a use after free from `CSqlConnector::ms_ppSqlReadServers` pointing to `CServer->m_apSqlReadServers`. --- src/engine/server/server.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/engine/server/server.cpp b/src/engine/server/server.cpp index 8c7d0967d..bde321224 100644 --- a/src/engine/server/server.cpp +++ b/src/engine/server/server.cpp @@ -2063,7 +2063,7 @@ int CServer::Run() GameServer()->OnInit(); if(ErrorShutdown()) { - return 1; + m_RunServer = false; } str_format(aBuf, sizeof(aBuf), "version %s", GameServer()->NetVersion()); Console()->Print(IConsole::OUTPUT_LEVEL_STANDARD, "server", aBuf); @@ -2281,6 +2281,7 @@ int CServer::Run() const char *pDisconnectReason = "Server shutdown"; if(ErrorShutdown()) { + dbg_msg("server", "shutdown from game server (%s)", m_aErrorShutdownReason); pDisconnectReason = m_aErrorShutdownReason; } // disconnect all clients on shutdown