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

Archive Index This month's Index

Subject: Re: [libssh2] Corrupted scp transfers

Re: [libssh2] Corrupted scp transfers

From: Dan Fandrich <dan_at_coneharvesters.com>
Date: Thu, 5 Apr 2007 14:39:01 -0700

On Mon, Mar 26, 2007 at 04:15:36PM -0700, Dan Fandrich wrote:
> I've added some scp tests to curl's test suite which use libssh2, and
> I've found that the test file uploads (which are 30 byte files) are
> corrupted sometimes. The uploaded files end up being 0 length. Running
> the tests several times in succession usually causes it to work at least
> once, so it looks like a timing related problem. I've tested on Linux
> x86 systems using both 2.4 and 2.6 kernels and OpenSSH 3.1 and 3.9.

The following patch fixes this problem for me. If a channel close message
has not been received by the time libssh2_channel_close is called,
this waits for it.

RCS file: /cvsroot/libssh2/libssh2/src/channel.c,v
retrieving revision 1.39
diff -u -r1.39 channel.c
--- channel.c 31 Mar 2007 20:28:29 -0000 1.39
+++ channel.c 5 Apr 2007 21:36:18 -0000
@@ -1381,6 +1381,7 @@
 {
         LIBSSH2_SESSION *session = channel->session;
         unsigned char packet[5];
+ int rc = 0;
 
         if (channel->local.close) {
                 /* Already closed, act like we sent another close, even though we didn't... shhhhhh */
@@ -1401,9 +1402,22 @@
                 return -1;
         }
 
- /* TODO: Wait up to a timeout value for a CHANNEL_CLOSE to come back, to avoid the problem alluded to in channel_nextid */
+ /* Wait for the remote SSH_MSG_CHANNEL_CLOSE message */
+ if (!channel->remote.close) {
+ libssh2pack_t ret;
+ /* set blocking mode */
+ int bl = _libssh2_channel_set_blocking(channel, 1);
+ do {
+ ret = libssh2_packet_read(session);
+ if ((ret < 0) && (ret != PACKET_EAGAIN)) {
+ rc = -1;
+ }
+ } while (ret != SSH_MSG_CHANNEL_CLOSE && rc == 0);
 
- return 0;
+ _libssh2_channel_set_blocking(channel, bl);
+ }
+
+ return rc;
 }
 /* }}} */
 

>>> Dan

-- 
http://www.MoveAnnouncer.com              The web change of address service
          Let webmasters know that your web site has moved
-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys-and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
libssh2-devel mailing list
libssh2-devel_at_lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/libssh2-devel
Received on 2007-04-05

the libssh2 team