From 865216b15a4cfb836dddcb9bf66532b4f46497a3 Mon Sep 17 00:00:00 2001 From: "madmaxoft@gmail.com" Date: Thu, 2 Feb 2012 07:47:19 +0000 Subject: cSocket API fix (possible invalid pointer) cMCLogger slight change (CS ptr -> member) git-svn-id: http://mc-server.googlecode.com/svn/trunk@222 0a769ca7-a7f5-676a-18bf-c427514a06d6 --- source/cServer.cpp | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) (limited to 'source/cServer.cpp') diff --git a/source/cServer.cpp b/source/cServer.cpp index 44dd365c2..f14a419a9 100644 --- a/source/cServer.cpp +++ b/source/cServer.cpp @@ -295,17 +295,23 @@ void cServer::StartListenClient() { cSocket SClient = m_pState->SListenClient.Accept(); - if( SClient.IsValid() ) + if (!SClient.IsValid()) { - char * ClientIP = SClient.GetIPString(); - if( ClientIP == 0 ) - return; + return; + } + + const AString & ClientIP = SClient.GetIPString(); + if (ClientIP.empty()) + { + LOGWARN("cServer: A client connected, but didn't present its IP, disconnecting."); + SClient.CloseSocket(); + return; + } - LOG("%s connected!", ClientIP); + LOG("%s connected!", ClientIP.c_str()); - cClientHandle *NewHandle = new cClientHandle( SClient ); - m_pState->Clients.push_back( NewHandle ); // TODO - lock list - } + cClientHandle *NewHandle = new cClientHandle( SClient ); + m_pState->Clients.push_back( NewHandle ); // TODO - lock list } -- cgit v1.2.3