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

Archive Index This month's Index

Subject: [libssh2] #266: libssh2_scp_recv -> libssh2_channel_read gets sometimes NULL bytes at the end of transfered file

[libssh2] #266: libssh2_scp_recv -> libssh2_channel_read gets sometimes NULL bytes at the end of transfered file

From: libssh2 Trac <trac_at_libssh2.stuge.se>
Date: Mon, 03 Jun 2013 08:17:13 -0000

#266: libssh2_scp_recv -> libssh2_channel_read gets sometimes NULL bytes at the
end of transfered file
---------------------+--------------------
 Reporter: ganguin | Owner:
     Type: defect | Status: new
 Priority: normal | Milestone: 1.4.3
Component: SCP | Version: 1.2.8
 Keywords: | Blocked By:
   Blocks: |
---------------------+--------------------
 I have a little issue with libssh2_scp_recv, I get sometimes a byte too
 much when reading the file with libssh2_channel_read. The byte seems
 always to be a NULL byte.

 on server:
 {{{
 echo "Hello world" > ~/remote_file
 }}}

 code:
 {{{
 char buf[16384];
 ssize_t len = 0;
 struct stat sb;
 LIBSSH2_CHANNEL *scp = libssh2_scp_recv(session, "remote_file", &sb);
 len = libssh2_channel_read(scp, buf, sizeof(buf)); // omitted read loop to
 simplify
 if (len > sb.st_size)
   printf("size: %ld, read bytes: %ld\n", sb.st_size, len);
 libssh2_channel_free(scp);
 }}}

 I get "Hello world\n\0" instead of "Hello world\n".

 As a workaround I trust sb.st_size and use it to truncate read data when
 needed.

 Strangely it seems to happen only to files having ascii only content. The
 test I did with:

 {{{
 dd if=/dev/urandom of=~/remote_file bs=1024 count=1
 }}}

 transfered correctly without the additional NULL byte.

 my libssh2 version is 1.2.8-2 latest version for Ubuntu Precise 12.04. I
 didn't test it on newer versions. But I didn't find any closed ticket
 about it.

-- 
Ticket URL: <https://trac.libssh2.org/ticket/266>
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 2013-06-03

the libssh2 team