www.libssh2.org | Daily snapshots | Mailing list archive | Docs | Examples | github

Archive Index This month's Index

Subject: [libssh2] #281: Possible bug in direct_tcpip.c

[libssh2] #281: Possible bug in direct_tcpip.c

From: libssh2 Trac <trac_at_libssh2.stuge.se>
Date: Wed, 08 Jan 2014 10:35:34 -0000

#281: Possible bug in direct_tcpip.c
----------------------+--------------------
 Reporter: jakob | Owner:
     Type: defect | Status: new
 Priority: normal | Milestone: 1.4.3
Component: examples | Version: 1.4.2
 Keywords: | Blocked By:
   Blocks: |
----------------------+--------------------
 I think I found a bug in direct_tcpip.c

 This is the problematic section. It tries to send "len" bytes stored in
 "buf" on a channel.

 {{{
 235 wr = 0;
 236 do {
 237 i = libssh2_channel_write(channel, buf, len);
 238 if (i < 0) {
 239 fprintf(stderr, "libssh2_channel_write: %d\n",
 i);
 240 goto shutdown;
 241 }
 242 wr += i;
 243 } while(i > 0 && wr < len);
 }}}

 However, when libssh2_channel_write fails to write everything at once,
 then this code will try writing the data in buf again from the beginning!
 Also, I don't know why it aborts when i=0, this would just ignore some of
 the data.

 I think this code should rather like this:

 {{{
 235 wr = 0;
 236 while (wr<len) {
 237 i = libssh2_channel_write(channel, buf+wr, len);
 238 if (i < 0) {
 239 fprintf(stderr, "libssh2_channel_write: %d\n",
 i);
 240 goto shutdown;
 241 }
 242 wr += i;
 243 }
 }}}

 Please excuse that I include the code inline in this ticket, I am not very
 familiar with git, but I wanted to report this issue nevertheless.

-- 
Ticket URL: <https://trac.libssh2.org/ticket/281>
libssh2 <https://trac.libssh2.org/>
C library for writing portable SSH2 clients
_______________________________________________
libssh2-devel http://cool.haxx.se/cgi-bin/mailman/listinfo/libssh2-devel
Received on 2014-01-08

the libssh2 team