aboutsummaryrefslogtreecommitdiff
path: root/kex.c
diff options
context:
space:
mode:
Diffstat (limited to 'kex.c')
-rw-r--r--kex.c17
1 files changed, 12 insertions, 5 deletions
diff --git a/kex.c b/kex.c
index ce85f043958e..09c7258e05bd 100644
--- a/kex.c
+++ b/kex.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: kex.c,v 1.156 2020/01/23 10:24:29 dtucker Exp $ */
+/* $OpenBSD: kex.c,v 1.158 2020/03/13 04:01:56 djm Exp $ */
/*
* Copyright (c) 2000, 2001 Markus Friedl. All rights reserved.
*
@@ -670,8 +670,7 @@ kex_free_newkeys(struct newkeys *newkeys)
}
free(newkeys->mac.name);
explicit_bzero(&newkeys->mac, sizeof(newkeys->mac));
- explicit_bzero(newkeys, sizeof(*newkeys));
- free(newkeys);
+ freezero(newkeys, sizeof(*newkeys));
}
void
@@ -1168,7 +1167,7 @@ int
kex_exchange_identification(struct ssh *ssh, int timeout_ms,
const char *version_addendum)
{
- int remote_major, remote_minor, mismatch;
+ int remote_major, remote_minor, mismatch, oerrno = 0;
size_t len, i, n;
int r, expect_nl;
u_char c;
@@ -1187,6 +1186,7 @@ kex_exchange_identification(struct ssh *ssh, int timeout_ms,
PROTOCOL_MAJOR_2, PROTOCOL_MINOR_2, SSH_VERSION,
version_addendum == NULL ? "" : " ",
version_addendum == NULL ? "" : version_addendum)) != 0) {
+ oerrno = errno;
error("%s: sshbuf_putf: %s", __func__, ssh_err(r));
goto out;
}
@@ -1194,11 +1194,13 @@ kex_exchange_identification(struct ssh *ssh, int timeout_ms,
if (atomicio(vwrite, ssh_packet_get_connection_out(ssh),
sshbuf_mutable_ptr(our_version),
sshbuf_len(our_version)) != sshbuf_len(our_version)) {
- error("%s: write: %.100s", __func__, strerror(errno));
+ oerrno = errno;
+ debug("%s: write: %.100s", __func__, strerror(errno));
r = SSH_ERR_SYSTEM_ERROR;
goto out;
}
if ((r = sshbuf_consume_end(our_version, 2)) != 0) { /* trim \r\n */
+ oerrno = errno;
error("%s: sshbuf_consume_end: %s", __func__, ssh_err(r));
goto out;
}
@@ -1234,6 +1236,7 @@ kex_exchange_identification(struct ssh *ssh, int timeout_ms,
r = SSH_ERR_CONN_TIMEOUT;
goto out;
} else if (r == -1) {
+ oerrno = errno;
error("%s: %s",
__func__, strerror(errno));
r = SSH_ERR_SYSTEM_ERROR;
@@ -1249,6 +1252,7 @@ kex_exchange_identification(struct ssh *ssh, int timeout_ms,
r = SSH_ERR_CONN_CLOSED;
goto out;
} else if (len != 1) {
+ oerrno = errno;
error("%s: read: %.100s",
__func__, strerror(errno));
r = SSH_ERR_SYSTEM_ERROR;
@@ -1266,6 +1270,7 @@ kex_exchange_identification(struct ssh *ssh, int timeout_ms,
goto invalid;
}
if ((r = sshbuf_put_u8(peer_version, c)) != 0) {
+ oerrno = errno;
error("%s: sshbuf_put: %s",
__func__, ssh_err(r));
goto out;
@@ -1366,6 +1371,8 @@ kex_exchange_identification(struct ssh *ssh, int timeout_ms,
free(our_version_string);
free(peer_version_string);
free(remote_version);
+ if (r == SSH_ERR_SYSTEM_ERROR)
+ errno = oerrno;
return r;
}