summaryrefslogtreecommitdiff
path: root/packet.c
diff options
context:
space:
mode:
authorColin Watson <cjwatson@debian.org>2015-08-19 17:00:17 +0100
committerColin Watson <cjwatson@debian.org>2015-08-19 17:40:32 +0100
commit927d0032b865f05679d3cc052bc13cb0e6490283 (patch)
tree69f782deb79182f26069ff41e9539f17e6e44912 /packet.c
parentd35c65e77ab6a6a95fefa2c852827ba08e507f0b (diff)
parent810eecd6b2e03770f21e46b5cb8ce8c7fcd46da8 (diff)
New upstream release (6.9p1).
Diffstat (limited to 'packet.c')
-rw-r--r--packet.c50
1 files changed, 34 insertions, 16 deletions
diff --git a/packet.c b/packet.c
index b1219c85b..a7727ef65 100644
--- a/packet.c
+++ b/packet.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: packet.c,v 1.208 2015/02/13 18:57:00 markus Exp $ */ 1/* $OpenBSD: packet.c,v 1.212 2015/05/01 07:10:01 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
@@ -290,6 +290,7 @@ ssh_packet_set_connection(struct ssh *ssh, int fd_in, int fd_out)
290 (r = cipher_init(&state->receive_context, none, 290 (r = cipher_init(&state->receive_context, none,
291 (const u_char *)"", 0, NULL, 0, CIPHER_DECRYPT)) != 0) { 291 (const u_char *)"", 0, NULL, 0, CIPHER_DECRYPT)) != 0) {
292 error("%s: cipher_init failed: %s", __func__, ssh_err(r)); 292 error("%s: cipher_init failed: %s", __func__, ssh_err(r));
293 free(ssh);
293 return NULL; 294 return NULL;
294 } 295 }
295 state->newkeys[MODE_IN] = state->newkeys[MODE_OUT] = NULL; 296 state->newkeys[MODE_IN] = state->newkeys[MODE_OUT] = NULL;
@@ -791,7 +792,9 @@ ssh_packet_set_compress_hooks(struct ssh *ssh, void *ctx,
791void 792void
792ssh_packet_set_encryption_key(struct ssh *ssh, const u_char *key, u_int keylen, int number) 793ssh_packet_set_encryption_key(struct ssh *ssh, const u_char *key, u_int keylen, int number)
793{ 794{
794#ifdef WITH_SSH1 795#ifndef WITH_SSH1
796 fatal("no SSH protocol 1 support");
797#else /* WITH_SSH1 */
795 struct session_state *state = ssh->state; 798 struct session_state *state = ssh->state;
796 const struct sshcipher *cipher = cipher_by_number(number); 799 const struct sshcipher *cipher = cipher_by_number(number);
797 int r; 800 int r;
@@ -1279,7 +1282,7 @@ ssh_packet_read_seqnr(struct ssh *ssh, u_char *typep, u_int32_t *seqnr_p)
1279 * been sent. 1282 * been sent.
1280 */ 1283 */
1281 if ((r = ssh_packet_write_wait(ssh)) != 0) 1284 if ((r = ssh_packet_write_wait(ssh)) != 0)
1282 return r; 1285 goto out;
1283 1286
1284 /* Stay in the loop until we have received a complete packet. */ 1287 /* Stay in the loop until we have received a complete packet. */
1285 for (;;) { 1288 for (;;) {
@@ -1337,15 +1340,20 @@ ssh_packet_read_seqnr(struct ssh *ssh, u_char *typep, u_int32_t *seqnr_p)
1337 len = roaming_read(state->connection_in, buf, 1340 len = roaming_read(state->connection_in, buf,
1338 sizeof(buf), &cont); 1341 sizeof(buf), &cont);
1339 } while (len == 0 && cont); 1342 } while (len == 0 && cont);
1340 if (len == 0) 1343 if (len == 0) {
1341 return SSH_ERR_CONN_CLOSED; 1344 r = SSH_ERR_CONN_CLOSED;
1342 if (len < 0) 1345 goto out;
1343 return SSH_ERR_SYSTEM_ERROR; 1346 }
1347 if (len < 0) {
1348 r = SSH_ERR_SYSTEM_ERROR;
1349 goto out;
1350 }
1344 1351
1345 /* Append it to the buffer. */ 1352 /* Append it to the buffer. */
1346 if ((r = ssh_packet_process_incoming(ssh, buf, len)) != 0) 1353 if ((r = ssh_packet_process_incoming(ssh, buf, len)) != 0)
1347 return r; 1354 goto out;
1348 } 1355 }
1356 out:
1349 free(setp); 1357 free(setp);
1350 return r; 1358 return r;
1351} 1359}
@@ -1912,9 +1920,19 @@ sshpkt_fatal(struct ssh *ssh, const char *tag, int r)
1912 logit("Connection closed by %.200s", ssh_remote_ipaddr(ssh)); 1920 logit("Connection closed by %.200s", ssh_remote_ipaddr(ssh));
1913 cleanup_exit(255); 1921 cleanup_exit(255);
1914 case SSH_ERR_CONN_TIMEOUT: 1922 case SSH_ERR_CONN_TIMEOUT:
1915 logit("Connection to %.200s timed out while " 1923 logit("Connection to %.200s timed out", ssh_remote_ipaddr(ssh));
1916 "waiting to write", ssh_remote_ipaddr(ssh));
1917 cleanup_exit(255); 1924 cleanup_exit(255);
1925 case SSH_ERR_DISCONNECTED:
1926 logit("Disconnected from %.200s",
1927 ssh_remote_ipaddr(ssh));
1928 cleanup_exit(255);
1929 case SSH_ERR_SYSTEM_ERROR:
1930 if (errno == ECONNRESET) {
1931 logit("Connection reset by %.200s",
1932 ssh_remote_ipaddr(ssh));
1933 cleanup_exit(255);
1934 }
1935 /* FALLTHROUGH */
1918 default: 1936 default:
1919 fatal("%s%sConnection to %.200s: %s", 1937 fatal("%s%sConnection to %.200s: %s",
1920 tag != NULL ? tag : "", tag != NULL ? ": " : "", 1938 tag != NULL ? tag : "", tag != NULL ? ": " : "",
@@ -2727,13 +2745,14 @@ sshpkt_put_stringb(struct ssh *ssh, const struct sshbuf *v)
2727 return sshbuf_put_stringb(ssh->state->outgoing_packet, v); 2745 return sshbuf_put_stringb(ssh->state->outgoing_packet, v);
2728} 2746}
2729 2747
2730#if defined(WITH_OPENSSL) && defined(OPENSSL_HAS_ECC) 2748#ifdef WITH_OPENSSL
2749#ifdef OPENSSL_HAS_ECC
2731int 2750int
2732sshpkt_put_ec(struct ssh *ssh, const EC_POINT *v, const EC_GROUP *g) 2751sshpkt_put_ec(struct ssh *ssh, const EC_POINT *v, const EC_GROUP *g)
2733{ 2752{
2734 return sshbuf_put_ec(ssh->state->outgoing_packet, v, g); 2753 return sshbuf_put_ec(ssh->state->outgoing_packet, v, g);
2735} 2754}
2736#endif /* WITH_OPENSSL && OPENSSL_HAS_ECC */ 2755#endif /* OPENSSL_HAS_ECC */
2737 2756
2738#ifdef WITH_SSH1 2757#ifdef WITH_SSH1
2739int 2758int
@@ -2743,7 +2762,6 @@ sshpkt_put_bignum1(struct ssh *ssh, const BIGNUM *v)
2743} 2762}
2744#endif /* WITH_SSH1 */ 2763#endif /* WITH_SSH1 */
2745 2764
2746#ifdef WITH_OPENSSL
2747int 2765int
2748sshpkt_put_bignum2(struct ssh *ssh, const BIGNUM *v) 2766sshpkt_put_bignum2(struct ssh *ssh, const BIGNUM *v)
2749{ 2767{
@@ -2795,13 +2813,14 @@ sshpkt_get_cstring(struct ssh *ssh, char **valp, size_t *lenp)
2795 return sshbuf_get_cstring(ssh->state->incoming_packet, valp, lenp); 2813 return sshbuf_get_cstring(ssh->state->incoming_packet, valp, lenp);
2796} 2814}
2797 2815
2798#if defined(WITH_OPENSSL) && defined(OPENSSL_HAS_ECC) 2816#ifdef WITH_OPENSSL
2817#ifdef OPENSSL_HAS_ECC
2799int 2818int
2800sshpkt_get_ec(struct ssh *ssh, EC_POINT *v, const EC_GROUP *g) 2819sshpkt_get_ec(struct ssh *ssh, EC_POINT *v, const EC_GROUP *g)
2801{ 2820{
2802 return sshbuf_get_ec(ssh->state->incoming_packet, v, g); 2821 return sshbuf_get_ec(ssh->state->incoming_packet, v, g);
2803} 2822}
2804#endif /* WITH_OPENSSL && OPENSSL_HAS_ECC */ 2823#endif /* OPENSSL_HAS_ECC */
2805 2824
2806#ifdef WITH_SSH1 2825#ifdef WITH_SSH1
2807int 2826int
@@ -2811,7 +2830,6 @@ sshpkt_get_bignum1(struct ssh *ssh, BIGNUM *v)
2811} 2830}
2812#endif /* WITH_SSH1 */ 2831#endif /* WITH_SSH1 */
2813 2832
2814#ifdef WITH_OPENSSL
2815int 2833int
2816sshpkt_get_bignum2(struct ssh *ssh, BIGNUM *v) 2834sshpkt_get_bignum2(struct ssh *ssh, BIGNUM *v)
2817{ 2835{