diff options
author | Matt Johnston <matt@ucc.asn.au> | 2015-09-29 22:19:11 +0800 |
---|---|---|
committer | Matt Johnston <matt@ucc.asn.au> | 2015-09-29 22:19:11 +0800 |
commit | 9e379835c4ebbfef41440416fc72518e48ea8dde (patch) | |
tree | 3e4923491c6ec6a0577f7307e65b306543be9aba | |
parent | 8ccbd216c61539e4d2d7add7be5efd78fb9a9864 (diff) |
avoid invalidated iterator when connection fails
-rw-r--r-- | netio.c | 16 |
1 files changed, 7 insertions, 9 deletions
@@ -174,28 +174,26 @@ void remove_connect_pending() { void set_connect_fds(fd_set *writefd) { m_list_elem *iter; - TRACE(("enter handle_connect_fds")) - for (iter = ses.conn_pending.first; iter; iter = iter->next) { + TRACE(("enter set_connect_fds")) + iter = ses.conn_pending.first; + while (iter) { + m_list_elem *next_iter = iter->next; struct dropbear_progress_connection *c = iter->item; /* Set one going */ - while (c->res_iter && c->sock < 0) - { + while (c->res_iter && c->sock < 0) { connect_try_next(c); } if (c->sock >= 0) { FD_SET(c->sock, writefd); } else { - m_list_elem *remove_iter; /* Final failure */ if (!c->errstring) { c->errstring = m_strdup("unexpected failure"); } c->cb(DROPBEAR_FAILURE, -1, c->cb_data, c->errstring); - /* Safely remove without invalidating iter */ - remove_iter = iter; - iter = iter->prev; - remove_connect(c, remove_iter); + remove_connect(c, iter); } + iter = next_iter; } } |