vanilla handshake: ignore unknown sequence

This commit is contained in:
east 2015-08-14 13:49:10 +02:00
parent 9f1ab9a7bf
commit 051ec30832
4 changed files with 13 additions and 2 deletions

View file

@ -58,10 +58,13 @@ int CNetRecvUnpacker::FetchChunk(CNetChunk *pChunk)
// handle sequence stuff
if(m_pConnection && (Header.m_Flags&NET_CHUNKFLAG_VITAL))
{
if(Header.m_Sequence == (m_pConnection->m_Ack+1)%NET_MAX_SEQUENCE)
// anti spoof: ignore unknown sequence
if(Header.m_Sequence == (m_pConnection->m_Ack+1)%NET_MAX_SEQUENCE || m_pConnection->m_UnknownSeq)
{
m_pConnection->m_UnknownSeq = false;
// in sequence
m_pConnection->m_Ack = (m_pConnection->m_Ack+1)%NET_MAX_SEQUENCE;
m_pConnection->m_Ack = Header.m_Sequence;
}
else
{

View file

@ -158,6 +158,7 @@ private:
SECURITY_TOKEN m_SecurityToken;
int m_RemoteClosed;
bool m_BlockCloseMsg;
bool m_UnknownSeq;
TStaticRingBuffer<CNetChunkResend, NET_CONN_BUFFERSIZE> m_Buffer;
@ -219,6 +220,7 @@ public:
// anti spoof
void DirectInit(NETADDR &Addr, SECURITY_TOKEN SecurityToken);
void SetUnknownSeq() { m_UnknownSeq = true; }
};
class CConsoleNetConnection

View file

@ -31,6 +31,7 @@ void CNetConnection::Reset()
m_Token = -1;
m_SecurityToken = NET_SECURITY_TOKEN_UNKNOWN;
//mem_zero(&m_PeerAddr, sizeof(m_PeerAddr));
m_UnknownSeq = false;
m_Buffer.Init();

View file

@ -190,6 +190,11 @@ int CNetServer::TryAcceptClient(NETADDR &Addr, SECURITY_TOKEN SecurityToken, boo
// init connection slot
m_aSlots[Slot].m_Connection.DirectInit(Addr, SecurityToken);
if (NoAuth)
// client sequence is unknown if the auth was done
// connection-less
m_aSlots[Slot].m_Connection.SetUnknownSeq();
if (g_Config.m_Debug)
{
char aAddrStr[NETADDR_MAXSTRSIZE];