diff options
Diffstat (limited to 'usr.bin/ssh/clientloop.c')
-rw-r--r-- | usr.bin/ssh/clientloop.c | 49 |
1 files changed, 16 insertions, 33 deletions
diff --git a/usr.bin/ssh/clientloop.c b/usr.bin/ssh/clientloop.c index 79bffbc00b3..b7d4c11f471 100644 --- a/usr.bin/ssh/clientloop.c +++ b/usr.bin/ssh/clientloop.c @@ -1,4 +1,4 @@ -/* $OpenBSD: clientloop.c,v 1.405 2024/04/30 02:14:10 djm Exp $ */ +/* $OpenBSD: clientloop.c,v 1.406 2024/05/09 09:46:47 djm Exp $ */ /* * Author: Tatu Ylonen <ylo@cs.hut.fi> * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland @@ -147,7 +147,6 @@ static time_t control_persist_exit_time = 0; volatile sig_atomic_t quit_pending; /* Set non-zero to quit the loop. */ static int last_was_cr; /* Last character was a newline. */ static int exit_status; /* Used to store the command exit status. */ -static struct sshbuf *stderr_buffer; /* Used for final exit message. */ static int connection_in; /* Connection to server (input). */ static int connection_out; /* Connection to server (output). */ static int need_rekeying; /* Set to non-zero if rekeying is requested. */ @@ -192,17 +191,18 @@ static void quit_message(const char *fmt, ...) static void quit_message(const char *fmt, ...) { - char *msg; + char *msg, *fmt2; va_list args; - int r; + xasprintf(&fmt2, "%s\r\n", fmt); va_start(args, fmt); - xvasprintf(&msg, fmt, args); + xvasprintf(&msg, fmt2, args); va_end(args); - if ((r = sshbuf_putf(stderr_buffer, "%s\r\n", msg)) != 0) - fatal_fr(r, "sshbuf_putf"); + (void)atomicio(vwrite, STDERR_FILENO, msg, strlen(msg)); free(msg); + free(fmt2); + quit_pending = 1; } @@ -1437,7 +1437,7 @@ client_loop(struct ssh *ssh, int have_pty, int escape_char_arg, struct pollfd *pfd = NULL; u_int npfd_alloc = 0, npfd_active = 0; double start_time, total_time; - int channel_did_enqueue = 0, r, len; + int channel_did_enqueue = 0, r; u_int64_t ibytes, obytes; int conn_in_ready, conn_out_ready; sigset_t bsigset, osigset; @@ -1489,10 +1489,6 @@ client_loop(struct ssh *ssh, int have_pty, int escape_char_arg, quit_pending = 0; - /* Initialize buffer. */ - if ((stderr_buffer = sshbuf_new()) == NULL) - fatal_f("sshbuf_new failed"); - client_init_dispatch(ssh); /* @@ -1623,6 +1619,14 @@ client_loop(struct ssh *ssh, int have_pty, int escape_char_arg, /* Terminate the session. */ + /* + * In interactive mode (with pseudo tty) display a message indicating + * that the connection has been closed. + */ + if (have_pty && options.log_level >= SYSLOG_LEVEL_INFO) + quit_message("Connection to %s closed.", host); + + /* Stop watching for window change. */ ssh_signal(SIGWINCH, SIG_DFL); @@ -1655,27 +1659,6 @@ client_loop(struct ssh *ssh, int have_pty, int escape_char_arg, cleanup_exit(255); } - /* - * In interactive mode (with pseudo tty) display a message indicating - * that the connection has been closed. - */ - if (have_pty && options.log_level >= SYSLOG_LEVEL_INFO) - quit_message("Connection to %s closed.", host); - - /* Output any buffered data for stderr. */ - if (sshbuf_len(stderr_buffer) > 0) { - len = atomicio(vwrite, fileno(stderr), - (u_char *)sshbuf_ptr(stderr_buffer), - sshbuf_len(stderr_buffer)); - if (len < 0 || (u_int)len != sshbuf_len(stderr_buffer)) - error("Write failed flushing stderr buffer."); - else if ((r = sshbuf_consume(stderr_buffer, len)) != 0) - fatal_fr(r, "sshbuf_consume"); - } - - /* Clear and free any buffers. */ - sshbuf_free(stderr_buffer); - /* Report bytes transferred, and transfer rates. */ total_time = monotime_double() - start_time; ssh_packet_get_bytes(ssh, &ibytes, &obytes); |