comparison netio.c @ 1152:57d09741d46d

avoid invalidated iterator when connection fails
author Matt Johnston <matt@ucc.asn.au>
date Tue, 29 Sep 2015 22:19:11 +0800
parents a7c4a70ae495
children 750ec4ec4cbe 3b624ad2dc5e
comparison
equal deleted inserted replaced
1151:a550e1e2e2a9 1152:57d09741d46d
172 } 172 }
173 173
174 174
175 void set_connect_fds(fd_set *writefd) { 175 void set_connect_fds(fd_set *writefd) {
176 m_list_elem *iter; 176 m_list_elem *iter;
177 TRACE(("enter handle_connect_fds")) 177 TRACE(("enter set_connect_fds"))
178 for (iter = ses.conn_pending.first; iter; iter = iter->next) { 178 iter = ses.conn_pending.first;
179 while (iter) {
180 m_list_elem *next_iter = iter->next;
179 struct dropbear_progress_connection *c = iter->item; 181 struct dropbear_progress_connection *c = iter->item;
180 /* Set one going */ 182 /* Set one going */
181 while (c->res_iter && c->sock < 0) 183 while (c->res_iter && c->sock < 0) {
182 {
183 connect_try_next(c); 184 connect_try_next(c);
184 } 185 }
185 if (c->sock >= 0) { 186 if (c->sock >= 0) {
186 FD_SET(c->sock, writefd); 187 FD_SET(c->sock, writefd);
187 } else { 188 } else {
188 m_list_elem *remove_iter;
189 /* Final failure */ 189 /* Final failure */
190 if (!c->errstring) { 190 if (!c->errstring) {
191 c->errstring = m_strdup("unexpected failure"); 191 c->errstring = m_strdup("unexpected failure");
192 } 192 }
193 c->cb(DROPBEAR_FAILURE, -1, c->cb_data, c->errstring); 193 c->cb(DROPBEAR_FAILURE, -1, c->cb_data, c->errstring);
194 /* Safely remove without invalidating iter */ 194 remove_connect(c, iter);
195 remove_iter = iter; 195 }
196 iter = iter->prev; 196 iter = next_iter;
197 remove_connect(c, remove_iter);
198 }
199 } 197 }
200 } 198 }
201 199
202 void handle_connect_fds(fd_set *writefd) { 200 void handle_connect_fds(fd_set *writefd) {
203 m_list_elem *iter; 201 m_list_elem *iter;