summaryrefslogtreecommitdiff
path: root/usr.bin/ssh/packet.c
diff options
context:
space:
mode:
authorDamien Miller <djm@cvs.openbsd.org>2019-01-19 21:33:15 +0000
committerDamien Miller <djm@cvs.openbsd.org>2019-01-19 21:33:15 +0000
commit29769e593f7a4475f9045daa9d73eb20d3881f3f (patch)
treeb7c3f9b78b87d5505a965b54309b137659d3eaa0 /usr.bin/ssh/packet.c
parent42c30280187544ac337177e16690f3e6712fe255 (diff)
allow sshpkt_fatal() to take a varargs format; we'll use this to give
packet-related fatal error messages more context (esp. the remote endpoint) ok markus@
Diffstat (limited to 'usr.bin/ssh/packet.c')
-rw-r--r--usr.bin/ssh/packet.c29
1 files changed, 23 insertions, 6 deletions
diff --git a/usr.bin/ssh/packet.c b/usr.bin/ssh/packet.c
index df31ae6ee8c..245023a23b5 100644
--- a/usr.bin/ssh/packet.c
+++ b/usr.bin/ssh/packet.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: packet.c,v 1.279 2019/01/04 03:23:00 djm Exp $ */
+/* $OpenBSD: packet.c,v 1.280 2019/01/19 21:33:14 djm Exp $ */
/*
* Author: Tatu Ylonen <ylo@cs.hut.fi>
* Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
@@ -1785,10 +1785,10 @@ sshpkt_fmt_connection_id(struct ssh *ssh, char *s, size_t l)
/*
* Pretty-print connection-terminating errors and exit.
*/
-void
-sshpkt_fatal(struct ssh *ssh, const char *tag, int r)
+static void
+sshpkt_vfatal(struct ssh *ssh, int r, const char *fmt, va_list ap)
{
- char remote_id[512];
+ char *tag = NULL, remote_id[512];
sshpkt_fmt_connection_id(ssh, remote_id, sizeof(remote_id));
@@ -1822,6 +1822,11 @@ sshpkt_fatal(struct ssh *ssh, const char *tag, int r)
}
/* FALLTHROUGH */
default:
+ if (vasprintf(&tag, fmt, ap) == -1) {
+ ssh_packet_clear_keys(ssh);
+ logdie("%s: could not allocate failure message",
+ __func__);
+ }
ssh_packet_clear_keys(ssh);
logdie("%s%sConnection %s %s: %s",
tag != NULL ? tag : "", tag != NULL ? ": " : "",
@@ -1830,6 +1835,18 @@ sshpkt_fatal(struct ssh *ssh, const char *tag, int r)
}
}
+void
+sshpkt_fatal(struct ssh *ssh, int r, const char *fmt, ...)
+{
+ va_list ap;
+
+ va_start(ap, fmt);
+ sshpkt_vfatal(ssh, r, fmt, ap);
+ /* NOTREACHED */
+ va_end(ap);
+ logdie("%s: should have exited", __func__);
+}
+
/*
* Logs the error plus constructs and sends a disconnect packet, closes the
* connection, and exits. This function never returns. The error message
@@ -1865,10 +1882,10 @@ ssh_packet_disconnect(struct ssh *ssh, const char *fmt,...)
* for it to get sent.
*/
if ((r = sshpkt_disconnect(ssh, "%s", buf)) != 0)
- sshpkt_fatal(ssh, __func__, r);
+ sshpkt_fatal(ssh, r, "%s", __func__);
if ((r = ssh_packet_write_wait(ssh)) != 0)
- sshpkt_fatal(ssh, __func__, r);
+ sshpkt_fatal(ssh, r, "%s", __func__);
/* Close the connection. */
ssh_packet_close(ssh);