diff options
author | Matt Johnston <matt@ucc.asn.au> | 2020-10-18 22:53:44 +0800 |
---|---|---|
committer | Matt Johnston <matt@ucc.asn.au> | 2020-10-18 22:53:44 +0800 |
commit | 6ca24af24afe3a3572e9d043df3f8342d38c84b1 (patch) | |
tree | b06b58a6f94bd2827d023f0de10e7f3843a6e28c /cli-session.c | |
parent | 17873e8c922eded2cec86184673a6d110df6403f (diff) | |
parent | 400c7c161f8fd4859f557339f77025044ec950e0 (diff) |
Merge fuzz branch
Diffstat (limited to 'cli-session.c')
-rw-r--r-- | cli-session.c | 65 |
1 files changed, 65 insertions, 0 deletions
diff --git a/cli-session.c b/cli-session.c index f42ea90..5e5af22 100644 --- a/cli-session.c +++ b/cli-session.c @@ -352,6 +352,11 @@ static void cli_session_cleanup(void) { (void)fcntl(cli_ses.stdoutcopy, F_SETFL, cli_ses.stdoutflags); (void)fcntl(cli_ses.stderrcopy, F_SETFL, cli_ses.stderrflags); + /* Don't leak */ + m_close(cli_ses.stdincopy); + m_close(cli_ses.stdoutcopy); + m_close(cli_ses.stderrcopy); + cli_tty_cleanup(); if (cli_ses.server_sig_algs) { buf_free(cli_ses.server_sig_algs); @@ -407,3 +412,63 @@ static void recv_msg_global_request_cli(void) { /* Send a proper rejection */ send_msg_request_failure(); } + +void cli_dropbear_exit(int exitcode, const char* format, va_list param) { + char exitmsg[150]; + char fullmsg[300]; + + /* Note that exit message must be rendered before session cleanup */ + + /* Render the formatted exit message */ + vsnprintf(exitmsg, sizeof(exitmsg), format, param); + TRACE(("Exited, cleaning up: %s", exitmsg)) + + /* Add the prefix depending on session/auth state */ + if (!ses.init_done) { + snprintf(fullmsg, sizeof(fullmsg), "Exited: %s", exitmsg); + } else { + snprintf(fullmsg, sizeof(fullmsg), + "Connection to %s@%s:%s exited: %s", + cli_opts.username, cli_opts.remotehost, + cli_opts.remoteport, exitmsg); + } + + /* Do the cleanup first, since then the terminal will be reset */ + session_cleanup(); + +#if DROPBEAR_FUZZ + if (fuzz.do_jmp) { + longjmp(fuzz.jmp, 1); + } +#endif + + /* Avoid printing onwards from terminal cruft */ + fprintf(stderr, "\n"); + + dropbear_log(LOG_INFO, "%s", fullmsg); + + exit(exitcode); +} + +void cli_dropbear_log(int priority, const char* format, va_list param) { + + char printbuf[1024]; + const char *name; + + name = cli_opts.progname; + if (!name) { + name = "dbclient"; + } + + vsnprintf(printbuf, sizeof(printbuf), format, param); + +#ifndef DISABLE_SYSLOG + if (opts.usingsyslog) { + syslog(priority, "%s", printbuf); + } +#endif + + fprintf(stderr, "%s: %s\n", name, printbuf); + fflush(stderr); +} + |