Quantcast
Channel: sshnet Issue Tracker Rss Feed
Viewing all articles
Browse latest Browse all 1026

Created Unassigned: Race condition in Session.cs [2770]

$
0
0
Hello,

I've discovered a race condition within the session.cs class. The issue occurs when attempting to connect via an SshClient and the subsequent session.Connect function call.

After authentication occurs (with ConnectionInfo.Authenticate(this)), the first message the server sends is the 'SSH_MSG_GLOBAL_REQUEST' message. The race condition consists of the server sending this message (which is received in a different thread) and the Connect() thread registering the message, indicating it is valid. If the server sends the message before the message is registered, an error is thrown and the connection is abandoned.

I've attached a revised Session.cs file which adds a new EventHandle; the handle is set after registering the group of messages near the bottom of the session.Connect() function. In the MessageListener() thread, if the current message is not valid, this handle is waited on (with an arbitrary timeout) then checked again. If it is still not valid, an exception is thrown.

As a proof of concept: adding a Thread.Sleep(2000) above the comment '// Register Connection messages' in Session.cs will trigger the exception and cause the connection to fail.

It is possible a similar situation could occur whenever messages are registered/unregistered in general, however I have not explored that possibility.

Thanks.

Viewing all articles
Browse latest Browse all 1026

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>