summaryrefslogtreecommitdiffstats
path: root/libssh/messages.c
diff options
context:
space:
mode:
authorAndreas Schneider <mail@cynapses.org>2009-04-09 14:28:23 +0000
committerAndreas Schneider <mail@cynapses.org>2009-04-09 14:28:23 +0000
commita8bb3024e809c37be8c9598387564672b954e1da (patch)
treec4b64c23f66e8453a3c0220b3df30d3c2548072b /libssh/messages.c
parent38d88750211a71551a3a922385790832d6a3510b (diff)
downloadlibssh-a8bb3024e809c37be8c9598387564672b954e1da.tar.gz
libssh-a8bb3024e809c37be8c9598387564672b954e1da.tar.xz
libssh-a8bb3024e809c37be8c9598387564672b954e1da.zip
Add error checking to handle_channel_request_open().
git-svn-id: svn+ssh://svn.berlios.de/svnroot/repos/libssh/trunk@445 7dcaeef0-15fb-0310-b436-a5af3365683c
Diffstat (limited to 'libssh/messages.c')
-rw-r--r--libssh/messages.c82
1 files changed, 52 insertions, 30 deletions
diff --git a/libssh/messages.c b/libssh/messages.c
index 8b32cdf..7721cbd 100644
--- a/libssh/messages.c
+++ b/libssh/messages.c
@@ -314,39 +314,61 @@ int ssh_message_auth_reply_success(SSH_MESSAGE *msg, int partial) {
return packet_send(msg->session);
}
-static SSH_MESSAGE *handle_channel_request_open(SSH_SESSION *session){
- SSH_MESSAGE *msg;
- STRING *type;
- char *type_c;
- u32 sender, window, packet;
+static SSH_MESSAGE *handle_channel_request_open(SSH_SESSION *session) {
+ SSH_MESSAGE *msg = NULL;
+ STRING *type = NULL;
+ char *type_c = NULL;
+ u32 sender, window, packet;
- enter_function();
- msg = message_new(session);
- if (msg == NULL) {
- return NULL;
- }
- msg->type=SSH_CHANNEL_REQUEST_OPEN;
- type=buffer_get_ssh_string(session->in_buffer);
- type_c=string_to_char(type);
- ssh_log(session, SSH_LOG_PACKET,
- "Clients wants to open a %s channel", type_c);
- free(type);
- buffer_get_u32(session->in_buffer,&sender);
- buffer_get_u32(session->in_buffer,&window);
- buffer_get_u32(session->in_buffer,&packet);
- msg->channel_request_open.sender=ntohl(sender);
- msg->channel_request_open.window=ntohl(window);
- msg->channel_request_open.packet_size=ntohl(packet);
- if(!strcmp(type_c,"session")){
- msg->channel_request_open.type=SSH_CHANNEL_SESSION;
- free(type_c);
- leave_function();
- return msg;
- }
- msg->channel_request_open.type=SSH_CHANNEL_UNKNOWN;
- free(type_c);
+ enter_function();
+
+ msg = message_new(session);
+ if (msg == NULL) {
+ return NULL;
+ }
+
+ msg->type = SSH_CHANNEL_REQUEST_OPEN;
+
+ type = buffer_get_ssh_string(session->in_buffer);
+ if (type == NULL) {
+ goto error;
+ }
+ type_c = string_to_char(type);
+ if (type_c == NULL) {
+ goto error;
+ }
+
+ ssh_log(session, SSH_LOG_PACKET,
+ "Clients wants to open a %s channel", type_c);
+ string_free(type);
+
+ buffer_get_u32(session->in_buffer, &sender);
+ buffer_get_u32(session->in_buffer, &window);
+ buffer_get_u32(session->in_buffer, &packet);
+
+ msg->channel_request_open.sender = ntohl(sender);
+ msg->channel_request_open.window = ntohl(window);
+ msg->channel_request_open.packet_size = ntohl(packet);
+
+ if (strcmp(type_c,"session") == 0) {
+ msg->channel_request_open.type = SSH_CHANNEL_SESSION;
+ SAFE_FREE(type_c);
leave_function();
return msg;
+ }
+
+ msg->channel_request_open.type = SSH_CHANNEL_UNKNOWN;
+ SAFE_FREE(type_c);
+
+ leave_function();
+ return msg;
+error:
+ string_free(type);
+ SAFE_FREE(type_c);
+ ssh_message_free(msg);
+
+ leave_function();
+ return NULL;
}
CHANNEL *ssh_message_channel_request_open_reply_accept(SSH_MESSAGE *msg){