comparison common-session.c @ 1046:b8f4b7027191 coverity

merge
author Matt Johnston <matt@ucc.asn.au>
date Tue, 24 Feb 2015 22:48:34 +0800
parents 3fb883a6aa81
children 01eea88963f3
comparison
equal deleted inserted replaced
1014:37c510c2ac7c 1046:b8f4b7027191
51 51
52 /* called only at the start of a session, set up initial state */ 52 /* called only at the start of a session, set up initial state */
53 void common_session_init(int sock_in, int sock_out) { 53 void common_session_init(int sock_in, int sock_out) {
54 time_t now; 54 time_t now;
55 55
56 #ifdef DEBUG_TRACE
57 debug_start_net();
58 #endif
59
56 TRACE(("enter session_init")) 60 TRACE(("enter session_init"))
57 61
58 ses.sock_in = sock_in; 62 ses.sock_in = sock_in;
59 ses.sock_out = sock_out; 63 ses.sock_out = sock_out;
60 ses.maxfd = MAX(sock_in, sock_out); 64 ses.maxfd = MAX(sock_in, sock_out);
234 } /* for(;;) */ 238 } /* for(;;) */
235 239
236 /* Not reached */ 240 /* Not reached */
237 } 241 }
238 242
243 static void cleanup_buf(buffer **buf) {
244 if (!*buf) {
245 return;
246 }
247 buf_burn(*buf);
248 buf_free(*buf);
249 *buf = NULL;
250 }
251
239 /* clean up a session on exit */ 252 /* clean up a session on exit */
240 void session_cleanup() { 253 void session_cleanup() {
241 254
242 TRACE(("enter session_cleanup")) 255 TRACE(("enter session_cleanup"))
243 256
245 if (!sessinitdone) { 258 if (!sessinitdone) {
246 TRACE(("leave session_cleanup: !sessinitdone")) 259 TRACE(("leave session_cleanup: !sessinitdone"))
247 return; 260 return;
248 } 261 }
249 262
263 /* Beware of changing order of functions here. */
264
265 /* Must be before extra_session_cleanup() */
266 chancleanup();
267
250 if (ses.extra_session_cleanup) { 268 if (ses.extra_session_cleanup) {
251 ses.extra_session_cleanup(); 269 ses.extra_session_cleanup();
252 } 270 }
253 271
254 chancleanup(); 272 /* After these are freed most functions will exit */
255 273 #ifdef DROPBEAR_CLEANUP
256 /* Cleaning up keys must happen after other cleanup 274 /* listeners call cleanup functions, this should occur before
257 functions which might queue packets */ 275 other session state is freed. */
258 if (ses.session_id) { 276 remove_all_listeners();
259 buf_burn(ses.session_id); 277
260 buf_free(ses.session_id); 278 while (!isempty(&ses.writequeue)) {
261 ses.session_id = NULL; 279 buf_free(dequeue(&ses.writequeue));
262 } 280 }
263 if (ses.hash) { 281
264 buf_burn(ses.hash); 282 m_free(ses.remoteident);
265 buf_free(ses.hash); 283 m_free(ses.authstate.pw_dir);
266 ses.hash = NULL; 284 m_free(ses.authstate.pw_name);
267 } 285 m_free(ses.authstate.pw_shell);
286 m_free(ses.authstate.pw_passwd);
287 m_free(ses.authstate.username);
288 #endif
289
290 cleanup_buf(&ses.session_id);
291 cleanup_buf(&ses.hash);
292 cleanup_buf(&ses.payload);
293 cleanup_buf(&ses.readbuf);
294 cleanup_buf(&ses.writepayload);
295 cleanup_buf(&ses.kexhashbuf);
296 cleanup_buf(&ses.transkexinit);
297 if (ses.dh_K) {
298 mp_clear(ses.dh_K);
299 }
300 m_free(ses.dh_K);
301
268 m_burn(ses.keys, sizeof(struct key_context)); 302 m_burn(ses.keys, sizeof(struct key_context));
269 m_free(ses.keys); 303 m_free(ses.keys);
270 304
271 TRACE(("leave session_cleanup")) 305 TRACE(("leave session_cleanup"))
272 } 306 }
393 TRACE(("leave ident_readln: return %d", pos+1)) 427 TRACE(("leave ident_readln: return %d", pos+1))
394 return pos+1; 428 return pos+1;
395 } 429 }
396 430
397 void ignore_recv_response() { 431 void ignore_recv_response() {
398 // Do nothing 432 /* Do nothing */
399 TRACE(("Ignored msg_request_response")) 433 TRACE(("Ignored msg_request_response"))
400 } 434 }
401 435
402 static void send_msg_keepalive() { 436 static void send_msg_keepalive() {
437 time_t old_time_idle = ses.last_packet_time_idle;
438 struct Channel *chan = get_any_ready_channel();
439
403 CHECKCLEARTOWRITE(); 440 CHECKCLEARTOWRITE();
404 time_t old_time_idle = ses.last_packet_time_idle;
405
406 struct Channel *chan = get_any_ready_channel();
407 441
408 if (chan) { 442 if (chan) {
409 /* Channel requests are preferable, more implementations 443 /* Channel requests are preferable, more implementations
410 handle them than SSH_MSG_GLOBAL_REQUEST */ 444 handle them than SSH_MSG_GLOBAL_REQUEST */
411 TRACE(("keepalive channel request %d", chan->index)) 445 TRACE(("keepalive channel request %d", chan->index))
571 TRACE(("update_channel_prio: not any")) 605 TRACE(("update_channel_prio: not any"))
572 new_prio = DROPBEAR_PRIO_LOWDELAY; 606 new_prio = DROPBEAR_PRIO_LOWDELAY;
573 } 607 }
574 608
575 if (new_prio != ses.socket_prio) { 609 if (new_prio != ses.socket_prio) {
576 TRACE(("Dropbear priority transitioning %4.4s -> %4.4s", (char*)&ses.socket_prio, (char*)&new_prio)) 610 TRACE(("Dropbear priority transitioning %d -> %d", ses.socket_prio, new_prio))
577 set_sock_priority(ses.sock_out, new_prio); 611 set_sock_priority(ses.sock_out, new_prio);
578 ses.socket_prio = new_prio; 612 ses.socket_prio = new_prio;
579 } 613 }
580 } 614 }
581 615