From dff3cd562db1a5673a68bec172b566d640cf41f9 Mon Sep 17 00:00:00 2001 From: Simon Tatham Date: Fri, 12 Oct 2018 23:27:53 +0100 Subject: [PATCH] Fix assertion failure if server won't start a shell. In the recent refactoring, when I rewrote the loop in the SSH-2 connection layer startup which tries the primary and then the fallback command, I failed to reproduce a subtlety of the previous code, namely that if CONF_remote_cmd2 holds the empty string, we don't even look for CONF_ssh_subsys2. This is because no application other than pscp will have set the latter, and looking it up when it's absent triggers an assertion failure in conf.c. --- ssh2connection.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/ssh2connection.c b/ssh2connection.c index a5c293ff..c0fe4961 100644 --- a/ssh2connection.c +++ b/ssh2connection.c @@ -1288,13 +1288,19 @@ static void ssh2_connection_process_queue(PacketProtocolLayer *ppl) char *cmd; if (s->session_attempt == 0) { - subsys = conf_get_int(s->conf, CONF_ssh_subsys); cmd = conf_get_str(s->conf, CONF_remote_cmd); + subsys = conf_get_int(s->conf, CONF_ssh_subsys); } else { - subsys = conf_get_int(s->conf, CONF_ssh_subsys2); cmd = conf_get_str(s->conf, CONF_remote_cmd2); - if (!*cmd) + if (!*cmd) { + /* If there's no remote_cmd2 configured, then we + * have no fallback command, and we should quit + * this loop before even trying to look up + * CONF_ssh_subsys2, which is one of the few conf + * keys that is not guaranteed to be populated. */ break; + } + subsys = conf_get_int(s->conf, CONF_ssh_subsys2); ppl_logevent(("Primary command failed; attempting fallback")); }