merge from main

--HG--
branch : fuzz
This commit is contained in:
Matt Johnston
2018-02-17 19:29:51 +08:00
740 changed files with 99326 additions and 23274 deletions

View File

@@ -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;
}