From 168302b9d63e58c4b696261189b2997a6633d43a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nguy=E1=BB=85n=20Th=C3=A1i=20Ng=E1=BB=8Dc=20Duy?= Date: Tue, 15 Jul 2025 15:38:59 +0200 Subject: [PATCH] Fix ssh_handle_key_exchange() timeout MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit See libssh-mirror#311 for background. But in some case, it's possible to trigger the code in ssh_handle_key_exchange() to move session state directly to SSH_SESSION_STATE_AUTHENTICATED. The exit condition for this function is SSH_SESSION_STATE_AUTHENTICATING though, so when it happens, ssh_handle_key_exchange() will time out eventually. The fix is straightforward. Tested with the problematic client (trilead-ssh2) and made sure the bad condition happened (and not cause timeout) Signed-off-by: Nguyễn Thái Ngọc Duy Reviewed-by: Jakub Jelen --- src/server.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/server.c b/src/server.c index 167cac6c..35541213 100644 --- a/src/server.c +++ b/src/server.c @@ -525,6 +525,7 @@ static int ssh_server_kex_termination(void *s){ ssh_session session = s; if (session->session_state != SSH_SESSION_STATE_ERROR && session->session_state != SSH_SESSION_STATE_AUTHENTICATING && + session->session_state != SSH_SESSION_STATE_AUTHENTICATED && session->session_state != SSH_SESSION_STATE_DISCONNECTED) return 0; else