diff options
author | rofl0r <retnyg@gmx.net> | 2011-08-06 10:31:43 +0200 |
---|---|---|
committer | Andreas Schneider <asn@cryptomilk.org> | 2011-08-06 11:11:12 +0200 |
commit | 563fbe4de8ee090b40b50415a86f9a3da16f46b0 (patch) | |
tree | 03080ec3c56aee324b11c190415c9e5647ecdeec /src | |
parent | 39f962c91eb4575a65edc7d984ce3f1a699097b8 (diff) | |
download | libssh-563fbe4de8ee090b40b50415a86f9a3da16f46b0.tar.gz libssh-563fbe4de8ee090b40b50415a86f9a3da16f46b0.tar.xz libssh-563fbe4de8ee090b40b50415a86f9a3da16f46b0.zip |
channels: Fix checking for fatal errors.
We need this that we don't end up in and infinite poll loop.
Diffstat (limited to 'src')
-rw-r--r-- | src/channels.c | 5 | ||||
-rw-r--r-- | src/poll.c | 7 | ||||
-rw-r--r-- | src/socket.c | 38 |
3 files changed, 31 insertions, 19 deletions
diff --git a/src/channels.c b/src/channels.c index f01d52e8..ddccb97c 100644 --- a/src/channels.c +++ b/src/channels.c @@ -1452,6 +1452,11 @@ static int channel_request(ssh_channel channel, const char *request, } while(channel->request_state == SSH_CHANNEL_REQ_STATE_PENDING){ ssh_handle_packets(session,-1); + if(session->session_state == SSH_SESSION_STATE_ERROR) { + channel->request_state = SSH_CHANNEL_REQ_STATE_ERROR; + break; + } + } /* we received something */ switch (channel->request_state){ @@ -612,11 +612,16 @@ int ssh_poll_ctx_dopoll(ssh_poll_ctx ctx, int timeout) { if (!ctx->pollfds[i].revents) { i++; } else { + int ret; + p = ctx->pollptrs[i]; fd = ctx->pollfds[i].fd; revents = ctx->pollfds[i].revents; - if (p->cb && p->cb(p, fd, revents, p->cb_data) < 0) { + if (p->cb && (ret = p->cb(p, fd, revents, p->cb_data)) < 0) { + if (ret == -2) { + return -1; + } /* the poll was removed, reload the used counter and start again */ used = ctx->polls_used; i=0; diff --git a/src/socket.c b/src/socket.c index 53ebc19f..a4a16b13 100644 --- a/src/socket.c +++ b/src/socket.c @@ -246,32 +246,34 @@ int ssh_socket_pollcallback(struct ssh_poll_handle_struct *p, socket_t fd, int r s->read_wontblock=1; r=ssh_socket_unbuffered_read(s,buffer,sizeof(buffer)); if(r<0){ - if(p != NULL) { - ssh_poll_remove_events(p, POLLIN); - } + if(p != NULL) { + ssh_poll_remove_events(p, POLLIN); + } if(s->callbacks && s->callbacks->exception){ s->callbacks->exception( SSH_SOCKET_EXCEPTION_ERROR, s->last_errno,s->callbacks->userdata); - /* p may have been freed, so don't use it - * anymore in this function */ - p = NULL; + /* p may have been freed, so don't use it + * anymore in this function */ + p = NULL; + return -2; } } if(r==0){ - if(p != NULL) { - ssh_poll_remove_events(p, POLLIN); - } - if(p != NULL) { - ssh_poll_remove_events(p, POLLIN); - } + if(p != NULL) { + ssh_poll_remove_events(p, POLLIN); + } + if(p != NULL) { + ssh_poll_remove_events(p, POLLIN); + } if(s->callbacks && s->callbacks->exception){ s->callbacks->exception( SSH_SOCKET_EXCEPTION_EOF, 0,s->callbacks->userdata); - /* p may have been freed, so don't use it - * anymore in this function */ - p = NULL; + /* p may have been freed, so don't use it + * anymore in this function */ + p = NULL; + return -2; } } if(r>0){ @@ -282,9 +284,9 @@ int ssh_socket_pollcallback(struct ssh_poll_handle_struct *p, socket_t fd, int r buffer_get_rest_len(s->in_buffer), s->callbacks->userdata); buffer_pass_bytes(s->in_buffer,r); - /* p may have been freed, so don't use it - * anymore in this function */ - p = NULL; + /* p may have been freed, so don't use it + * anymore in this function */ + p = NULL; } } } |