1
1

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
Этот коммит содержится в:
Andreas Schneider 2009-04-09 14:28:23 +00:00
родитель 38d8875021
Коммит a8bb3024e8

Просмотреть файл

@ -315,38 +315,60 @@ int ssh_message_auth_reply_success(SSH_MESSAGE *msg, int partial) {
} }
static SSH_MESSAGE *handle_channel_request_open(SSH_SESSION *session) { static SSH_MESSAGE *handle_channel_request_open(SSH_SESSION *session) {
SSH_MESSAGE *msg; SSH_MESSAGE *msg = NULL;
STRING *type; STRING *type = NULL;
char *type_c; char *type_c = NULL;
u32 sender, window, packet; u32 sender, window, packet;
enter_function(); enter_function();
msg = message_new(session); msg = message_new(session);
if (msg == NULL) { if (msg == NULL) {
return NULL; return NULL;
} }
msg->type = SSH_CHANNEL_REQUEST_OPEN; msg->type = SSH_CHANNEL_REQUEST_OPEN;
type = buffer_get_ssh_string(session->in_buffer); type = buffer_get_ssh_string(session->in_buffer);
if (type == NULL) {
goto error;
}
type_c = string_to_char(type); type_c = string_to_char(type);
if (type_c == NULL) {
goto error;
}
ssh_log(session, SSH_LOG_PACKET, ssh_log(session, SSH_LOG_PACKET,
"Clients wants to open a %s channel", type_c); "Clients wants to open a %s channel", type_c);
free(type); string_free(type);
buffer_get_u32(session->in_buffer, &sender); buffer_get_u32(session->in_buffer, &sender);
buffer_get_u32(session->in_buffer, &window); buffer_get_u32(session->in_buffer, &window);
buffer_get_u32(session->in_buffer, &packet); buffer_get_u32(session->in_buffer, &packet);
msg->channel_request_open.sender = ntohl(sender); msg->channel_request_open.sender = ntohl(sender);
msg->channel_request_open.window = ntohl(window); msg->channel_request_open.window = ntohl(window);
msg->channel_request_open.packet_size = ntohl(packet); msg->channel_request_open.packet_size = ntohl(packet);
if(!strcmp(type_c,"session")){
if (strcmp(type_c,"session") == 0) {
msg->channel_request_open.type = SSH_CHANNEL_SESSION; msg->channel_request_open.type = SSH_CHANNEL_SESSION;
free(type_c); SAFE_FREE(type_c);
leave_function(); leave_function();
return msg; return msg;
} }
msg->channel_request_open.type = SSH_CHANNEL_UNKNOWN; msg->channel_request_open.type = SSH_CHANNEL_UNKNOWN;
free(type_c); SAFE_FREE(type_c);
leave_function(); leave_function();
return msg; 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){ CHANNEL *ssh_message_channel_request_open_reply_accept(SSH_MESSAGE *msg){