From 8b87d80a8483c82f4e1479e45d26e103ab853154 Mon Sep 17 00:00:00 2001 From: Simon Tatham Date: Thu, 19 Sep 2019 17:34:50 +0100 Subject: [PATCH] Windows Plink: fix segfault at startup when connection-sharing. The message "Reusing a shared connection to this server" is sent to the seat's output method during the call to ssh_init. In Windows Plink, that output method wants to talk to the BinarySink stderr_bs (or stdout_bs, but for this particular message, stderr). So we have to have already set up stderr_bs by the time the backend init function is called. --- windows/winplink.c | 46 +++++++++++++++++++++++----------------------- 1 file changed, 23 insertions(+), 23 deletions(-) diff --git a/windows/winplink.c b/windows/winplink.c index 55aa088c..dce5691f 100644 --- a/windows/winplink.c +++ b/windows/winplink.c @@ -448,29 +448,6 @@ int main(int argc, char **argv) lp_eventlog(default_logpolicy, "Running with restricted process ACL"); } - /* - * Start up the connection. - */ - netevent = CreateEvent(NULL, false, false, NULL); - { - const char *error; - char *realhost; - /* nodelay is only useful if stdin is a character device (console) */ - bool nodelay = conf_get_bool(conf, CONF_tcp_nodelay) && - (GetFileType(GetStdHandle(STD_INPUT_HANDLE)) == FILE_TYPE_CHAR); - - error = backend_init(vt, plink_seat, &backend, logctx, conf, - conf_get_str(conf, CONF_host), - conf_get_int(conf, CONF_port), - &realhost, nodelay, - conf_get_bool(conf, CONF_tcp_keepalives)); - if (error) { - fprintf(stderr, "Unable to open connection:\n%s", error); - return 1; - } - sfree(realhost); - } - inhandle = GetStdHandle(STD_INPUT_HANDLE); outhandle = GetStdHandle(STD_OUTPUT_HANDLE); errhandle = GetStdHandle(STD_ERROR_HANDLE); @@ -522,6 +499,29 @@ int main(int argc, char **argv) stderr_bs = BinarySink_UPCAST(stderr_scc); } + /* + * Start up the connection. + */ + netevent = CreateEvent(NULL, false, false, NULL); + { + const char *error; + char *realhost; + /* nodelay is only useful if stdin is a character device (console) */ + bool nodelay = conf_get_bool(conf, CONF_tcp_nodelay) && + (GetFileType(GetStdHandle(STD_INPUT_HANDLE)) == FILE_TYPE_CHAR); + + error = backend_init(vt, plink_seat, &backend, logctx, conf, + conf_get_str(conf, CONF_host), + conf_get_int(conf, CONF_port), + &realhost, nodelay, + conf_get_bool(conf, CONF_tcp_keepalives)); + if (error) { + fprintf(stderr, "Unable to open connection:\n%s", error); + return 1; + } + sfree(realhost); + } + main_thread_id = GetCurrentThreadId(); sending = false;