From 123fe0131eacef645c64c60226a64c097abc5906 Mon Sep 17 00:00:00 2001 From: Mathias Fredriksson Date: Wed, 24 Aug 2022 19:12:40 +0300 Subject: [PATCH] fix: Avoid double escaping of ProxyCommand on Windows (#3664) Fixes #2853 --- cli/configssh.go | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/cli/configssh.go b/cli/configssh.go index 40a5f49406..b84a423312 100644 --- a/cli/configssh.go +++ b/cli/configssh.go @@ -280,10 +280,16 @@ func configSSH() *cobra.Command { "\tLogLevel ERROR", ) if !skipProxyCommand { + // In SSH configs, strings inside "" are interpreted literally and there + // is no need to e.g. escape backslashes (common on Windows platforms). + // We will escape the quotes, though. + escapedBinaryFile := strings.ReplaceAll(binaryFile, "\"", "\\\"") if !wireguard { - configOptions = append(configOptions, fmt.Sprintf("\tProxyCommand %q --global-config %q ssh --stdio %s", binaryFile, root, hostname)) + //nolint:gocritic // We don't want to use %q here, see above. + configOptions = append(configOptions, fmt.Sprintf("\tProxyCommand \"%s\" --global-config \"%s\" ssh --stdio %s", escapedBinaryFile, root, hostname)) } else { - configOptions = append(configOptions, fmt.Sprintf("\tProxyCommand %q --global-config %q ssh --wireguard --stdio %s", binaryFile, root, hostname)) + //nolint:gocritic // We don't want to use %q here, see above. + configOptions = append(configOptions, fmt.Sprintf("\tProxyCommand \"%s\" --global-config \"%s\" ssh --wireguard --stdio %s", escapedBinaryFile, root, hostname)) } }