Markus posted a bug report about a bad 0-return from libssh2_channel_read:

http://libssh2.haxx.se/mail/libssh2-devel-archive-2009-04/0076.shtml

  And it was indeed a bad loop that terminated too early due to a receveived
  close packet.
This commit is contained in:
Daniel Stenberg
2009-04-30 10:30:26 +00:00
parent 6409bb53ba
commit 9f104cd883
2 changed files with 16 additions and 1 deletions

View File

@@ -1794,8 +1794,15 @@ static ssize_t channel_read(LIBSSH2_CHANNEL *channel, int stream_id,
channel->read_packet = session->packets.head;
while (channel->read_packet &&
!channel->remote.close &&
(bytes_read < (int) buflen)) {
/* previously this loop condition also checked for
!channel->remote.close but we cannot let it do this:
We may have a series of packets to read that are still pending even
if a close has been received. Acknowledging the close too early
makes us flush buffers prematurely and loose data.
*/
LIBSSH2_PACKET *readpkt = channel->read_packet;
/* In case packet gets destroyed during this iteration */