Ticket #126 (closed defect: fixed)

Opened 8 years ago

Last modified 7 years ago

_libssh2_channel_write returns erroneous value

Reported by: dseanrussell Owned by: bagder
Priority: normal Milestone:
Component: Version:
Keywords: Cc: dseanrussell, bagder
Blocked By: Blocks:


_libssh2_channel_write is not returning correct data under the following circumstances:

  • buflen is larger than the current local window size, so channel->write_bufwrite is reduced to channel->local.window_size.
  • The first chunk of the block is successfully written, so buflen, buf, and channel->write_bufwrote are updated correctly.
  • When the second chunk of the block is to be written, there is apparenly new room in the local window, so the new data is copied to the packet and _libssh2_transport_write is called.
  • _libssh2_transport_write fails with PACKET_EAGAIN, which is returned.
  • The write is retried, and finally succeeds. The 'wrote' value is returned, which only contains the amount of the second chunk of the original write.

I believe that this function should return channel->write_bufwrote, not wrote.

Change History

comment:1 Changed 8 years ago by bagder

I'm not sure I agree, but I agree that there's a problem here!

in my mind, it should not return PACKET_EAGAIN in the first case where it did manage to send away data, it should rather return the amount it managed to send even if it did get a EAGAIN case in the last transport_write() call. EAGAIN would then only be returned if no previous call to transport_write() was successful.

comment:2 Changed 7 years ago by bagder

  • Resolution set to fixed
  • Status changed from assigned to closed

I've pushed a fix for this as I suggested, available as commit 8b63dc9e59c676991ce62316d203849bc56e2a6c

Note: See TracTickets for help on using tickets.