diff options
Diffstat (limited to 'libssh/messages.c')
-rw-r--r-- | libssh/messages.c | 85 |
1 files changed, 47 insertions, 38 deletions
diff --git a/libssh/messages.c b/libssh/messages.c index 33deb13..79d6bba 100644 --- a/libssh/messages.c +++ b/libssh/messages.c @@ -658,47 +658,56 @@ static int ssh_message_channel_request_reply_default(SSH_MESSAGE *msg) { return SSH_OK; } -SSH_MESSAGE *ssh_message_get(SSH_SESSION *session){ - SSH_MESSAGE *ret; - enter_function(); - while(1){ - if(packet_read(session) || packet_translate(session)){ - leave_function(); - return NULL; +SSH_MESSAGE *ssh_message_get(SSH_SESSION *session) { + SSH_MESSAGE *msg = NULL; + + enter_function(); + + if (msg == NULL) { + goto error; + } + + do { + if ((packet_read(session) != SSH_OK) || + (packet_translate(session) != SSH_OK)) { + goto error; + } + switch(session->in_packet.type) { + case SSH2_MSG_SERVICE_REQUEST: + if (handle_service_request(session) < 0) { + goto error; } - switch(session->in_packet.type){ - case SSH2_MSG_SERVICE_REQUEST: - if(handle_service_request(session)){ - leave_function(); - return NULL; - } - break; - case SSH2_MSG_IGNORE: - case SSH2_MSG_DEBUG: - break; - case SSH2_MSG_USERAUTH_REQUEST: - ret = handle_userauth_request(session); - leave_function(); - return ret; - case SSH2_MSG_CHANNEL_OPEN: - ret = handle_channel_request_open(session); - leave_function(); - return ret; - case SSH2_MSG_CHANNEL_REQUEST: - ret = handle_channel_request(session); - leave_function(); - return ret; - default: - if (handle_unimplemented(session) == 0) { - ssh_set_error(session, SSH_FATAL, - "Unhandled message %d\n", session->in_packet.type); - } - leave_function(); - return NULL; + break; + case SSH2_MSG_IGNORE: + case SSH2_MSG_DEBUG: + break; + case SSH2_MSG_USERAUTH_REQUEST: + msg = handle_userauth_request(session); + + leave_function(); + return msg; + case SSH2_MSG_CHANNEL_OPEN: + msg = handle_channel_request_open(session); + + leave_function(); + return msg; + case SSH2_MSG_CHANNEL_REQUEST: + msg = handle_channel_request(session); + leave_function(); + + return msg; + default: + if (handle_unimplemented(session) == 0) { + ssh_set_error(session, SSH_FATAL, + "Unhandled message %d\n", session->in_packet.type); } + goto error; } - leave_function(); - return NULL; + } while(1); + +error: + leave_function(); + return NULL; } int ssh_message_type(SSH_MESSAGE *msg){ |