From bf62c850510d26e0653335c10aabb427d634ee8f Mon Sep 17 00:00:00 2001 From: Simon Tatham Date: Fri, 18 May 2018 07:22:57 +0100 Subject: [PATCH] Stop using ssh->protocol_initial_phase_done in SSH-1. This flag was used to indicate that ssh1_protocol (or, as of the previous commit, ssh1_coro_wrapper) should stop passing packets to do_ssh1_login and start passing them to do_ssh1_connection. Now, instead of using a flag, we simply have two separate versions of ssh1_coro_wrapper for the two phases, and indicate the change by rewriting all the entries in the dispatch table. So now we _just_ have a function-pointer dereference per packet, rather than one of those and then a flag check. --- ssh.c | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/ssh.c b/ssh.c index 6ca27f61..8bfd53eb 100644 --- a/ssh.c +++ b/ssh.c @@ -973,7 +973,7 @@ struct ssh_tag { struct rdpkt2_state_tag rdpkt2_state; struct rdpkt2_bare_state_tag rdpkt2_bare_state; - /* SSH-1 and SSH-2 use this for different things, but both use it */ + /* Only used by SSH-2 */ int protocol_initial_phase_done; void (*protocol) (Ssh ssh, const void *vin, int inlen); @@ -6268,16 +6268,23 @@ 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) +static void ssh1_coro_wrapper_session(Ssh ssh, struct Packet *pktin); + +static void ssh1_coro_wrapper_initial(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); + if (do_ssh1_login(ssh, NULL, 0, pktin)) { + int i; + for (i = 0; i < 256; i++) + if (ssh->packet_dispatch[i] == ssh1_coro_wrapper_initial) + ssh->packet_dispatch[i] = ssh1_coro_wrapper_session; } } +static void ssh1_coro_wrapper_session(Ssh ssh, struct Packet *pktin) +{ + do_ssh1_connection(ssh, NULL, 0, pktin); +} + static void ssh1_protocol_setup(Ssh ssh) { int i; @@ -6286,7 +6293,7 @@ static void ssh1_protocol_setup(Ssh ssh) * Most messages are handled by the main protocol routine. */ for (i = 0; i < 256; i++) - ssh->packet_dispatch[i] = ssh1_coro_wrapper; + ssh->packet_dispatch[i] = ssh1_coro_wrapper_initial; /* * These special message types we install handlers for.