Skip to content

Commit

Permalink
upstream: simplify exit message handling, which was more complicated
Browse files Browse the repository at this point in the history
than it needed to be because of unexpunged ssh1 remnants. ok markus@

OpenBSD-Commit-ID: 8b0cd2c0dee75fb053718f442aa89510b684610b
  • Loading branch information
djmdjm committed May 10, 2024
1 parent cbbbf76 commit 1c0d813
Showing 1 changed file with 16 additions and 33 deletions.
49 changes: 16 additions & 33 deletions clientloop.c
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -156,7 +156,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. */
Expand Down Expand Up @@ -201,17 +200,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;
}

Expand Down Expand Up @@ -1446,7 +1446,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;
Expand Down Expand Up @@ -1498,10 +1498,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);

/*
Expand Down Expand Up @@ -1632,6 +1628,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);

Expand Down Expand Up @@ -1664,27 +1668,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);
Expand Down

0 comments on commit 1c0d813

Please sign in to comment.