From 2ea356c46c713566b077e659ee4f9a079997142c Mon Sep 17 00:00:00 2001 From: Simon Tatham Date: Sun, 7 Oct 2018 21:22:05 +0100 Subject: [PATCH] Fix crash on early connection of a sharing downstream. If you start up two sharing-enabled PuTTYs to the same host simultaneously, the one that ends up being the downstream can connect to the upstream before the upstream has provided a ConnectionLayer to the sharestate, which means that log_downstream() will dereference cs->parent->cl->frontend to find its Frontend and fail because cl is NULL. Fixed by providing a dummy initial ConnectionLayer containing nothing but a frontend pointer, which is then replaced by the real one later. --- ssh.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/ssh.c b/ssh.c index 433a2572..0119d236 100644 --- a/ssh.c +++ b/ssh.c @@ -91,6 +91,12 @@ struct Ssh { */ ConnectionLayer *cl; + /* + * A dummy ConnectionLayer that can be used for logging sharing + * downstreams that connect before the real one is ready. + */ + ConnectionLayer cl_dummy; + /* * session_started is FALSE until we initialise the main protocol * layers. So it distinguishes between base_layer==NULL meaning @@ -106,6 +112,7 @@ struct Ssh { int need_random_unref; }; + #define ssh_logevent(params) ( \ logevent_and_free((ssh)->frontend, dupprintf params)) @@ -640,6 +647,8 @@ static const char *connect_to_host(Ssh *ssh, const char *host, int port, ssh->s = ssh_connection_sharing_init( ssh->savedhost, ssh->savedport, ssh->conf, ssh->frontend, &ssh->plug, &ssh->connshare); + if (ssh->connshare) + ssh_connshare_provide_connlayer(ssh->connshare, &ssh->cl_dummy); ssh->attempting_connshare = FALSE; if (ssh->s != NULL) { /* @@ -805,6 +814,7 @@ static const char *ssh_init(Frontend *frontend, Backend **backend_handle, *backend_handle = &ssh->backend; ssh->frontend = frontend; + ssh->cl_dummy.frontend = frontend; random_ref(); /* do this now - may be needed by sharing setup code */ ssh->need_random_unref = TRUE;