prevent that the server uses close messages from clients. Closes #950

This commit is contained in:
oy 2012-04-20 21:39:49 +02:00
parent 635dc7cda1
commit ea876df455
4 changed files with 21 additions and 16 deletions

View file

@ -140,6 +140,7 @@ private:
int m_Token; int m_Token;
int m_RemoteClosed; int m_RemoteClosed;
bool m_BlockCloseMsg;
TStaticRingBuffer<CNetChunkResend, NET_CONN_BUFFERSIZE> m_Buffer; TStaticRingBuffer<CNetChunkResend, NET_CONN_BUFFERSIZE> m_Buffer;
@ -167,7 +168,7 @@ private:
void Resend(); void Resend();
public: public:
void Init(NETSOCKET Socket); void Init(NETSOCKET Socket, bool BlockCloseMsg);
int Connect(NETADDR *pAddr); int Connect(NETADDR *pAddr);
void Disconnect(const char *pReason); void Disconnect(const char *pReason);

View file

@ -16,7 +16,7 @@ bool CNetClient::Open(NETADDR BindAddr, int Flags)
// init // init
m_Socket = Socket; m_Socket = Socket;
m_Connection.Init(m_Socket); m_Connection.Init(m_Socket, false);
return true; return true;
} }

View file

@ -37,12 +37,13 @@ void CNetConnection::SetError(const char *pString)
str_copy(m_ErrorString, pString, sizeof(m_ErrorString)); str_copy(m_ErrorString, pString, sizeof(m_ErrorString));
} }
void CNetConnection::Init(NETSOCKET Socket) void CNetConnection::Init(NETSOCKET Socket, bool BlockCloseMsg)
{ {
Reset(); Reset();
ResetStats(); ResetStats();
m_Socket = Socket; m_Socket = Socket;
m_BlockCloseMsg = BlockCloseMsg;
mem_zero(m_ErrorString, sizeof(m_ErrorString)); mem_zero(m_ErrorString, sizeof(m_ErrorString));
} }
@ -213,21 +214,24 @@ int CNetConnection::Feed(CNetPacketConstruct *pPacket, NETADDR *pAddr)
m_State = NET_CONNSTATE_ERROR; m_State = NET_CONNSTATE_ERROR;
m_RemoteClosed = 1; m_RemoteClosed = 1;
if(pPacket->m_DataSize) if(!m_BlockCloseMsg)
{ {
// make sure to sanitize the error string form the other party if(pPacket->m_DataSize)
char Str[128]; {
if(pPacket->m_DataSize < 128) // make sure to sanitize the error string form the other party
str_copy(Str, (char *)pPacket->m_aChunkData, pPacket->m_DataSize); char Str[128];
else if(pPacket->m_DataSize < 128)
str_copy(Str, (char *)pPacket->m_aChunkData, sizeof(Str)); str_copy(Str, (char *)pPacket->m_aChunkData, pPacket->m_DataSize);
str_sanitize_strong(Str); else
str_copy(Str, (char *)pPacket->m_aChunkData, sizeof(Str));
str_sanitize_strong(Str);
// set the error string // set the error string
SetError(Str); SetError(Str);
}
else
SetError("No reason given");
} }
else
SetError("No reason given");
if(g_Config.m_Debug) if(g_Config.m_Debug)
dbg_msg("conn", "closed reason='%s'", ErrorString()); dbg_msg("conn", "closed reason='%s'", ErrorString());

View file

@ -30,7 +30,7 @@ bool CNetServer::Open(NETADDR BindAddr, CNetBan *pNetBan, int MaxClients, int Ma
m_MaxClientsPerIP = MaxClientsPerIP; m_MaxClientsPerIP = MaxClientsPerIP;
for(int i = 0; i < NET_MAX_CLIENTS; i++) for(int i = 0; i < NET_MAX_CLIENTS; i++)
m_aSlots[i].m_Connection.Init(m_Socket); m_aSlots[i].m_Connection.Init(m_Socket, true);
return true; return true;
} }