Maxime Larocque | 10 Jul 2012 16:56
Picon
Favicon

PATCH - libssh2 disconnection

Hello,

We found a problem with the disconnect process of libssh2. When used 
with Apache Mina SSHd server it aborts the connection too fast, causing 
exceptions in the SSHd server.

An OpenSSH client connection to Apache Mina SSHd does not cause the 
problem. A libssh2 connection to an OpenSSH server does not cause any 
logs in the server.

It seems that the libssh2 server does not wait for all the messages to 
be received before closing the connection, once the first message is 
received ( SSH_MSG_CHANNEL_EOF), it aborts the connection instead of 
waiting for SSH_MSG_CHANNEL_CLOSE.

It was tested with libssh2 1.4.2 (which is not yet a valid version in Trac).

The following patch resolves the problem on our system:

==================================================
--- libssh2-1.4.2/src/channel.c    2012-07-03 14:41:27.010562955 -0400
+++ libssh2-1.4.2/src/channel2.c    2012-07-03 14:41:19.098562719 -0400
 <at>  <at>  -2295,7 +2295,7  <at>  <at> 
      if (channel->close_state == libssh2_NB_state_sent) {
          /* We must wait for the remote SSH_MSG_CHANNEL_CLOSE message */

-        while (!channel->remote.close && !rc &&
+        while (!channel->remote.close && (rc >= 0) &&
                 (session->socket_state != LIBSSH2_SOCKET_DISCONNECTED))
              rc = _libssh2_transport_read(session);
(Continue reading)


Gmane