aboutsummaryrefslogtreecommitdiff
path: root/src/poll.c
diff options
context:
space:
mode:
authorMeng Tan <mtan@wallix.com>2018-03-29 11:34:54 +0200
committerAndreas Schneider <asn@cryptomilk.org>2018-04-10 11:20:52 +0200
commite005fd310f614fdedc1f5ac69843d5d41acf0b42 (patch)
treeffb7d36b08bde84bf3c55c8ad2121909896acf96 /src/poll.c
parentfb2fefb3c65996abac7defcdc0ea758060ea3111 (diff)
downloadlibssh-e005fd310f614fdedc1f5ac69843d5d41acf0b42.tar.gz
libssh-e005fd310f614fdedc1f5ac69843d5d41acf0b42.tar.xz
libssh-e005fd310f614fdedc1f5ac69843d5d41acf0b42.zip
Fix ssh_event_add_session() when session socket has two pollhandlers
Signed-off-by: Meng Tan <mtan@wallix.com> Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
Diffstat (limited to 'src/poll.c')
-rw-r--r--src/poll.c23
1 files changed, 18 insertions, 5 deletions
diff --git a/src/poll.c b/src/poll.c
index c698c13f..8872aa3c 100644
--- a/src/poll.c
+++ b/src/poll.c
@@ -812,20 +812,23 @@ void ssh_event_remove_poll(ssh_event event, ssh_poll_handle p)
* SSH_ERROR on failure
*/
int ssh_event_add_session(ssh_event event, ssh_session session) {
- unsigned int i;
ssh_poll_handle p;
#ifdef WITH_SERVER
struct ssh_iterator *iterator;
#endif
-
+
if(event == NULL || event->ctx == NULL || session == NULL) {
return SSH_ERROR;
}
if(session->default_poll_ctx == NULL) {
return SSH_ERROR;
}
- for(i = 0; i < session->default_poll_ctx->polls_used; i++) {
- p = session->default_poll_ctx->pollptrs[i];
+ while (session->default_poll_ctx->polls_used > 0) {
+ p = session->default_poll_ctx->pollptrs[0];
+ /*
+ * ssh_poll_ctx_remove() decrements
+ * session->default_poll_ctx->polls_used
+ */
ssh_poll_ctx_remove(session->default_poll_ctx, p);
ssh_poll_ctx_add(event->ctx, p);
/* associate the pollhandler with a session so we can put it back
@@ -961,11 +964,21 @@ int ssh_event_remove_session(ssh_event event, ssh_session session) {
for(i = 0; i < used; i++) {
p = event->ctx->pollptrs[i];
if(p->session == session){
+ /*
+ * ssh_poll_ctx_remove() decrements
+ * event->ctx->polls_used
+ */
ssh_poll_ctx_remove(event->ctx, p);
p->session = NULL;
ssh_poll_ctx_add(session->default_poll_ctx, p);
rc = SSH_OK;
- used = 0;
+ /*
+ * Restart the loop!
+ * A session can initially have two pollhandlers.
+ */
+ used = event->ctx->polls_used;
+ i = 0;
+
}
}
#ifdef WITH_SERVER