From 23c745d3350f875ae5f7646ae1d370d8dfd9ca8a Mon Sep 17 00:00:00 2001 From: milo Date: Sun, 8 Aug 2010 22:52:09 +0200 Subject: [PATCH] kex: Fixed initialization of server kex. Signed-off-by: Andreas Schneider --- libssh/kex.c | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/libssh/kex.c b/libssh/kex.c index 4bb7e389..d57273ec 100644 --- a/libssh/kex.c +++ b/libssh/kex.c @@ -260,14 +260,26 @@ SSH_PACKET_CALLBACK(ssh_packet_kexinit){ ssh_set_error(session,SSH_FATAL,"SSH_KEXINIT received in wrong state"); goto error; } - if (buffer_get_data(packet,session->server_kex.cookie,16) != 16) { - ssh_set_error(session, SSH_FATAL, "ssh_packet_kexinit: no cookie in packet"); - goto error; - } + if (server_kex) { + if (buffer_get_data(packet,session->client_kex.cookie,16) != 16) { + ssh_set_error(session, SSH_FATAL, "ssh_packet_kexinit: no cookie in packet"); + goto error; + } - if (hashbufin_add_cookie(session, session->server_kex.cookie) < 0) { - ssh_set_error(session, SSH_FATAL, "ssh_packet_kexinit: adding cookie failed"); - goto error; + if (hashbufin_add_cookie(session, session->client_kex.cookie) < 0) { + ssh_set_error(session, SSH_FATAL, "ssh_packet_kexinit: adding cookie failed"); + goto error; + } + } else { + if (buffer_get_data(packet,session->server_kex.cookie,16) != 16) { + ssh_set_error(session, SSH_FATAL, "ssh_packet_kexinit: no cookie in packet"); + goto error; + } + + if (hashbufin_add_cookie(session, session->server_kex.cookie) < 0) { + ssh_set_error(session, SSH_FATAL, "ssh_packet_kexinit: adding cookie failed"); + goto error; + } } memset(strings, 0, sizeof(char *) * 10);