From e4182a1b9ea0032bb6b840e73689baa78afaddfc Mon Sep 17 00:00:00 2001 From: savis <106487343+savisxss@users.noreply.github.com> Date: Sun, 28 Dec 2025 05:03:47 +0100 Subject: [PATCH] Add handshake session timeout protection --- src/game/desc.cpp | 9 +++++++++ src/game/desc.h | 7 +++++++ src/game/desc_manager.cpp | 12 ++++++++++++ 3 files changed, 28 insertions(+) diff --git a/src/game/desc.cpp b/src/game/desc.cpp index 2f6c450..6cdf37c 100644 --- a/src/game/desc.cpp +++ b/src/game/desc.cpp @@ -52,6 +52,7 @@ void DESC::Initialize() m_iHandshakeRetry = 0; m_dwClientTime = 0; m_bHandshaking = false; + m_handshake_time = get_dword_time(); m_lpBufferedOutputBuffer = NULL; m_lpOutputBuffer = NULL; @@ -715,6 +716,14 @@ bool DESC::IsHandshaking() return m_bHandshaking; } +bool DESC::IsExpiredHandshake() const +{ + if (m_handshake_time == 0) + return false; + + return (m_handshake_time + (5 * 1000)) < get_dword_time(); +} + DWORD DESC::GetClientTime() { return m_dwClientTime; diff --git a/src/game/desc.h b/src/game/desc.h index bc81300..b654202 100644 --- a/src/game/desc.h +++ b/src/game/desc.h @@ -174,6 +174,10 @@ class DESC bool isChannelStatusRequested() const { return m_bChannelStatusRequested; } void SetChannelStatusRequested(bool bChannelStatusRequested) { m_bChannelStatusRequested = bChannelStatusRequested; } + // Handshake timeout check + bool IsExpiredHandshake() const; + void SetHandshakeTime(uint32_t handshake_time) { m_handshake_time = handshake_time; } + protected: void Initialize(); @@ -246,6 +250,9 @@ class DESC bool m_bDestroyed; bool m_bChannelStatusRequested; + // Handshake timeout protection + uint32_t m_handshake_time; + #ifdef _IMPROVED_PACKET_ENCRYPTION_ Cipher cipher_; #else diff --git a/src/game/desc_manager.cpp b/src/game/desc_manager.cpp index d735a1e..ed55d64 100644 --- a/src/game/desc_manager.cpp +++ b/src/game/desc_manager.cpp @@ -224,6 +224,18 @@ void DESC_MANAGER::DestroyClosed() DestroyDesc(d, false); m_set_pkDesc.erase(ci); } + else if (d->IsPhase(PHASE_HANDSHAKE)) + { + if (d->GetType() == DESC_TYPE_ACCEPTOR) + { + if (d->IsExpiredHandshake()) + { + sys_log(0, "[%s]: handshake session has expired!", d->GetHostName()); + DestroyDesc(d, false); + m_set_pkDesc.erase(ci); + } + } + } } }