diff options
author | brian m. carlson <sandals@crustytoothpaste.net> | 2015-04-26 20:30:12 +0000 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2015-04-28 15:23:12 -0700 |
commit | baaf233755f71c057d28b9e8692e24d4fca7d22f (patch) | |
tree | f4dd21df1b7ea6028213cf59cfb9cfb8b27dafc8 /connect.c | |
parent | d1018c2494c05e6a27ec5945902306cfb9e45b0c (diff) | |
download | git-baaf233755f71c057d28b9e8692e24d4fca7d22f.tar.gz |
connect: improve check for plink to reduce false positivesbc/connect-plink
The git_connect function has code to handle plink and tortoiseplink
specially, as they require different command line arguments from
OpenSSH (-P instead of -p for ports; tortoiseplink additionally requires
-batch). However, the match was done by checking for "plink" anywhere
in the string, which led to a GIT_SSH value containing "uplink" being
treated as an invocation of putty's plink.
Improve the check by looking for "plink" or "tortoiseplink" (or those
names suffixed with ".exe") only in the final component of the path.
This has the downside that a program such as "plink-0.63" would no
longer be recognized, but the increased robustness is likely worth it.
Add tests to cover these cases to avoid regressions.
Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net>
Acked-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'connect.c')
-rw-r--r-- | connect.c | 18 |
1 files changed, 15 insertions, 3 deletions
@@ -722,7 +722,7 @@ struct child_process *git_connect(int fd[2], const char *url, conn->in = conn->out = -1; if (protocol == PROTO_SSH) { const char *ssh; - int putty; + int putty, tortoiseplink = 0; char *ssh_host = hostandport; const char *port = NULL; get_host_and_port(&ssh_host, &port); @@ -747,14 +747,26 @@ struct child_process *git_connect(int fd[2], const char *url, conn->use_shell = 1; putty = 0; } else { + const char *base; + char *ssh_dup; + ssh = getenv("GIT_SSH"); if (!ssh) ssh = "ssh"; - putty = !!strcasestr(ssh, "plink"); + + ssh_dup = xstrdup(ssh); + base = basename(ssh_dup); + + tortoiseplink = !strcasecmp(base, "tortoiseplink") || + !strcasecmp(base, "tortoiseplink.exe"); + putty = !strcasecmp(base, "plink") || + !strcasecmp(base, "plink.exe") || tortoiseplink; + + free(ssh_dup); } argv_array_push(&conn->args, ssh); - if (putty && !strcasestr(ssh, "tortoiseplink")) + if (tortoiseplink) argv_array_push(&conn->args, "-batch"); if (port) { /* P is for PuTTY, p is for OpenSSH */ |