1
0
mirror of https://git.libssh.org/projects/libssh.git synced 2025-11-30 13:01:23 +03:00

Add return values and error checking to channel_default_bufferize().

git-svn-id: svn+ssh://svn.berlios.de/svnroot/repos/libssh/trunk@414 7dcaeef0-15fb-0310-b436-a5af3365683c
This commit is contained in:
Andreas Schneider
2009-04-07 14:10:45 +00:00
parent 8d3a43db7a
commit aea8587586
2 changed files with 39 additions and 16 deletions

View File

@@ -600,7 +600,7 @@ STRING *ssh_encrypt_rsa1(SSH_SESSION *session, STRING *data, PUBLIC_KEY *key);
/* channel.c */ /* channel.c */
void channel_handle(SSH_SESSION *session, int type); void channel_handle(SSH_SESSION *session, int type);
CHANNEL *channel_new(SSH_SESSION *session); CHANNEL *channel_new(SSH_SESSION *session);
void channel_default_bufferize(CHANNEL *channel, void *data, int len, int channel_default_bufferize(CHANNEL *channel, void *data, int len,
int is_stderr); int is_stderr);
u32 ssh_channel_new_id(SSH_SESSION *session); u32 ssh_channel_new_id(SSH_SESSION *session);
CHANNEL *ssh_channel_from_local(SSH_SESSION *session,u32 num); CHANNEL *ssh_channel_from_local(SSH_SESSION *session,u32 num);

View File

@@ -271,7 +271,11 @@ static void channel_rcv_data(SSH_SESSION *session,int is_stderr){
"Data packet too big for our window(%zu vs %d)", "Data packet too big for our window(%zu vs %d)",
string_len(str), string_len(str),
channel->local_window); channel->local_window);
channel_default_bufferize(channel,str->string,string_len(str), is_stderr); if (channel_default_bufferize(channel,str->string,string_len(str), is_stderr) < 0) {
string_free(str);
leave_function();
return;
}
if(string_len(str)<=channel->local_window) if(string_len(str)<=channel->local_window)
channel->local_window-=string_len(str); channel->local_window-=string_len(str);
else else
@@ -424,22 +428,41 @@ void channel_handle(SSH_SESSION *session, int type){
/* when data has been received from the ssh server, it can be applied to the known /* when data has been received from the ssh server, it can be applied to the known
user function, with help of the callback, or inserted here */ user function, with help of the callback, or inserted here */
/* XXX is the window changed ? */ /* XXX is the window changed ? */
void channel_default_bufferize(CHANNEL *channel, void *data, int len, int is_stderr){ int channel_default_bufferize(CHANNEL *channel, void *data, int len,
struct ssh_session *session = channel->session; int is_stderr) {
struct ssh_session *session = channel->session;
ssh_log(session, SSH_LOG_RARE, ssh_log(session, SSH_LOG_RARE,
"placing %d bytes into channel buffer (stderr=%d)", len, is_stderr); "placing %d bytes into channel buffer (stderr=%d)", len, is_stderr);
if(!is_stderr){ if (! is_stderr) {
/* stdout */ /* stdout */
if(!channel->stdout_buffer) if(channel->stdout_buffer == NULL) {
channel->stdout_buffer=buffer_new(); channel->stdout_buffer = buffer_new();
buffer_add_data(channel->stdout_buffer,data,len); if (channel->stdout_buffer == NULL) {
} else { return -1;
/* stderr */ }
if(!channel->stderr_buffer)
channel->stderr_buffer=buffer_new();
buffer_add_data(channel->stderr_buffer,data,len);
} }
if (buffer_add_data(channel->stdout_buffer, data, len) < 0) {
buffer_free(channel->stdout_buffer);
return -1;
}
} else {
/* stderr */
if (channel->stderr_buffer == NULL) {
channel->stderr_buffer = buffer_new();
if (channel->stderr_buffer == NULL) {
return -1;
}
}
if (buffer_add_data(channel->stderr_buffer, data, len) < 0) {
buffer_free(channel->stderr_buffer);
return -1;
}
}
return 0;
} }
/** \brief open a session channel (suited for a shell. Not tcp Forwarding) /** \brief open a session channel (suited for a shell. Not tcp Forwarding)