1
0
mirror of https://git.libssh.org/projects/libssh.git synced 2025-07-28 01:41:48 +03:00

Fixes infinite loops

Thanks to Xi Wang for the patches
This commit is contained in:
Aris Adamantiadis
2010-04-24 22:46:19 +02:00
parent 833903e8ec
commit 6cdbc01208
3 changed files with 11 additions and 8 deletions

View File

@ -240,7 +240,7 @@ static void select_loop(ssh_session session,ssh_channel channel){
channels[0]=NULL; channels[0]=NULL;
} }
if(channels[0]){ if(channels[0]){
while(channel && channel_is_open(channel) && channel_poll(channel,0)){ while(channel && channel_is_open(channel) && channel_poll(channel,0)>0){
lus=channel_read_buffer(channel,readbuf,0,0); lus=channel_read_buffer(channel,readbuf,0,0);
if(lus==-1){ if(lus==-1){
fprintf(stderr, "Error reading channel: %s\n", fprintf(stderr, "Error reading channel: %s\n",
@ -259,7 +259,7 @@ static void select_loop(ssh_session session,ssh_channel channel){
return; return;
} }
} }
while(channel && channel_is_open(channel) && channel_poll(channel,1)){ /* stderr */ while(channel && channel_is_open(channel) && channel_poll(channel,1)>0){ /* stderr */
lus=channel_read_buffer(channel,readbuf,0,1); lus=channel_read_buffer(channel,readbuf,0,1);
if(lus==-1){ if(lus==-1){
fprintf(stderr, "Error reading channel: %s\n", fprintf(stderr, "Error reading channel: %s\n",
@ -332,7 +332,7 @@ static void select_loop(ssh_session session,ssh_channel channel){
channels[0]=NULL; channels[0]=NULL;
} }
if(outchannels[0]){ if(outchannels[0]){
while(channel && channel_is_open(channel) && channel_poll(channel,0)){ while(channel && channel_is_open(channel) && channel_poll(channel,0)>0){
lus=channel_read(channel,buffer,sizeof(buffer),0); lus=channel_read(channel,buffer,sizeof(buffer),0);
if(lus==-1){ if(lus==-1){
fprintf(stderr, "Error reading channel: %s\n", fprintf(stderr, "Error reading channel: %s\n",
@ -351,7 +351,7 @@ static void select_loop(ssh_session session,ssh_channel channel){
return; return;
} }
} }
while(channel && channel_is_open(channel) && channel_poll(channel,1)){ /* stderr */ while(channel && channel_is_open(channel) && channel_poll(channel,1)>0){ /* stderr */
lus=channel_read(channel,buffer,sizeof(buffer),1); lus=channel_read(channel,buffer,sizeof(buffer),1);
if(lus==-1){ if(lus==-1){
fprintf(stderr, "Error reading channel: %s\n", fprintf(stderr, "Error reading channel: %s\n",

View File

@ -218,7 +218,8 @@ static int wait_auth_status(ssh_session session) {
enter_function(); enter_function();
while (session->auth_state == SSH_AUTH_STATE_NONE) { while (session->auth_state == SSH_AUTH_STATE_NONE) {
ssh_handle_packets(session,-1); if (ssh_handle_packets(session,-1) != SSH_OK)
break;
} }
switch(session->auth_state){ switch(session->auth_state){
case SSH_AUTH_STATE_ERROR: case SSH_AUTH_STATE_ERROR:

View File

@ -38,7 +38,8 @@ static int wait_auth1_status(ssh_session session) {
enter_function(); enter_function();
/* wait for a packet */ /* wait for a packet */
while(session->auth_state == SSH_AUTH_STATE_NONE) while(session->auth_state == SSH_AUTH_STATE_NONE)
ssh_handle_packets(session,-1); if (ssh_handle_packets(session,-1) != SSH_OK)
break;
ssh_log(session,SSH_LOG_PROTOCOL,"Auth state : %d",session->auth_state); ssh_log(session,SSH_LOG_PROTOCOL,"Auth state : %d",session->auth_state);
leave_function(); leave_function();
switch(session->auth_state) { switch(session->auth_state) {
@ -57,9 +58,10 @@ void ssh_auth1_handler(ssh_session session, uint8_t type){
ssh_set_error(session,SSH_FATAL,"SSH_SMSG_SUCCESS or FAILED received in wrong state"); ssh_set_error(session,SSH_FATAL,"SSH_SMSG_SUCCESS or FAILED received in wrong state");
return; return;
} }
if(type==SSH_SMSG_SUCCESS) if(type==SSH_SMSG_SUCCESS){
session->auth_state=SSH_AUTH_STATE_SUCCESS; session->auth_state=SSH_AUTH_STATE_SUCCESS;
if(type==SSH_SMSG_FAILURE) session->session_state=SSH_SESSION_STATE_AUTHENTICATED;
} else if(type==SSH_SMSG_FAILURE)
session->auth_state=SSH_AUTH_STATE_FAILED; session->auth_state=SSH_AUTH_STATE_FAILED;
} }