From 0a15a2c47192e33f4babdd2a9cf7c4648858f987 Mon Sep 17 00:00:00 2001 From: Simon Tatham Date: Fri, 18 May 2018 07:22:57 +0100 Subject: [PATCH] Unconditionally fill the SSH-1 dispatch table. In SSH-2, every possible packet type code has a non-NULL entry in the dispatch table, even if most of them are just ssh2_msg_unimplemented. In SSH-1, some dispatch table entries are NULL, which means that the code processing the dispatch table has to have some SSH-1 specific fallback logic. Now I've put the fallback logic in a separate function, and replaced the NULL table entries with pointers to that function, so that another pointless difference between the SSH-1 and SSH-2 code is removed. --- ssh.c | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/ssh.c b/ssh.c index dfc9a553..a57271f1 100644 --- a/ssh.c +++ b/ssh.c @@ -6268,15 +6268,25 @@ static void ssh_msg_ignore(Ssh ssh, struct Packet *pktin) /* Do nothing, because we're ignoring it! Duhh. */ } +static void ssh1_coro_wrapper(Ssh ssh, struct Packet *pktin) +{ + if (!ssh->protocol_initial_phase_done) { + if (do_ssh1_login(ssh, NULL, 0, pktin)) + ssh->protocol_initial_phase_done = TRUE; + } else { + do_ssh1_connection(ssh, NULL, 0, pktin); + } +} + static void ssh1_protocol_setup(Ssh ssh) { int i; /* - * Most messages are handled by the coroutines. + * Most messages are handled by the main protocol routine. */ for (i = 0; i < 256; i++) - ssh->packet_dispatch[i] = NULL; + ssh->packet_dispatch[i] = ssh1_coro_wrapper; /* * These special message types we install handlers for. @@ -6293,7 +6303,7 @@ static void ssh1_protocol(Ssh ssh, const void *vin, int inlen, if (ssh->state == SSH_STATE_CLOSED) return; - if (pktin && ssh->packet_dispatch[pktin->type]) { + if (pktin) { ssh->packet_dispatch[pktin->type](ssh, pktin); return; }