Ticket #245 (new defect)

Opened 5 years ago

Last modified 5 years ago

libssh2 does not handle channel_close correctly

Reported by: maxmtl Owned by:
Priority: normal Milestone:
Component: protocol Version: 1.4.1
Keywords: Cc:
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 choices...

(Debugging done under contract for Accedian Networks)


libssh2-1.4.2-channelClose.patch (527 bytes) - added by maxmtl 5 years ago.
Patch to correct the problem

Download all attachments as: .zip

Change History

Changed 5 years ago by maxmtl

Patch to correct the problem

comment:1 Changed 5 years ago by bagder

  • Milestone 1.4.0 deleted

Milestone 1.4.0 deleted

Note: See TracTickets for help on using tickets.