mirror of
https://github.com/clearml/dropbear
synced 2025-04-21 06:34:28 +00:00
avoid invalidated iterator when connection fails
This commit is contained in:
parent
8ccbd216c6
commit
9e379835c4
16
netio.c
16
netio.c
@ -174,28 +174,26 @@ void remove_connect_pending() {
|
|||||||
|
|
||||||
void set_connect_fds(fd_set *writefd) {
|
void set_connect_fds(fd_set *writefd) {
|
||||||
m_list_elem *iter;
|
m_list_elem *iter;
|
||||||
TRACE(("enter handle_connect_fds"))
|
TRACE(("enter set_connect_fds"))
|
||||||
for (iter = ses.conn_pending.first; iter; iter = iter->next) {
|
iter = ses.conn_pending.first;
|
||||||
|
while (iter) {
|
||||||
|
m_list_elem *next_iter = iter->next;
|
||||||
struct dropbear_progress_connection *c = iter->item;
|
struct dropbear_progress_connection *c = iter->item;
|
||||||
/* Set one going */
|
/* Set one going */
|
||||||
while (c->res_iter && c->sock < 0)
|
while (c->res_iter && c->sock < 0) {
|
||||||
{
|
|
||||||
connect_try_next(c);
|
connect_try_next(c);
|
||||||
}
|
}
|
||||||
if (c->sock >= 0) {
|
if (c->sock >= 0) {
|
||||||
FD_SET(c->sock, writefd);
|
FD_SET(c->sock, writefd);
|
||||||
} else {
|
} else {
|
||||||
m_list_elem *remove_iter;
|
|
||||||
/* Final failure */
|
/* Final failure */
|
||||||
if (!c->errstring) {
|
if (!c->errstring) {
|
||||||
c->errstring = m_strdup("unexpected failure");
|
c->errstring = m_strdup("unexpected failure");
|
||||||
}
|
}
|
||||||
c->cb(DROPBEAR_FAILURE, -1, c->cb_data, c->errstring);
|
c->cb(DROPBEAR_FAILURE, -1, c->cb_data, c->errstring);
|
||||||
/* Safely remove without invalidating iter */
|
remove_connect(c, iter);
|
||||||
remove_iter = iter;
|
|
||||||
iter = iter->prev;
|
|
||||||
remove_connect(c, remove_iter);
|
|
||||||
}
|
}
|
||||||
|
iter = next_iter;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user