diff options
author | Colin Watson <cjwatson@debian.org> | 2020-02-21 11:57:14 +0000 |
---|---|---|
committer | Colin Watson <cjwatson@debian.org> | 2020-02-21 11:57:14 +0000 |
commit | f0de78bd4f29fa688c5df116f3f9cd43543a76d0 (patch) | |
tree | 856b0dee3f2764c13a32dad5ffe2424fab7fef41 /packet.c | |
parent | 4213eec74e74de6310c27a40c3e9759a08a73996 (diff) | |
parent | 8aa3455b16fddea4c0144a7c4a1edb10ec67dcc8 (diff) |
Import openssh_8.2p1.orig.tar.gz
Diffstat (limited to 'packet.c')
-rw-r--r-- | packet.c | 45 |
1 files changed, 42 insertions, 3 deletions
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: packet.c,v 1.286 2019/06/28 13:35:04 deraadt Exp $ */ | 1 | /* $OpenBSD: packet.c,v 1.290 2020/01/30 07:20:05 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 |
@@ -58,7 +58,9 @@ | |||
58 | #include <string.h> | 58 | #include <string.h> |
59 | #include <unistd.h> | 59 | #include <unistd.h> |
60 | #include <limits.h> | 60 | #include <limits.h> |
61 | #ifdef HAVE_POLL_H | ||
61 | #include <poll.h> | 62 | #include <poll.h> |
63 | #endif | ||
62 | #include <signal.h> | 64 | #include <signal.h> |
63 | #include <time.h> | 65 | #include <time.h> |
64 | 66 | ||
@@ -74,7 +76,9 @@ | |||
74 | # endif | 76 | # endif |
75 | #endif | 77 | #endif |
76 | 78 | ||
79 | #ifdef WITH_ZLIB | ||
77 | #include <zlib.h> | 80 | #include <zlib.h> |
81 | #endif | ||
78 | 82 | ||
79 | #include "xmalloc.h" | 83 | #include "xmalloc.h" |
80 | #include "compat.h" | 84 | #include "compat.h" |
@@ -148,9 +152,11 @@ struct session_state { | |||
148 | /* Scratch buffer for packet compression/decompression. */ | 152 | /* Scratch buffer for packet compression/decompression. */ |
149 | struct sshbuf *compression_buffer; | 153 | struct sshbuf *compression_buffer; |
150 | 154 | ||
155 | #ifdef WITH_ZLIB | ||
151 | /* Incoming/outgoing compression dictionaries */ | 156 | /* Incoming/outgoing compression dictionaries */ |
152 | z_stream compression_in_stream; | 157 | z_stream compression_in_stream; |
153 | z_stream compression_out_stream; | 158 | z_stream compression_out_stream; |
159 | #endif | ||
154 | int compression_in_started; | 160 | int compression_in_started; |
155 | int compression_out_started; | 161 | int compression_out_started; |
156 | int compression_in_failures; | 162 | int compression_in_failures; |
@@ -528,9 +534,9 @@ ssh_remote_ipaddr(struct ssh *ssh) | |||
528 | ssh->local_ipaddr = get_local_ipaddr(sock); | 534 | ssh->local_ipaddr = get_local_ipaddr(sock); |
529 | ssh->local_port = get_local_port(sock); | 535 | ssh->local_port = get_local_port(sock); |
530 | } else { | 536 | } else { |
531 | ssh->remote_ipaddr = strdup("UNKNOWN"); | 537 | ssh->remote_ipaddr = xstrdup("UNKNOWN"); |
532 | ssh->remote_port = 65535; | 538 | ssh->remote_port = 65535; |
533 | ssh->local_ipaddr = strdup("UNKNOWN"); | 539 | ssh->local_ipaddr = xstrdup("UNKNOWN"); |
534 | ssh->local_port = 65535; | 540 | ssh->local_port = 65535; |
535 | } | 541 | } |
536 | } | 542 | } |
@@ -607,6 +613,7 @@ ssh_packet_close_internal(struct ssh *ssh, int do_close) | |||
607 | state->newkeys[mode] = NULL; | 613 | state->newkeys[mode] = NULL; |
608 | ssh_clear_newkeys(ssh, mode); /* next keys */ | 614 | ssh_clear_newkeys(ssh, mode); /* next keys */ |
609 | } | 615 | } |
616 | #ifdef WITH_ZLIB | ||
610 | /* compression state is in shared mem, so we can only release it once */ | 617 | /* compression state is in shared mem, so we can only release it once */ |
611 | if (do_close && state->compression_buffer) { | 618 | if (do_close && state->compression_buffer) { |
612 | sshbuf_free(state->compression_buffer); | 619 | sshbuf_free(state->compression_buffer); |
@@ -633,6 +640,7 @@ ssh_packet_close_internal(struct ssh *ssh, int do_close) | |||
633 | inflateEnd(stream); | 640 | inflateEnd(stream); |
634 | } | 641 | } |
635 | } | 642 | } |
643 | #endif /* WITH_ZLIB */ | ||
636 | cipher_free(state->send_context); | 644 | cipher_free(state->send_context); |
637 | cipher_free(state->receive_context); | 645 | cipher_free(state->receive_context); |
638 | state->send_context = state->receive_context = NULL; | 646 | state->send_context = state->receive_context = NULL; |
@@ -688,6 +696,7 @@ ssh_packet_init_compression(struct ssh *ssh) | |||
688 | return 0; | 696 | return 0; |
689 | } | 697 | } |
690 | 698 | ||
699 | #ifdef WITH_ZLIB | ||
691 | static int | 700 | static int |
692 | start_compression_out(struct ssh *ssh, int level) | 701 | start_compression_out(struct ssh *ssh, int level) |
693 | { | 702 | { |
@@ -819,6 +828,33 @@ uncompress_buffer(struct ssh *ssh, struct sshbuf *in, struct sshbuf *out) | |||
819 | /* NOTREACHED */ | 828 | /* NOTREACHED */ |
820 | } | 829 | } |
821 | 830 | ||
831 | #else /* WITH_ZLIB */ | ||
832 | |||
833 | static int | ||
834 | start_compression_out(struct ssh *ssh, int level) | ||
835 | { | ||
836 | return SSH_ERR_INTERNAL_ERROR; | ||
837 | } | ||
838 | |||
839 | static int | ||
840 | start_compression_in(struct ssh *ssh) | ||
841 | { | ||
842 | return SSH_ERR_INTERNAL_ERROR; | ||
843 | } | ||
844 | |||
845 | static int | ||
846 | compress_buffer(struct ssh *ssh, struct sshbuf *in, struct sshbuf *out) | ||
847 | { | ||
848 | return SSH_ERR_INTERNAL_ERROR; | ||
849 | } | ||
850 | |||
851 | static int | ||
852 | uncompress_buffer(struct ssh *ssh, struct sshbuf *in, struct sshbuf *out) | ||
853 | { | ||
854 | return SSH_ERR_INTERNAL_ERROR; | ||
855 | } | ||
856 | #endif /* WITH_ZLIB */ | ||
857 | |||
822 | void | 858 | void |
823 | ssh_clear_newkeys(struct ssh *ssh, int mode) | 859 | ssh_clear_newkeys(struct ssh *ssh, int mode) |
824 | { | 860 | { |
@@ -1814,6 +1850,7 @@ static void | |||
1814 | sshpkt_vfatal(struct ssh *ssh, int r, const char *fmt, va_list ap) | 1850 | sshpkt_vfatal(struct ssh *ssh, int r, const char *fmt, va_list ap) |
1815 | { | 1851 | { |
1816 | char *tag = NULL, remote_id[512]; | 1852 | char *tag = NULL, remote_id[512]; |
1853 | int oerrno = errno; | ||
1817 | 1854 | ||
1818 | sshpkt_fmt_connection_id(ssh, remote_id, sizeof(remote_id)); | 1855 | sshpkt_fmt_connection_id(ssh, remote_id, sizeof(remote_id)); |
1819 | 1856 | ||
@@ -1841,6 +1878,7 @@ sshpkt_vfatal(struct ssh *ssh, int r, const char *fmt, va_list ap) | |||
1841 | case SSH_ERR_NO_HOSTKEY_ALG_MATCH: | 1878 | case SSH_ERR_NO_HOSTKEY_ALG_MATCH: |
1842 | if (ssh && ssh->kex && ssh->kex->failed_choice) { | 1879 | if (ssh && ssh->kex && ssh->kex->failed_choice) { |
1843 | ssh_packet_clear_keys(ssh); | 1880 | ssh_packet_clear_keys(ssh); |
1881 | errno = oerrno; | ||
1844 | logdie("Unable to negotiate with %s: %s. " | 1882 | logdie("Unable to negotiate with %s: %s. " |
1845 | "Their offer: %s", remote_id, ssh_err(r), | 1883 | "Their offer: %s", remote_id, ssh_err(r), |
1846 | ssh->kex->failed_choice); | 1884 | ssh->kex->failed_choice); |
@@ -1853,6 +1891,7 @@ sshpkt_vfatal(struct ssh *ssh, int r, const char *fmt, va_list ap) | |||
1853 | __func__); | 1891 | __func__); |
1854 | } | 1892 | } |
1855 | ssh_packet_clear_keys(ssh); | 1893 | ssh_packet_clear_keys(ssh); |
1894 | errno = oerrno; | ||
1856 | logdie("%s%sConnection %s %s: %s", | 1895 | logdie("%s%sConnection %s %s: %s", |
1857 | tag != NULL ? tag : "", tag != NULL ? ": " : "", | 1896 | tag != NULL ? tag : "", tag != NULL ? ": " : "", |
1858 | ssh->state->server_side ? "from" : "to", | 1897 | ssh->state->server_side ? "from" : "to", |