From e6a82119e1bb021e4510ec2ec6fb239ef923f456 Mon Sep 17 00:00:00 2001 From: Spencer McIntyre Date: Fri, 29 Mar 2024 09:05:24 -0400 Subject: [PATCH] Account for errors when generating IDs --- lib/ruby_smb/server/server_client/session_setup.rb | 6 +++++- lib/ruby_smb/server/server_client/tree_connect.rb | 2 ++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/ruby_smb/server/server_client/session_setup.rb b/lib/ruby_smb/server/server_client/session_setup.rb index ea325d10..350144bb 100644 --- a/lib/ruby_smb/server/server_client/session_setup.rb +++ b/lib/ruby_smb/server/server_client/session_setup.rb @@ -53,10 +53,12 @@ def do_logoff_andx_smb1(request, session) end def do_session_setup_smb2(request, session) + @smb2_related_operations_state.delete(:session_id) + session_id = request.smb2_header.session_id if session_id == 0 session_id = rand(1..0xfffffffe) - session = @session_table[session_id] = Session.new(session_id) + session = Session.new(session_id) else session = @session_table[session_id] if session.nil? @@ -92,6 +94,8 @@ def do_session_setup_smb2(request, session) update_preauth_hash(response) end + + @session_table[session_id] = session @smb2_related_operations_state[:session_id] = session_id response diff --git a/lib/ruby_smb/server/server_client/tree_connect.rb b/lib/ruby_smb/server/server_client/tree_connect.rb index 9bf56cb8..193cc901 100644 --- a/lib/ruby_smb/server/server_client/tree_connect.rb +++ b/lib/ruby_smb/server/server_client/tree_connect.rb @@ -41,6 +41,8 @@ def do_tree_disconnect_smb1(request, session) end def do_tree_connect_smb2(request, session) + @smb2_related_operations_state.delete(:tree_id) + response = RubySMB::SMB2::Packet::TreeConnectResponse.new response.smb2_header.credits = 1 if session.tree_connect_table.length >= MAX_TREE_CONNECTIONS