Subject: libssh2_channel_write_ex returned more bytes than requested (buflen)

libssh2_channel_write_ex returned more bytes than requested (buflen)

From: Matt Nowick <nowick_at_imonmail.com>
Date: Fri, 13 Sep 2013 09:32:35 -0500

Hi,
      I encountered a problem recently that I don't understand.
libssh2_channel_write_ex seems to have returned more bytes than the
requested buflen. After this happened my program crashed, presumably
because of a buffer overrun. Am I using this function correctly? Below
is a code fragment and output.

i=libssh2_channel_write_ex(ssh_channel, 0, (char *)buff, bytesToSend);
         if(i==bytesToSend) {
             return(0); // I'm done
         } else if( i>=0 || i==LIBSSH2_ERROR_EAGAIN ) {
             // try again after short rest
             if(i>=0) {
                 ds_error(INFO1, thisRoutine, "wrote %i/%i bytes to ssh
channel, trying 2nd time...", i, bytesToSend);
             } else {
                 ds_error(INFO1, thisRoutine, "ssh channel is busy,
trying 2nd time...");
                 i=0;
             }
             .
             .
             .

My log file left the message:
[Wed Sep 11 07:59:41 2013] writeRawPacket: wrote 746/46 bytes to ssh
channel, trying 2nd time...

This would indicate that libssh2_channel_write_ex returned a value of
746, but I only requested 46.

Any ideas?
Thanks

_______________________________________________
libssh2-devel http://cool.haxx.se/cgi-bin/mailman/listinfo/libssh2-devel
Received on 2013-09-13