- Markus Moeller fixed the issue also reported by Alexander Lamaison which

caused SFTP reads with large buffers to fail.
This commit is contained in:
Daniel Stenberg 2008-12-19 22:21:36 +00:00
parent 942a81c8d5
commit 70f844e57c
2 changed files with 22 additions and 5 deletions

3
NEWS
View File

@ -1,6 +1,9 @@
Version 0.19 ( )
-------------------------------
- (Dec 18 2008) Markus Moeller fixed the issue also reported by Alexander
Lamaison which caused SFTP reads with large buffers to fail.
- Vlad Grachov brought the new function called
libssh2_session_block_directions() which returns a bitmask for what
directions the connection blocks. It is to be used applications that use

View File

@ -1006,9 +1006,22 @@ libssh2_sftp_read(LIBSSH2_SFTP_HANDLE * handle, char *buffer,
*/
bytes_requested = buffer_maxlen - total_read;
/* 10 = packet_type(1) + request_id(4) + data_length(4) +
end_of_line_flag(1) */
if (bytes_requested > LIBSSH2_SFTP_PACKET_MAXLEN - 10) {
bytes_requested = LIBSSH2_SFTP_PACKET_MAXLEN - 10;
end_of_line_flag(1)
10 is changed to 13 below simple because it seems there's a
"GlobalScape" SFTP server that responds with a slightly too big
buffer at times and we can apparently compensate for that by doing
this trick.
Further details on this issue:
https://sourceforge.net/mailarchive/forum.php?thread_name=9c3275a90811261517v6c0b1da2u918cc1b8370abf83%40mail.gmail.com&forum_name=libssh2-devel
http://forums.globalscape.com/tm.aspx?m=15249
*/
if (bytes_requested > LIBSSH2_SFTP_PACKET_MAXLEN - 13) {
bytes_requested = LIBSSH2_SFTP_PACKET_MAXLEN - 13;
}
#ifdef LIBSSH2_DEBUG_SFTP
_libssh2_debug(session, LIBSSH2_DBG_SFTP,
@ -1032,7 +1045,7 @@ libssh2_sftp_read(LIBSSH2_SFTP_HANDLE * handle, char *buffer,
libssh2_htonu64(s, handle->u.file.offset);
s += 8;
libssh2_htonu32(s, buffer_maxlen);
libssh2_htonu32(s, bytes_requested);
s += 4;
sftp->read_state = libssh2_NB_state_created;
@ -1343,7 +1356,8 @@ libssh2_sftp_write(LIBSSH2_SFTP_HANDLE * handle, const char *buffer,
LIBSSH2_CHANNEL *channel = sftp->channel;
LIBSSH2_SESSION *session = channel->session;
unsigned long data_len, retcode;
/* 25 = packet_len(4) + packet_type(1) + request_id(4) + handle_len(4) + offset(8) + count(4) */
/* 25 = packet_len(4) + packet_type(1) + request_id(4) + handle_len(4) +
offset(8) + count(4) */
ssize_t packet_len = handle->handle_len + count + 25;
unsigned char *s, *data;
int rc;