diff options
author | Matt Johnston <matt@ucc.asn.au> | 2018-02-17 19:29:51 +0800 |
---|---|---|
committer | Matt Johnston <matt@ucc.asn.au> | 2018-02-17 19:29:51 +0800 |
commit | 7e8094d53a1c01ac671156ff2e67157b64d01a3a (patch) | |
tree | c88345f5bdd118eb9414dff5ab5c307bb1806c57 /common-session.c | |
parent | f7a664f127d3dfde0e7c7a9ca74b1d14f9a2f983 (diff) | |
parent | f042eb41ab0d31f8ba0c5ccc9c848ad01f08f986 (diff) |
merge from main
--HG--
branch : fuzz
Diffstat (limited to 'common-session.c')
-rw-r--r-- | common-session.c | 40 |
1 files changed, 16 insertions, 24 deletions
diff --git a/common-session.c b/common-session.c index aa0dddb..556adeb 100644 --- a/common-session.c +++ b/common-session.c @@ -43,13 +43,6 @@ static void read_session_identification(void); struct sshsession ses; /* GLOBAL */ -/* need to know if the session struct has been initialised, this way isn't the - * cleanest, but works OK */ -int sessinitdone = 0; /* GLOBAL */ - -/* this is set when we get SIGINT or SIGTERM, the handler is in main.c */ -int exitflag = 0; /* GLOBAL */ - /* called only at the start of a session, set up initial state */ void common_session_init(int sock_in, int sock_out) { time_t now; @@ -86,13 +79,13 @@ void common_session_init(int sock_in, int sock_out) { if (!fuzz.fuzzing) #endif { - if (pipe(ses.signal_pipe) < 0) { - dropbear_exit("Signal pipe failed"); - } - setnonblocking(ses.signal_pipe[0]); - setnonblocking(ses.signal_pipe[1]); - ses.maxfd = MAX(ses.maxfd, ses.signal_pipe[0]); - ses.maxfd = MAX(ses.maxfd, ses.signal_pipe[1]); + if (pipe(ses.signal_pipe) < 0) { + dropbear_exit("Signal pipe failed"); + } + setnonblocking(ses.signal_pipe[0]); + setnonblocking(ses.signal_pipe[1]); + ses.maxfd = MAX(ses.maxfd, ses.signal_pipe[0]); + ses.maxfd = MAX(ses.maxfd, ses.signal_pipe[1]); } ses.writepayload = buf_new(TRANS_MAX_PAYLOAD_LEN); @@ -169,9 +162,8 @@ void session_loop(void(*loophandler)()) { if (!fuzz.fuzzing) #endif { - FD_SET(ses.signal_pipe[0], &readfd); + FD_SET(ses.signal_pipe[0], &readfd); } - ses.channel_signal_pending = 0; /* set up for channels which can be read/written */ setchannelfds(&readfd, &writefd, writequeue_has_space); @@ -199,7 +191,7 @@ void session_loop(void(*loophandler)()) { val = select(ses.maxfd+1, &readfd, &writefd, NULL, &timeout); - if (exitflag) { + if (ses.exitflag) { dropbear_exit("Terminated by signal"); } @@ -219,6 +211,7 @@ void session_loop(void(*loophandler)()) { /* We'll just empty out the pipe if required. We don't do any thing with the data, since the pipe's purpose is purely to wake up the select() above. */ + ses.channel_signal_pending = 0; if (FD_ISSET(ses.signal_pipe[0], &readfd)) { char x; TRACE(("signal pipe set")) @@ -253,6 +246,10 @@ void session_loop(void(*loophandler)()) { handle_connect_fds(&writefd); + /* loop handler prior to channelio, in case the server loophandler closes + channels on process exit */ + loophandler(); + /* process pipes etc for the channels, ses.dataallowed == 0 * during rekeying ) */ channelio(&readfd, &writefd); @@ -264,11 +261,6 @@ void session_loop(void(*loophandler)()) { } } - - if (loophandler) { - loophandler(); - } - } /* for(;;) */ /* Not reached */ @@ -289,8 +281,8 @@ void session_cleanup() { TRACE(("enter session_cleanup")) /* we can't cleanup if we don't know the session state */ - if (!sessinitdone) { - TRACE(("leave session_cleanup: !sessinitdone")) + if (!ses.init_done) { + TRACE(("leave session_cleanup: !ses.init_done")) return; } |