From 518d25eba180c7be1323b6cd077d9b025ee127a0 Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Fri, 11 Jun 2010 16:07:30 +0200 Subject: [PATCH] SFTP: limit write() to not produce overly large packets sftp_write() now limits how much data it gets at a time even more than before. Since this function creates a complete outgoing packet based on what gets passed to it, it is crucial that it doesn't create too large packets. With this method, there's also no longer any problem to use very large buffers in your application and feed that to libssh2. I've done numerous tests now with uploading data over SFTP using 100K buffers and I've had no problems with that. --- src/sftp.c | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/src/sftp.c b/src/sftp.c index 695621e..6520952 100644 --- a/src/sftp.c +++ b/src/sftp.c @@ -1402,12 +1402,9 @@ static ssize_t sftp_write(LIBSSH2_SFTP_HANDLE *handle, const char *buffer, unsigned char *s, *data; int rc; - /* There's no point in us accepting a VERY large packet here since we - cannot send it anyway. We just accept 4 times the big size to fill up - the queue somewhat. */ - - if(count > (MAX_SSH_PACKET_LEN*4)) - count = MAX_SSH_PACKET_LEN*4; + /* we limit this to just send a single SSH packet at a time */ + if(count > 32500) + count = 32500; packet_len = handle->handle_len + count + 25;