Re: [PATCH v2 2/2] connect: improve check for plink to reduce false positives
- From
- Pete Harlan <pchpublic88@gmail.com>
- Date
- Apr 24, 2015, 22:46 UTC
- Message-ID
- <CAM=ud8zKE-Huq_ZGVq9ycFFw+R7TBkQ5R4tcwfha9OBm_geASg@mail.gmail.com>
- In-Reply-To
- <1429914505-325708-2-git-send-email-sandals@crustytoothpaste.net>
On Fri, Apr 24, 2015 at 3:28 PM, brian m. carlson <sandals@crustytoothpaste.net> wrote:
> The git_connect function has code to handle plink and tortoiseplink > specially, as they require different command line arguments from > OpenSSH. However, the match was done by checking for "plink" > case-insensitively in the string, which led to false positives when
Perhaps s/case-insensitively/anywhere/?
It's not important that it ignored case (your change ignores it too), it's that it was too lenient about its context.
--Pete
Show 51 quoted lines
> GIT_SSH contained "uplink". Improve the check by looking for "plink" or
> "tortoiseplink" (or those names suffixed with ".exe") in the final
> component of the path.
>
> Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net>
> ---
> connect.c | 18 +++++++++++++++---
> 1 file changed, 15 insertions(+), 3 deletions(-)
>
> diff --git a/connect.c b/connect.c
> index 749a07b..c0144d8 100644
> --- a/connect.c
> +++ b/connect.c
> @@ -724,7 +724,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);
> @@ -750,14 +750,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 */