aboutsummaryrefslogtreecommitdiff
path: root/libssh
diff options
context:
space:
mode:
authorAris Adamantiadis <aris@0xbadc0de.be>2008-06-27 16:56:24 +0000
committerAris Adamantiadis <aris@0xbadc0de.be>2008-06-27 16:56:24 +0000
commitb8dac18d0e457e40f8a33bc72bd9242fe740fffe (patch)
treee26f3327fe28ba03227e79b60aa7934940634912 /libssh
parent0d1e22f5f883e1c95a87698cc9a0b48371665623 (diff)
downloadlibssh-b8dac18d0e457e40f8a33bc72bd9242fe740fffe.tar.gz
libssh-b8dac18d0e457e40f8a33bc72bd9242fe740fffe.tar.xz
libssh-b8dac18d0e457e40f8a33bc72bd9242fe740fffe.zip
fixed a problem when a channel blocking read was bigger than size of buffer
+ window git-svn-id: svn+ssh://svn.berlios.de/svnroot/repos/libssh/trunk@178 7dcaeef0-15fb-0310-b436-a5af3365683c
Diffstat (limited to 'libssh')
-rw-r--r--libssh/channels.c10
1 files changed, 7 insertions, 3 deletions
diff --git a/libssh/channels.c b/libssh/channels.c
index 8b4d40b2..c019d0cd 100644
--- a/libssh/channels.c
+++ b/libssh/channels.c
@@ -148,8 +148,8 @@ CHANNEL *ssh_channel_from_local(SSH_SESSION *session,u32 num){
return channel;
}
-static void grow_window(SSH_SESSION *session, CHANNEL *channel){
- u32 new_window=WINDOWBASE;
+static void grow_window(SSH_SESSION *session, CHANNEL *channel, int minimumsize){
+ u32 new_window=minimumsize>WINDOWBASE ? minimumsize : WINDOWBASE;
enter_function();
buffer_add_u8(session->out_buffer,SSH2_MSG_CHANNEL_WINDOW_ADJUST);
buffer_add_u32(session->out_buffer,htonl(channel->remote_channel));
@@ -837,6 +837,10 @@ int channel_read(CHANNEL *channel, BUFFER *buffer,int bytes,int is_stderr){
else
stdbuf=channel->stdout_buffer;
+ /* We may have problem if the window is too small to accept as much data as asked */
+ ssh_log(session,SSH_LOG_PROTOCOL,"Read (%d) buffered : %d bytes. Window: %d",bytes,buffer_get_rest_len(stdbuf),channel->local_window);
+ if(bytes > buffer_get_rest_len(stdbuf) + channel->local_window)
+ grow_window(session,channel,bytes - buffer_get_rest_len(stdbuf));
/* block reading if asked bytes=0 */
while((buffer_get_rest_len(stdbuf)==0) || (buffer_get_rest_len(stdbuf) < bytes)){
if(channel->remote_eof && buffer_get_rest_len(stdbuf)==0){
@@ -854,7 +858,7 @@ int channel_read(CHANNEL *channel, BUFFER *buffer,int bytes,int is_stderr){
packet_parse(session);
}
if(channel->local_window < WINDOWLIMIT)
- grow_window(session,channel);
+ grow_window(session,channel,0);
if(bytes==0){
/* write the ful buffer informations */
buffer_add_data(buffer,buffer_get_rest(stdbuf),buffer_get_rest_len(stdbuf));