1
0
mirror of https://git.tartarus.org/simon/putty.git synced 2025-01-09 17:38:00 +00:00

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.
This commit is contained in:
Simon Tatham 2018-10-07 21:22:05 +01:00
parent cea1329b9e
commit 2ea356c46c

10
ssh.c
View File

@ -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;