aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorBernhard R. Link <brlink@debian.org>2011-02-13 15:12:39 +0100
committerAndreas Schneider <asn@cryptomilk.org>2011-02-14 22:48:53 +0100
commit7ae59c571afae0bae1f54a4d8b16a456b6469535 (patch)
tree4249cd5f5b64d2dadc48b94ebd314c039e2fa5bf /src
parentb1db0e54ad7dcdb8859c64fc44a4a60328033808 (diff)
downloadlibssh-7ae59c571afae0bae1f54a4d8b16a456b6469535.tar.gz
libssh-7ae59c571afae0bae1f54a4d8b16a456b6469535.tar.xz
libssh-7ae59c571afae0bae1f54a4d8b16a456b6469535.zip
channels: Set errors on return.
Signed-off-by: Andreas Schneider <asn@cryptomilk.org>
Diffstat (limited to 'src')
-rw-r--r--src/channels.c82
1 files changed, 80 insertions, 2 deletions
diff --git a/src/channels.c b/src/channels.c
index 975f2d76..66d60550 100644
--- a/src/channels.c
+++ b/src/channels.c
@@ -75,18 +75,21 @@ ssh_channel ssh_channel_new(ssh_session session) {
channel = malloc(sizeof(struct ssh_channel_struct));
if (channel == NULL) {
+ ssh_set_error_oom(session);
return NULL;
}
memset(channel,0,sizeof(struct ssh_channel_struct));
channel->stdout_buffer = ssh_buffer_new();
if (channel->stdout_buffer == NULL) {
+ ssh_set_error_oom(session);
SAFE_FREE(channel);
return NULL;
}
channel->stderr_buffer = ssh_buffer_new();
if (channel->stderr_buffer == NULL) {
+ ssh_set_error_oom(session);
ssh_buffer_free(channel->stdout_buffer);
SAFE_FREE(channel);
return NULL;
@@ -247,6 +250,7 @@ static int channel_open(ssh_channel channel, const char *type_c, int window,
type = ssh_string_from_char(type_c);
if (type == NULL) {
+ ssh_set_error_oom(session);
leave_function();
return err;
}
@@ -256,6 +260,7 @@ static int channel_open(ssh_channel channel, const char *type_c, int window,
buffer_add_u32(session->out_buffer, htonl(channel->local_channel)) < 0 ||
buffer_add_u32(session->out_buffer, htonl(channel->local_window)) < 0 ||
buffer_add_u32(session->out_buffer, htonl(channel->local_maxpacket)) < 0) {
+ ssh_set_error_oom(session);
ssh_string_free(type);
leave_function();
return err;
@@ -265,6 +270,7 @@ static int channel_open(ssh_channel channel, const char *type_c, int window,
if (payload != NULL) {
if (buffer_add_buffer(session->out_buffer, payload) < 0) {
+ ssh_set_error_oom(session);
leave_function();
return err;
}
@@ -335,6 +341,7 @@ static int grow_window(ssh_session session, ssh_channel channel, int minimumsize
if (buffer_add_u8(session->out_buffer, SSH2_MSG_CHANNEL_WINDOW_ADJUST) < 0 ||
buffer_add_u32(session->out_buffer, htonl(channel->remote_channel)) < 0 ||
buffer_add_u32(session->out_buffer, htonl(new_window - channel->local_window)) < 0) {
+ ssh_set_error_oom(session);
goto error;
}
@@ -824,6 +831,7 @@ int channel_default_bufferize(ssh_channel channel, void *data, int len,
}
if (buffer_add_data(channel->stdout_buffer, data, len) < 0) {
+ ssh_set_error_oom(session);
ssh_buffer_free(channel->stdout_buffer);
channel->stdout_buffer = NULL;
return -1;
@@ -839,6 +847,7 @@ int channel_default_bufferize(ssh_channel channel, void *data, int len,
}
if (buffer_add_data(channel->stderr_buffer, data, len) < 0) {
+ ssh_set_error_oom(session);
ssh_buffer_free(channel->stderr_buffer);
channel->stderr_buffer = NULL;
return -1;
@@ -911,26 +920,31 @@ int ssh_channel_open_forward(ssh_channel channel, const char *remotehost,
payload = ssh_buffer_new();
if (payload == NULL) {
+ ssh_set_error_oom(session);
goto error;
}
str = ssh_string_from_char(remotehost);
if (str == NULL) {
+ ssh_set_error_oom(session);
goto error;
}
if (buffer_add_ssh_string(payload, str) < 0 ||
buffer_add_u32(payload,htonl(remoteport)) < 0) {
+ ssh_set_error_oom(session);
goto error;
}
ssh_string_free(str);
str = ssh_string_from_char(sourcehost);
if (str == NULL) {
+ ssh_set_error_oom(session);
goto error;
}
if (buffer_add_ssh_string(payload, str) < 0 ||
buffer_add_u32(payload,htonl(localport)) < 0) {
+ ssh_set_error_oom(session);
goto error;
}
@@ -1013,9 +1027,11 @@ int ssh_channel_send_eof(ssh_channel channel){
enter_function();
if (buffer_add_u8(session->out_buffer, SSH2_MSG_CHANNEL_EOF) < 0) {
+ ssh_set_error_oom(session);
goto error;
}
if (buffer_add_u32(session->out_buffer,htonl(channel->remote_channel)) < 0) {
+ ssh_set_error_oom(session);
goto error;
}
rc = packet_send(session);
@@ -1070,6 +1086,7 @@ int ssh_channel_close(ssh_channel channel){
if (buffer_add_u8(session->out_buffer, SSH2_MSG_CHANNEL_CLOSE) < 0 ||
buffer_add_u32(session->out_buffer, htonl(channel->remote_channel)) < 0) {
+ ssh_set_error_oom(session);
goto error;
}
@@ -1155,16 +1172,19 @@ int channel_write_common(ssh_channel channel, const void *data,
SSH2_MSG_CHANNEL_EXTENDED_DATA : SSH2_MSG_CHANNEL_DATA) < 0 ||
buffer_add_u32(session->out_buffer,
htonl(channel->remote_channel)) < 0) {
+ ssh_set_error_oom(session);
goto error;
}
/* stderr message has an extra field */
if (is_stderr &&
buffer_add_u32(session->out_buffer, htonl(SSH2_EXTENDED_DATA_STDERR)) < 0) {
+ ssh_set_error_oom(session);
goto error;
}
/* append payload data */
if (buffer_add_u32(session->out_buffer, htonl(effectivelen)) < 0 ||
buffer_add_data(session->out_buffer, data, effectivelen) < 0) {
+ ssh_set_error_oom(session);
goto error;
}
@@ -1347,6 +1367,7 @@ static int channel_request(ssh_channel channel, const char *request,
req = ssh_string_from_char(request);
if (req == NULL) {
+ ssh_set_error_oom(session);
goto error;
}
@@ -1354,6 +1375,7 @@ static int channel_request(ssh_channel channel, const char *request,
buffer_add_u32(session->out_buffer, htonl(channel->remote_channel)) < 0 ||
buffer_add_ssh_string(session->out_buffer, req) < 0 ||
buffer_add_u8(session->out_buffer, reply == 0 ? 0 : 1) < 0) {
+ ssh_set_error_oom(session);
goto error;
}
ssh_string_free(req);
@@ -1361,6 +1383,7 @@ static int channel_request(ssh_channel channel, const char *request,
if (buffer != NULL) {
if (buffer_add_data(session->out_buffer, buffer_get_rest(buffer),
buffer_get_rest_len(buffer)) < 0) {
+ ssh_set_error_oom(session);
goto error;
}
}
@@ -1443,11 +1466,13 @@ int ssh_channel_request_pty_size(ssh_channel channel, const char *terminal,
#endif
buffer = ssh_buffer_new();
if (buffer == NULL) {
+ ssh_set_error_oom(session);
goto error;
}
term = ssh_string_from_char(terminal);
if (term == NULL) {
+ ssh_set_error_oom(session);
goto error;
}
@@ -1458,6 +1483,7 @@ int ssh_channel_request_pty_size(ssh_channel channel, const char *terminal,
buffer_add_u32(buffer, 0) < 0 ||
buffer_add_u32(buffer, htonl(1)) < 0 || /* Add a 0byte string */
buffer_add_u8(buffer, 0) < 0) {
+ ssh_set_error_oom(session);
goto error;
}
@@ -1515,6 +1541,7 @@ int ssh_channel_change_pty_size(ssh_channel channel, int cols, int rows) {
buffer = ssh_buffer_new();
if (buffer == NULL) {
+ ssh_set_error_oom(session);
goto error;
}
@@ -1522,6 +1549,7 @@ int ssh_channel_change_pty_size(ssh_channel channel, int cols, int rows) {
buffer_add_u32(buffer, htonl(rows)) < 0 ||
buffer_add_u32(buffer, 0) < 0 ||
buffer_add_u32(buffer, 0) < 0) {
+ ssh_set_error_oom(session);
goto error;
}
@@ -1567,15 +1595,18 @@ int ssh_channel_request_subsystem(ssh_channel channel, const char *subsys) {
buffer = ssh_buffer_new();
if (buffer == NULL) {
+ ssh_set_error_oom(channel->session);
goto error;
}
subsystem = ssh_string_from_char(subsys);
if (subsystem == NULL) {
+ ssh_set_error_oom(channel->session);
goto error;
}
if (buffer_add_ssh_string(buffer, subsystem) < 0) {
+ ssh_set_error_oom(channel->session);
goto error;
}
@@ -1635,11 +1666,13 @@ int ssh_channel_request_x11(ssh_channel channel, int single_connection, const ch
buffer = ssh_buffer_new();
if (buffer == NULL) {
+ ssh_set_error_oom(channel->session);
goto error;
}
p = ssh_string_from_char(protocol ? protocol : "MIT-MAGIC-COOKIE-1");
if (p == NULL) {
+ ssh_set_error_oom(channel->session);
goto error;
}
@@ -1649,6 +1682,7 @@ int ssh_channel_request_x11(ssh_channel channel, int single_connection, const ch
c = generate_cookie();
}
if (c == NULL) {
+ ssh_set_error_oom(channel->session);
goto error;
}
@@ -1656,6 +1690,7 @@ int ssh_channel_request_x11(ssh_channel channel, int single_connection, const ch
buffer_add_ssh_string(buffer, p) < 0 ||
buffer_add_ssh_string(buffer, c) < 0 ||
buffer_add_u32(buffer, htonl(screen_number)) < 0) {
+ ssh_set_error_oom(channel->session);
goto error;
}
@@ -1708,6 +1743,7 @@ static ssh_channel ssh_channel_accept(ssh_session session, int channeltype,
}
}
+ ssh_set_error(session, SSH_NO_ERROR, "No channel request of this type from server");
return NULL;
}
@@ -1805,12 +1841,14 @@ static int global_request(ssh_session session, const char *request,
}
req = ssh_string_from_char(request);
if (req == NULL) {
+ ssh_set_error_oom(session);
goto error;
}
if (buffer_add_u8(session->out_buffer, SSH2_MSG_GLOBAL_REQUEST) < 0 ||
buffer_add_ssh_string(session->out_buffer, req) < 0 ||
buffer_add_u8(session->out_buffer, reply == 0 ? 0 : 1) < 0) {
+ ssh_set_error_oom(session);
goto error;
}
ssh_string_free(req);
@@ -1819,6 +1857,7 @@ static int global_request(ssh_session session, const char *request,
if (buffer != NULL) {
if (buffer_add_data(session->out_buffer, buffer_get_rest(buffer),
buffer_get_rest_len(buffer)) < 0) {
+ ssh_set_error_oom(session);
goto error;
}
}
@@ -1897,16 +1936,19 @@ int ssh_forward_listen(ssh_session session, const char *address, int port, int *
buffer = ssh_buffer_new();
if (buffer == NULL) {
+ ssh_set_error_oom(session);
goto error;
}
addr = ssh_string_from_char(address ? address : "");
if (addr == NULL) {
+ ssh_set_error_oom(session);
goto error;
}
if (buffer_add_ssh_string(buffer, addr) < 0 ||
buffer_add_u32(buffer, htonl(port)) < 0) {
+ ssh_set_error_oom(session);
goto error;
}
@@ -1956,16 +1998,19 @@ int ssh_forward_cancel(ssh_session session, const char *address, int port) {
buffer = ssh_buffer_new();
if (buffer == NULL) {
+ ssh_set_error_oom(session);
goto error;
}
addr = ssh_string_from_char(address ? address : "");
if (addr == NULL) {
+ ssh_set_error_oom(session);
goto error;
}
if (buffer_add_ssh_string(buffer, addr) < 0 ||
buffer_add_u32(buffer, htonl(port)) < 0) {
+ ssh_set_error_oom(session);
goto error;
}
@@ -1997,25 +2042,30 @@ int ssh_channel_request_env(ssh_channel channel, const char *name, const char *v
buffer = ssh_buffer_new();
if (buffer == NULL) {
+ ssh_set_error_oom(channel->session);
goto error;
}
str = ssh_string_from_char(name);
if (str == NULL) {
+ ssh_set_error_oom(channel->session);
goto error;
}
if (buffer_add_ssh_string(buffer, str) < 0) {
+ ssh_set_error_oom(channel->session);
goto error;
}
ssh_string_free(str);
str = ssh_string_from_char(value);
if (str == NULL) {
+ ssh_set_error_oom(channel->session);
goto error;
}
if (buffer_add_ssh_string(buffer, str) < 0) {
+ ssh_set_error_oom(channel->session);
goto error;
}
@@ -2067,15 +2117,18 @@ int ssh_channel_request_exec(ssh_channel channel, const char *cmd) {
buffer = ssh_buffer_new();
if (buffer == NULL) {
+ ssh_set_error_oom(channel->session);
goto error;
}
command = ssh_string_from_char(cmd);
if (command == NULL) {
goto error;
+ ssh_set_error_oom(channel->session);
}
if (buffer_add_ssh_string(buffer, command) < 0) {
+ ssh_set_error_oom(channel->session);
goto error;
}
@@ -2116,15 +2169,18 @@ int ssh_channel_request_send_signal(ssh_channel channel, const char *sig) {
buffer = ssh_buffer_new();
if (buffer == NULL) {
+ ssh_set_error_oom(channel->session);
goto error;
}
encoded_signal = ssh_string_from_char(sig);
if (encoded_signal == NULL) {
+ ssh_set_error_oom(channel->session);
goto error;
}
if (buffer_add_ssh_string(buffer, encoded_signal) < 0) {
+ ssh_set_error_oom(channel->session);
goto error;
}
@@ -2176,7 +2232,10 @@ int channel_read_buffer(ssh_channel channel, ssh_buffer buffer, uint32_t count,
leave_function();
return r;
}
- buffer_add_data(buffer,buffer_tmp,r);
+ if(buffer_add_data(buffer,buffer_tmp,r) < 0){
+ ssh_set_error_oom(session);
+ r = SSH_ERROR;
+ }
leave_function();
return r;
}
@@ -2197,7 +2256,11 @@ int channel_read_buffer(ssh_channel channel, ssh_buffer buffer, uint32_t count,
leave_function();
return total;
}
- buffer_add_data(buffer,buffer_tmp,r);
+ if(buffer_add_data(buffer,buffer_tmp,r) < 0){
+ ssh_set_error_oom(session);
+ leave_function();
+ return SSH_ERROR;
+ }
total += r;
}
leave_function();
@@ -2699,26 +2762,31 @@ int ssh_channel_open_reverse_forward(ssh_channel channel, const char *remotehost
payload = ssh_buffer_new();
if (payload == NULL) {
+ ssh_set_error_oom(session);
goto error;
}
str = ssh_string_from_char(remotehost);
if (str == NULL) {
+ ssh_set_error_oom(session);
goto error;
}
if (buffer_add_ssh_string(payload, str) < 0 ||
buffer_add_u32(payload,htonl(remoteport)) < 0) {
+ ssh_set_error_oom(session);
goto error;
}
ssh_string_free(str);
str = ssh_string_from_char(sourcehost);
if (str == NULL) {
+ ssh_set_error_oom(session);
goto error;
}
if (buffer_add_ssh_string(payload, str) < 0 ||
buffer_add_u32(payload,htonl(localport)) < 0) {
+ ssh_set_error_oom(session);
goto error;
}
@@ -2761,10 +2829,12 @@ int ssh_channel_request_send_exit_status(ssh_channel channel, int exit_status) {
buffer = ssh_buffer_new();
if (buffer == NULL) {
+ ssh_set_error_oom(channel->session);
goto error;
}
if (buffer_add_u32(buffer, ntohl(exit_status)) < 0) {
+ ssh_set_error_oom(channel->session);
goto error;
}
@@ -2810,36 +2880,44 @@ int ssh_channel_request_send_exit_signal(ssh_channel channel, const char *sig,
buffer = ssh_buffer_new();
if (buffer == NULL) {
+ ssh_set_error_oom(channel->session);
goto error;
}
tmp = ssh_string_from_char(sig);
if (tmp == NULL) {
+ ssh_set_error_oom(channel->session);
goto error;
}
if (buffer_add_ssh_string(buffer, tmp) < 0) {
+ ssh_set_error_oom(channel->session);
goto error;
}
if (buffer_add_u8(buffer, core?1:0) < 0) {
+ ssh_set_error_oom(channel->session);
goto error;
}
ssh_string_free(tmp);
tmp = ssh_string_from_char(errmsg);
if (tmp == NULL) {
+ ssh_set_error_oom(channel->session);
goto error;
}
if (buffer_add_ssh_string(buffer, tmp) < 0) {
+ ssh_set_error_oom(channel->session);
goto error;
}
ssh_string_free(tmp);
tmp = ssh_string_from_char(lang);
if (tmp == NULL) {
+ ssh_set_error_oom(channel->session);
goto error;
}
if (buffer_add_ssh_string(buffer, tmp) < 0) {
+ ssh_set_error_oom(channel->session);
goto error;
}