From 1a8c94ba941362c4dbff2f2e120d7f731a6a6f55 Mon Sep 17 00:00:00 2001 From: Tal Aloni Date: Sat, 1 Jun 2024 17:21:15 +0300 Subject: [PATCH] Server: ConnectionState: Fix thread-safety issue --- .../Server/ConnectionState/SMB1ConnectionState.cs | 12 +++++++++--- .../Server/ConnectionState/SMB2ConnectionState.cs | 12 +++++++++--- 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/SMBLibrary/Server/ConnectionState/SMB1ConnectionState.cs b/SMBLibrary/Server/ConnectionState/SMB1ConnectionState.cs index 6c9903d..f49adee 100644 --- a/SMBLibrary/Server/ConnectionState/SMB1ConnectionState.cs +++ b/SMBLibrary/Server/ConnectionState/SMB1ConnectionState.cs @@ -1,4 +1,4 @@ -/* Copyright (C) 2014-2019 Tal Aloni . All rights reserved. +/* Copyright (C) 2014-2024 Tal Aloni . All rights reserved. * * You can redistribute this program and/or modify it under the terms of * the GNU Lesser Public License as published by the Free Software Foundation, @@ -78,14 +78,20 @@ namespace SMBLibrary.Server public SMB1Session GetSession(ushort userID) { SMB1Session session; - m_sessions.TryGetValue(userID, out session); + lock (m_sessions) + { + m_sessions.TryGetValue(userID, out session); + } return session; } public void RemoveSession(ushort userID) { SMB1Session session; - m_sessions.TryGetValue(userID, out session); + lock (m_sessions) + { + m_sessions.TryGetValue(userID, out session); + } if (session != null) { session.Close(); diff --git a/SMBLibrary/Server/ConnectionState/SMB2ConnectionState.cs b/SMBLibrary/Server/ConnectionState/SMB2ConnectionState.cs index 553a9ea..724dd19 100644 --- a/SMBLibrary/Server/ConnectionState/SMB2ConnectionState.cs +++ b/SMBLibrary/Server/ConnectionState/SMB2ConnectionState.cs @@ -1,4 +1,4 @@ -/* Copyright (C) 2014-2020 Tal Aloni . All rights reserved. +/* Copyright (C) 2014-2024 Tal Aloni . All rights reserved. * * You can redistribute this program and/or modify it under the terms of * the GNU Lesser Public License as published by the Free Software Foundation, @@ -56,14 +56,20 @@ namespace SMBLibrary.Server public SMB2Session GetSession(ulong sessionID) { SMB2Session session; - m_sessions.TryGetValue(sessionID, out session); + lock (m_sessions) + { + m_sessions.TryGetValue(sessionID, out session); + } return session; } public void RemoveSession(ulong sessionID) { SMB2Session session; - m_sessions.TryGetValue(sessionID, out session); + lock (m_sessions) + { + m_sessions.TryGetValue(sessionID, out session); + } if (session != null) { session.Close();