Skip to content

Commit 1c0d813

Browse files
committed
upstream: simplify exit message handling, which was more complicated
than it needed to be because of unexpunged ssh1 remnants. ok markus@ OpenBSD-Commit-ID: 8b0cd2c0dee75fb053718f442aa89510b684610b
1 parent cbbbf76 commit 1c0d813

File tree

1 file changed

+16
-33
lines changed

1 file changed

+16
-33
lines changed

clientloop.c

Lines changed: 16 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* $OpenBSD: clientloop.c,v 1.405 2024/04/30 02:14:10 djm Exp $ */
1+
/* $OpenBSD: clientloop.c,v 1.406 2024/05/09 09:46:47 djm Exp $ */
22
/*
33
* Author: Tatu Ylonen <ylo@cs.hut.fi>
44
* Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
@@ -156,7 +156,6 @@ static time_t control_persist_exit_time = 0;
156156
volatile sig_atomic_t quit_pending; /* Set non-zero to quit the loop. */
157157
static int last_was_cr; /* Last character was a newline. */
158158
static int exit_status; /* Used to store the command exit status. */
159-
static struct sshbuf *stderr_buffer; /* Used for final exit message. */
160159
static int connection_in; /* Connection to server (input). */
161160
static int connection_out; /* Connection to server (output). */
162161
static int need_rekeying; /* Set to non-zero if rekeying is requested. */
@@ -201,17 +200,18 @@ static void quit_message(const char *fmt, ...)
201200
static void
202201
quit_message(const char *fmt, ...)
203202
{
204-
char *msg;
203+
char *msg, *fmt2;
205204
va_list args;
206-
int r;
205+
xasprintf(&fmt2, "%s\r\n", fmt);
207206

208207
va_start(args, fmt);
209-
xvasprintf(&msg, fmt, args);
208+
xvasprintf(&msg, fmt2, args);
210209
va_end(args);
211210

212-
if ((r = sshbuf_putf(stderr_buffer, "%s\r\n", msg)) != 0)
213-
fatal_fr(r, "sshbuf_putf");
211+
(void)atomicio(vwrite, STDERR_FILENO, msg, strlen(msg));
214212
free(msg);
213+
free(fmt2);
214+
215215
quit_pending = 1;
216216
}
217217

@@ -1446,7 +1446,7 @@ client_loop(struct ssh *ssh, int have_pty, int escape_char_arg,
14461446
struct pollfd *pfd = NULL;
14471447
u_int npfd_alloc = 0, npfd_active = 0;
14481448
double start_time, total_time;
1449-
int channel_did_enqueue = 0, r, len;
1449+
int channel_did_enqueue = 0, r;
14501450
u_int64_t ibytes, obytes;
14511451
int conn_in_ready, conn_out_ready;
14521452
sigset_t bsigset, osigset;
@@ -1498,10 +1498,6 @@ client_loop(struct ssh *ssh, int have_pty, int escape_char_arg,
14981498

14991499
quit_pending = 0;
15001500

1501-
/* Initialize buffer. */
1502-
if ((stderr_buffer = sshbuf_new()) == NULL)
1503-
fatal_f("sshbuf_new failed");
1504-
15051501
client_init_dispatch(ssh);
15061502

15071503
/*
@@ -1632,6 +1628,14 @@ client_loop(struct ssh *ssh, int have_pty, int escape_char_arg,
16321628

16331629
/* Terminate the session. */
16341630

1631+
/*
1632+
* In interactive mode (with pseudo tty) display a message indicating
1633+
* that the connection has been closed.
1634+
*/
1635+
if (have_pty && options.log_level >= SYSLOG_LEVEL_INFO)
1636+
quit_message("Connection to %s closed.", host);
1637+
1638+
16351639
/* Stop watching for window change. */
16361640
ssh_signal(SIGWINCH, SIG_DFL);
16371641

@@ -1664,27 +1668,6 @@ client_loop(struct ssh *ssh, int have_pty, int escape_char_arg,
16641668
cleanup_exit(255);
16651669
}
16661670

1667-
/*
1668-
* In interactive mode (with pseudo tty) display a message indicating
1669-
* that the connection has been closed.
1670-
*/
1671-
if (have_pty && options.log_level >= SYSLOG_LEVEL_INFO)
1672-
quit_message("Connection to %s closed.", host);
1673-
1674-
/* Output any buffered data for stderr. */
1675-
if (sshbuf_len(stderr_buffer) > 0) {
1676-
len = atomicio(vwrite, fileno(stderr),
1677-
(u_char *)sshbuf_ptr(stderr_buffer),
1678-
sshbuf_len(stderr_buffer));
1679-
if (len < 0 || (u_int)len != sshbuf_len(stderr_buffer))
1680-
error("Write failed flushing stderr buffer.");
1681-
else if ((r = sshbuf_consume(stderr_buffer, len)) != 0)
1682-
fatal_fr(r, "sshbuf_consume");
1683-
}
1684-
1685-
/* Clear and free any buffers. */
1686-
sshbuf_free(stderr_buffer);
1687-
16881671
/* Report bytes transferred, and transfer rates. */
16891672
total_time = monotime_double() - start_time;
16901673
ssh_packet_get_bytes(ssh, &ibytes, &obytes);

0 commit comments

Comments
 (0)