summaryrefslogtreecommitdiff
path: root/kex.c
diff options
context:
space:
mode:
Diffstat (limited to 'kex.c')
-rw-r--r--kex.c14
1 files changed, 11 insertions, 3 deletions
diff --git a/kex.c b/kex.c
index 899036e6e..09c7258e0 100644
--- a/kex.c
+++ b/kex.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: kex.c,v 1.157 2020/02/26 13:40:09 jsg Exp $ */ 1/* $OpenBSD: kex.c,v 1.158 2020/03/13 04:01:56 djm Exp $ */
2/* 2/*
3 * Copyright (c) 2000, 2001 Markus Friedl. All rights reserved. 3 * Copyright (c) 2000, 2001 Markus Friedl. All rights reserved.
4 * 4 *
@@ -1167,7 +1167,7 @@ int
1167kex_exchange_identification(struct ssh *ssh, int timeout_ms, 1167kex_exchange_identification(struct ssh *ssh, int timeout_ms,
1168 const char *version_addendum) 1168 const char *version_addendum)
1169{ 1169{
1170 int remote_major, remote_minor, mismatch; 1170 int remote_major, remote_minor, mismatch, oerrno = 0;
1171 size_t len, i, n; 1171 size_t len, i, n;
1172 int r, expect_nl; 1172 int r, expect_nl;
1173 u_char c; 1173 u_char c;
@@ -1186,6 +1186,7 @@ kex_exchange_identification(struct ssh *ssh, int timeout_ms,
1186 PROTOCOL_MAJOR_2, PROTOCOL_MINOR_2, SSH_VERSION, 1186 PROTOCOL_MAJOR_2, PROTOCOL_MINOR_2, SSH_VERSION,
1187 version_addendum == NULL ? "" : " ", 1187 version_addendum == NULL ? "" : " ",
1188 version_addendum == NULL ? "" : version_addendum)) != 0) { 1188 version_addendum == NULL ? "" : version_addendum)) != 0) {
1189 oerrno = errno;
1189 error("%s: sshbuf_putf: %s", __func__, ssh_err(r)); 1190 error("%s: sshbuf_putf: %s", __func__, ssh_err(r));
1190 goto out; 1191 goto out;
1191 } 1192 }
@@ -1193,11 +1194,13 @@ kex_exchange_identification(struct ssh *ssh, int timeout_ms,
1193 if (atomicio(vwrite, ssh_packet_get_connection_out(ssh), 1194 if (atomicio(vwrite, ssh_packet_get_connection_out(ssh),
1194 sshbuf_mutable_ptr(our_version), 1195 sshbuf_mutable_ptr(our_version),
1195 sshbuf_len(our_version)) != sshbuf_len(our_version)) { 1196 sshbuf_len(our_version)) != sshbuf_len(our_version)) {
1196 error("%s: write: %.100s", __func__, strerror(errno)); 1197 oerrno = errno;
1198 debug("%s: write: %.100s", __func__, strerror(errno));
1197 r = SSH_ERR_SYSTEM_ERROR; 1199 r = SSH_ERR_SYSTEM_ERROR;
1198 goto out; 1200 goto out;
1199 } 1201 }
1200 if ((r = sshbuf_consume_end(our_version, 2)) != 0) { /* trim \r\n */ 1202 if ((r = sshbuf_consume_end(our_version, 2)) != 0) { /* trim \r\n */
1203 oerrno = errno;
1201 error("%s: sshbuf_consume_end: %s", __func__, ssh_err(r)); 1204 error("%s: sshbuf_consume_end: %s", __func__, ssh_err(r));
1202 goto out; 1205 goto out;
1203 } 1206 }
@@ -1233,6 +1236,7 @@ kex_exchange_identification(struct ssh *ssh, int timeout_ms,
1233 r = SSH_ERR_CONN_TIMEOUT; 1236 r = SSH_ERR_CONN_TIMEOUT;
1234 goto out; 1237 goto out;
1235 } else if (r == -1) { 1238 } else if (r == -1) {
1239 oerrno = errno;
1236 error("%s: %s", 1240 error("%s: %s",
1237 __func__, strerror(errno)); 1241 __func__, strerror(errno));
1238 r = SSH_ERR_SYSTEM_ERROR; 1242 r = SSH_ERR_SYSTEM_ERROR;
@@ -1248,6 +1252,7 @@ kex_exchange_identification(struct ssh *ssh, int timeout_ms,
1248 r = SSH_ERR_CONN_CLOSED; 1252 r = SSH_ERR_CONN_CLOSED;
1249 goto out; 1253 goto out;
1250 } else if (len != 1) { 1254 } else if (len != 1) {
1255 oerrno = errno;
1251 error("%s: read: %.100s", 1256 error("%s: read: %.100s",
1252 __func__, strerror(errno)); 1257 __func__, strerror(errno));
1253 r = SSH_ERR_SYSTEM_ERROR; 1258 r = SSH_ERR_SYSTEM_ERROR;
@@ -1265,6 +1270,7 @@ kex_exchange_identification(struct ssh *ssh, int timeout_ms,
1265 goto invalid; 1270 goto invalid;
1266 } 1271 }
1267 if ((r = sshbuf_put_u8(peer_version, c)) != 0) { 1272 if ((r = sshbuf_put_u8(peer_version, c)) != 0) {
1273 oerrno = errno;
1268 error("%s: sshbuf_put: %s", 1274 error("%s: sshbuf_put: %s",
1269 __func__, ssh_err(r)); 1275 __func__, ssh_err(r));
1270 goto out; 1276 goto out;
@@ -1365,6 +1371,8 @@ kex_exchange_identification(struct ssh *ssh, int timeout_ms,
1365 free(our_version_string); 1371 free(our_version_string);
1366 free(peer_version_string); 1372 free(peer_version_string);
1367 free(remote_version); 1373 free(remote_version);
1374 if (r == SSH_ERR_SYSTEM_ERROR)
1375 errno = oerrno;
1368 return r; 1376 return r;
1369} 1377}
1370 1378