summaryrefslogtreecommitdiff
path: root/packet.c
diff options
context:
space:
mode:
authordjm@openbsd.org <djm@openbsd.org>2019-01-19 21:33:13 +0000
committerDamien Miller <djm@mindrot.org>2019-01-20 09:02:20 +1100
commitad60b1179c9682ca5aef0b346f99ef68cbbbc4e5 (patch)
tree0c1df01c9924629b43337bb398e613f1b2f0ba6f /packet.c
parent0fa174ebe129f3d0aeaf4e2d1dd8de745870d0ff (diff)
upstream: 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@ OpenBSD-Commit-ID: de57211f9543426b515a8a10a4f481666b2b2a50
Diffstat (limited to 'packet.c')
-rw-r--r--packet.c29
1 files changed, 23 insertions, 6 deletions
diff --git a/packet.c b/packet.c
index ded5a3201..aa8be8c94 100644
--- a/packet.c
+++ b/packet.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: packet.c,v 1.279 2019/01/04 03:23:00 djm Exp $ */ 1/* $OpenBSD: packet.c,v 1.280 2019/01/19 21:33:14 djm Exp $ */
2/* 2/*
3 * Author: Tatu Ylonen <ylo@cs.hut.fi> 3 * Author: Tatu Ylonen <ylo@cs.hut.fi>
4 * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland 4 * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
@@ -1809,10 +1809,10 @@ sshpkt_fmt_connection_id(struct ssh *ssh, char *s, size_t l)
1809/* 1809/*
1810 * Pretty-print connection-terminating errors and exit. 1810 * Pretty-print connection-terminating errors and exit.
1811 */ 1811 */
1812void 1812static void
1813sshpkt_fatal(struct ssh *ssh, const char *tag, int r) 1813sshpkt_vfatal(struct ssh *ssh, int r, const char *fmt, va_list ap)
1814{ 1814{
1815 char remote_id[512]; 1815 char *tag = NULL, remote_id[512];
1816 1816
1817 sshpkt_fmt_connection_id(ssh, remote_id, sizeof(remote_id)); 1817 sshpkt_fmt_connection_id(ssh, remote_id, sizeof(remote_id));
1818 1818
@@ -1846,6 +1846,11 @@ sshpkt_fatal(struct ssh *ssh, const char *tag, int r)
1846 } 1846 }
1847 /* FALLTHROUGH */ 1847 /* FALLTHROUGH */
1848 default: 1848 default:
1849 if (vasprintf(&tag, fmt, ap) == -1) {
1850 ssh_packet_clear_keys(ssh);
1851 logdie("%s: could not allocate failure message",
1852 __func__);
1853 }
1849 ssh_packet_clear_keys(ssh); 1854 ssh_packet_clear_keys(ssh);
1850 logdie("%s%sConnection %s %s: %s", 1855 logdie("%s%sConnection %s %s: %s",
1851 tag != NULL ? tag : "", tag != NULL ? ": " : "", 1856 tag != NULL ? tag : "", tag != NULL ? ": " : "",
@@ -1854,6 +1859,18 @@ sshpkt_fatal(struct ssh *ssh, const char *tag, int r)
1854 } 1859 }
1855} 1860}
1856 1861
1862void
1863sshpkt_fatal(struct ssh *ssh, int r, const char *fmt, ...)
1864{
1865 va_list ap;
1866
1867 va_start(ap, fmt);
1868 sshpkt_vfatal(ssh, r, fmt, ap);
1869 /* NOTREACHED */
1870 va_end(ap);
1871 logdie("%s: should have exited", __func__);
1872}
1873
1857/* 1874/*
1858 * Logs the error plus constructs and sends a disconnect packet, closes the 1875 * Logs the error plus constructs and sends a disconnect packet, closes the
1859 * connection, and exits. This function never returns. The error message 1876 * connection, and exits. This function never returns. The error message
@@ -1889,10 +1906,10 @@ ssh_packet_disconnect(struct ssh *ssh, const char *fmt,...)
1889 * for it to get sent. 1906 * for it to get sent.
1890 */ 1907 */
1891 if ((r = sshpkt_disconnect(ssh, "%s", buf)) != 0) 1908 if ((r = sshpkt_disconnect(ssh, "%s", buf)) != 0)
1892 sshpkt_fatal(ssh, __func__, r); 1909 sshpkt_fatal(ssh, r, "%s", __func__);
1893 1910
1894 if ((r = ssh_packet_write_wait(ssh)) != 0) 1911 if ((r = ssh_packet_write_wait(ssh)) != 0)
1895 sshpkt_fatal(ssh, __func__, r); 1912 sshpkt_fatal(ssh, r, "%s", __func__);
1896 1913
1897 /* Close the connection. */ 1914 /* Close the connection. */
1898 ssh_packet_close(ssh); 1915 ssh_packet_close(ssh);