Subject: [libssh2] #245: libssh2 does not handle channel_close correctly

[libssh2] #245: libssh2 does not handle channel_close correctly

From: libssh2 Trac <>
Date: Tue, 10 Jul 2012 16:15:58 -0000

#245: libssh2 does not handle channel_close correctly
 Reporter: maxmtl | Owner:
     Type: defect | Status: new
 Priority: normal | Milestone: 1.4.0
Component: protocol | Version: 1.4.1
 Keywords: | Blocked By:
   Blocks: |
 libssh2 does not wait for the CHANNEL_CLOSE message from the server before
 closing the socket. It closes the socket as soon as any message has been
 received (e.g. CHANNEL_EOF or CHANNEL_REQUEST).

 The problem has been seen with libssh2 example sftp_write.c when
 communicating with the Apache Mina sshd server. Some exceptions about
 Connection Reset were displayed. The problem was not present using either
 the OpenSsh client or server applications.

 The attached patch corrects the problem; in channel.c / _channel_close(),
 _libssh2_transport_read is used to wait for the CHANNEL_CLOSE message. Its
 return value is validated using !rc, however when a message is received
 the return value is set to the actual message type, so (rc >= 0) should be
 used instead of (!rc).

 It may be related to issues 236 and 239, since some messages may not be
 parsed (CHANNEL_REQUEST:exit_status, for example).

 Tested with version 1.4.2; however this value was not available in the

 (Debugging done under contract for Accedian Networks)

Ticket URL: <>
libssh2 <>
C library for writing portable SSH2 clients
Received on 2012-07-10