diff options
-rw-r--r-- | dispatch.c | 6 | ||||
-rw-r--r-- | opacket.c | 14 | ||||
-rw-r--r-- | packet.c | 29 | ||||
-rw-r--r-- | packet.h | 5 |
4 files changed, 36 insertions, 18 deletions
diff --git a/dispatch.c b/dispatch.c index 0b3ea614e..6e4c501e0 100644 --- a/dispatch.c +++ b/dispatch.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: dispatch.c,v 1.31 2017/05/31 07:00:13 markus Exp $ */ | 1 | /* $OpenBSD: dispatch.c,v 1.32 2019/01/19 21:33:13 djm Exp $ */ |
2 | /* | 2 | /* |
3 | * Copyright (c) 2000 Markus Friedl. All rights reserved. | 3 | * Copyright (c) 2000 Markus Friedl. All rights reserved. |
4 | * | 4 | * |
@@ -47,7 +47,7 @@ dispatch_protocol_error(int type, u_int32_t seq, struct ssh *ssh) | |||
47 | (r = sshpkt_put_u32(ssh, seq)) != 0 || | 47 | (r = sshpkt_put_u32(ssh, seq)) != 0 || |
48 | (r = sshpkt_send(ssh)) != 0 || | 48 | (r = sshpkt_send(ssh)) != 0 || |
49 | (r = ssh_packet_write_wait(ssh)) != 0) | 49 | (r = ssh_packet_write_wait(ssh)) != 0) |
50 | sshpkt_fatal(ssh, __func__, r); | 50 | sshpkt_fatal(ssh, r, "%s", __func__); |
51 | return 0; | 51 | return 0; |
52 | } | 52 | } |
53 | 53 | ||
@@ -131,5 +131,5 @@ ssh_dispatch_run_fatal(struct ssh *ssh, int mode, volatile sig_atomic_t *done) | |||
131 | int r; | 131 | int r; |
132 | 132 | ||
133 | if ((r = ssh_dispatch_run(ssh, mode, done)) != 0) | 133 | if ((r = ssh_dispatch_run(ssh, mode, done)) != 0) |
134 | sshpkt_fatal(ssh, __func__, r); | 134 | sshpkt_fatal(ssh, r, "%s", __func__); |
135 | } | 135 | } |
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: opacket.c,v 1.7 2017/10/20 01:56:39 djm Exp $ */ | 1 | /* $OpenBSD: opacket.c,v 1.9 2019/01/19 21:33:14 djm Exp $ */ |
2 | /* Written by Markus Friedl. Placed in the public domain. */ | 2 | /* Written by Markus Friedl. Placed in the public domain. */ |
3 | 3 | ||
4 | #include "includes.h" | 4 | #include "includes.h" |
@@ -238,7 +238,7 @@ packet_read_seqnr(u_int32_t *seqnr) | |||
238 | int r; | 238 | int r; |
239 | 239 | ||
240 | if ((r = ssh_packet_read_seqnr(active_state, &type, seqnr)) != 0) | 240 | if ((r = ssh_packet_read_seqnr(active_state, &type, seqnr)) != 0) |
241 | sshpkt_fatal(active_state, __func__, r); | 241 | sshpkt_fatal(active_state, r, "%s", __func__); |
242 | return type; | 242 | return type; |
243 | } | 243 | } |
244 | 244 | ||
@@ -249,7 +249,7 @@ packet_read_poll_seqnr(u_int32_t *seqnr) | |||
249 | int r; | 249 | int r; |
250 | 250 | ||
251 | if ((r = ssh_packet_read_poll_seqnr(active_state, &type, seqnr))) | 251 | if ((r = ssh_packet_read_poll_seqnr(active_state, &type, seqnr))) |
252 | sshpkt_fatal(active_state, __func__, r); | 252 | sshpkt_fatal(active_state, r, "%s", __func__); |
253 | return type; | 253 | return type; |
254 | } | 254 | } |
255 | 255 | ||
@@ -266,7 +266,7 @@ packet_process_incoming(const char *buf, u_int len) | |||
266 | int r; | 266 | int r; |
267 | 267 | ||
268 | if ((r = ssh_packet_process_incoming(active_state, buf, len)) != 0) | 268 | if ((r = ssh_packet_process_incoming(active_state, buf, len)) != 0) |
269 | sshpkt_fatal(active_state, __func__, r); | 269 | sshpkt_fatal(active_state, r, "%s", __func__); |
270 | } | 270 | } |
271 | 271 | ||
272 | void | 272 | void |
@@ -275,7 +275,7 @@ packet_write_wait(void) | |||
275 | int r; | 275 | int r; |
276 | 276 | ||
277 | if ((r = ssh_packet_write_wait(active_state)) != 0) | 277 | if ((r = ssh_packet_write_wait(active_state)) != 0) |
278 | sshpkt_fatal(active_state, __func__, r); | 278 | sshpkt_fatal(active_state, r, "%s", __func__); |
279 | } | 279 | } |
280 | 280 | ||
281 | void | 281 | void |
@@ -284,7 +284,7 @@ packet_write_poll(void) | |||
284 | int r; | 284 | int r; |
285 | 285 | ||
286 | if ((r = ssh_packet_write_poll(active_state)) != 0) | 286 | if ((r = ssh_packet_write_poll(active_state)) != 0) |
287 | sshpkt_fatal(active_state, __func__, r); | 287 | sshpkt_fatal(active_state, r, "%s", __func__); |
288 | } | 288 | } |
289 | 289 | ||
290 | void | 290 | void |
@@ -293,7 +293,7 @@ packet_read_expect(int expected_type) | |||
293 | int r; | 293 | int r; |
294 | 294 | ||
295 | if ((r = ssh_packet_read_expect(active_state, expected_type)) != 0) | 295 | if ((r = ssh_packet_read_expect(active_state, expected_type)) != 0) |
296 | sshpkt_fatal(active_state, __func__, r); | 296 | sshpkt_fatal(active_state, r, "%s", __func__); |
297 | } | 297 | } |
298 | 298 | ||
299 | void | 299 | void |
@@ -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 | */ |
1812 | void | 1812 | static void |
1813 | sshpkt_fatal(struct ssh *ssh, const char *tag, int r) | 1813 | sshpkt_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 | ||
1862 | void | ||
1863 | sshpkt_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); |
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: packet.h,v 1.87 2019/01/19 21:31:32 djm Exp $ */ | 1 | /* $OpenBSD: packet.h,v 1.88 2019/01/19 21:33:14 djm Exp $ */ |
2 | 2 | ||
3 | /* | 3 | /* |
4 | * Author: Tatu Ylonen <ylo@cs.hut.fi> | 4 | * Author: Tatu Ylonen <ylo@cs.hut.fi> |
@@ -176,7 +176,8 @@ int sshpkt_send(struct ssh *ssh); | |||
176 | int sshpkt_disconnect(struct ssh *, const char *fmt, ...) | 176 | int sshpkt_disconnect(struct ssh *, const char *fmt, ...) |
177 | __attribute__((format(printf, 2, 3))); | 177 | __attribute__((format(printf, 2, 3))); |
178 | int sshpkt_add_padding(struct ssh *, u_char); | 178 | int sshpkt_add_padding(struct ssh *, u_char); |
179 | void sshpkt_fatal(struct ssh *ssh, const char *tag, int r); | 179 | void sshpkt_fatal(struct ssh *ssh, int r, const char *fmt, ...) |
180 | __attribute__((format(printf, 3, 4))); | ||
180 | int sshpkt_msg_ignore(struct ssh *, u_int); | 181 | int sshpkt_msg_ignore(struct ssh *, u_int); |
181 | 182 | ||
182 | int sshpkt_put(struct ssh *ssh, const void *v, size_t len); | 183 | int sshpkt_put(struct ssh *ssh, const void *v, size_t len); |