From b57f5a3a62f5d61cb82e96b6c821efeee125323a Mon Sep 17 00:00:00 2001 From: Nathan Fulton Date: Wed, 4 May 2016 22:42:02 -0400 Subject: [PATCH] Add null checks to fix server crashing --- server/endpoint.cpp | 1 + server/game.cpp | 11 ++++++++--- server/server.cpp | 48 ++++++++++++++++++++++++++++----------------- 3 files changed, 39 insertions(+), 21 deletions(-) diff --git a/server/endpoint.cpp b/server/endpoint.cpp index 4579b68..184e2bb 100644 --- a/server/endpoint.cpp +++ b/server/endpoint.cpp @@ -25,6 +25,7 @@ Endpoint::Endpoint(Server& server, base::Socket *socket, dword id, admin_(false), muted_(false), sigvisible_(false), seechat_(false), roomlimiter_(2, 120), teamchat_(false) { did_[0] = 0; + platform_[0] = 0; xpump_.Attach(socket, this, server.log()); } diff --git a/server/game.cpp b/server/game.cpp index 3bdc280..53b1332 100644 --- a/server/game.cpp +++ b/server/game.cpp @@ -1190,13 +1190,15 @@ void Game::SetAllies(SideMask side, SideMask sidmAllies) { } Player *Game::HumanPlayerFromEndpoint(Endpoint *endpoint) { - Player *pplr; + Player *pplr = NULL; for (int i = 0; i < kcPlayersMax; i++) { pplr = playerMgr_.GetPlayer(i); + + if (pplr == NULL) + continue; + if (pplr->endpoint() == endpoint) { break; - } else { - pplr = NULL; } } @@ -1301,6 +1303,9 @@ void Game::SendTeamChat(Endpoint *endpoint, const char *chat, const char *unfilt } bool Game::CanSendTeamChat(Endpoint *endpoint, bool broadcast) { + if (endpoint == NULL) + return false; + // Game not started yet if (!playing()) { if (broadcast) { diff --git a/server/server.cpp b/server/server.cpp index e76cd23..ef2c950 100644 --- a/server/server.cpp +++ b/server/server.cpp @@ -374,19 +374,25 @@ void Server::SetAnonsAllowed(bool anons_allowed) { } bool Server::SharedAccountExists(Endpoint *endpointAsker, const char *name) { + if (endpointAsker == NULL) + return false; + EndpointMap::iterator it = endpointmap_.begin(); - if (it->second->name() != NULL) { - for (; it != endpointmap_.end(); it++) { + for (; it != endpointmap_.end(); it++) { + if (it->second == NULL) + continue; - // Do the names match? - if (strcmp(name, it->second->name()) == 0) { + if (it->second->name() == NULL) + continue; - // Don't count endpointAsker - if (endpointAsker->id() != it->second->id()) { + // Do the names match? + if (strcmp(name, it->second->name()) == 0) { - // We found a shared account - return true; - } + // Don't count endpointAsker + if (endpointAsker->id() != it->second->id()) { + + // We found a shared account + return true; } } } @@ -394,19 +400,25 @@ bool Server::SharedAccountExists(Endpoint *endpointAsker, const char *name) { } void Server::DisconnectSharedAccounts(Endpoint *endpointAsker, const char *name) { + if (endpointAsker == NULL) + return; + EndpointMap::iterator it = endpointmap_.begin(); - if (it->second->name() != NULL) { - for (; it != endpointmap_.end(); it++) { + for (; it != endpointmap_.end(); it++) { + if (it->second == NULL) + continue; - // Do the names match? - if (strcmp(name, it->second->name()) == 0) { + if (it->second->name() == NULL) + continue; - // Son't disconnect the asker, only other endpoints - if (endpointAsker->id() != it->second->id()) { + // Do the names match? + if (strcmp(name, it->second->name()) == 0) { - // We found a shared account, dispose of it - it->second->Dispose(); - } + // Son't disconnect the asker, only other endpoints + if (endpointAsker->id() != it->second->id()) { + + // We found a shared account, dispose of it + it->second->Dispose(); } } }