From: Jeff King <peff@peff.net>
To: "brian m. carlson" <sandals@crustytoothpaste.net>,
Patrick Sharp <jakanapes@gmail.com>,
Johannes Schindelin <johannes.schindelin@gmx.de>,
git@vger.kernel.org
Subject: Re: [BUG] having 'plink' anywhere in the GIT_SSH environment variables sets putty = true
Date: Wed, 22 Apr 2015 18:00:54 -0400 [thread overview]
Message-ID: <20150422220053.GA32268@peff.net> (raw)
In-Reply-To: <20150422214445.GC827497@vauxhall.crustytoothpaste.net>
On Wed, Apr 22, 2015 at 09:44:45PM +0000, brian m. carlson wrote:
> On Wed, Apr 22, 2015 at 05:29:04PM -0400, Jeff King wrote:
> > > Perhaps it would be worthwhile to check instead if the text "plink" is
> > > the beginning of string or is preceded by a path separator. That would
> > > give us a bit more confidence that the user is looking for plink, but
> > > would still allow people to use "plink-0.63" if they like.
> >
> > Yeah, I think that is a reasonable approach. Note that it needs to
> > handle the "tortoiseplink" case from below, too (you can still use your
> > strategy, you just need to look for either string).
>
> So maybe something like this?
>
> diff --git a/connect.c b/connect.c
> index 391d211..ba3ab34 100644
> --- a/connect.c
> +++ b/connect.c
> @@ -749,10 +749,15 @@ struct child_process *git_connect(int fd[2], const char *url,
> conn->use_shell = 1;
> putty = 0;
> } else {
> + char *plink, *tplink;
> +
> ssh = getenv("GIT_SSH");
> if (!ssh)
> ssh = "ssh";
> - putty = !!strcasestr(ssh, "plink");
> + plink = strcasestr(ssh, "plink");
> + tplink = strcasestr(ssh, "tortoiseplink");
> + putty = plink == ssh || (plink && is_dir_sep(plink[-1])) ||
> + tplink == ssh || (tplink && is_dir_sep(tplink[-1]));
Yeah, that looks right to me. You might want to represent the "are we
tortoise" check as a separate flag, though, and reuse it a few lines
later.
Also, not related to your patch, but I notice the "putty" declaration is
in a different scope than I would have expected, which made me wonder if
it gets initialized in all code paths. I think is from the recent
addition of CONNECT_DIAG_URL, which pushes the bulk of the code into its
own else clause, even though the first part of the "if" always returns
early. I wonder if it would be simpler to read like:
diff --git a/connect.c b/connect.c
index 391d211..749a07b 100644
--- a/connect.c
+++ b/connect.c
@@ -743,28 +743,28 @@ struct child_process *git_connect(int fd[2], const char *url,
free(path);
free(conn);
return NULL;
- } else {
- ssh = getenv("GIT_SSH_COMMAND");
- if (ssh) {
- conn->use_shell = 1;
- putty = 0;
- } else {
- ssh = getenv("GIT_SSH");
- if (!ssh)
- ssh = "ssh";
- putty = !!strcasestr(ssh, "plink");
- }
-
- argv_array_push(&conn->args, ssh);
- if (putty && !strcasestr(ssh, "tortoiseplink"))
- argv_array_push(&conn->args, "-batch");
- if (port) {
- /* P is for PuTTY, p is for OpenSSH */
- argv_array_push(&conn->args, putty ? "-P" : "-p");
- argv_array_push(&conn->args, port);
- }
- argv_array_push(&conn->args, ssh_host);
}
+
+ ssh = getenv("GIT_SSH_COMMAND");
+ if (ssh) {
+ conn->use_shell = 1;
+ putty = 0;
+ } else {
+ ssh = getenv("GIT_SSH");
+ if (!ssh)
+ ssh = "ssh";
+ putty = !!strcasestr(ssh, "plink");
+ }
+
+ argv_array_push(&conn->args, ssh);
+ if (putty && !strcasestr(ssh, "tortoiseplink"))
+ argv_array_push(&conn->args, "-batch");
+ if (port) {
+ /* P is for PuTTY, p is for OpenSSH */
+ argv_array_push(&conn->args, putty ? "-P" : "-p");
+ argv_array_push(&conn->args, port);
+ }
+ argv_array_push(&conn->args, ssh_host);
} else {
/* remove repo-local variables from the environment */
conn->env = local_repo_env;
-Peff
next prev parent reply other threads:[~2015-04-22 22:01 UTC|newest]
Thread overview: 41+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-04-22 14:36 [BUG] having 'plink' anywhere in the GIT_SSH environment variables sets putty = true Patrick Sharp
2015-04-22 17:46 ` Johannes Schindelin
2015-04-22 19:12 ` Patrick Sharp
2015-04-22 20:29 ` Jeff King
2015-04-22 21:19 ` brian m. carlson
2015-04-22 21:29 ` Jeff King
2015-04-22 21:44 ` brian m. carlson
2015-04-22 22:00 ` Jeff King [this message]
2015-04-22 22:24 ` brian m. carlson
2015-04-22 23:23 ` Jeff King
2015-04-23 0:06 ` [PATCH 1/2] connect: simplify SSH connection code path brian m. carlson
2015-04-23 0:06 ` [PATCH 2/2] connect: improve check for plink to reduce false positives brian m. carlson
2015-04-23 6:50 ` Johannes Schindelin
2015-04-23 15:53 ` Jeff King
2015-04-23 23:14 ` brian m. carlson
2015-04-24 6:41 ` Johannes Schindelin
2015-04-24 22:28 ` [PATCH v2 1/2] connect: simplify SSH connection code path brian m. carlson
2015-04-24 22:28 ` [PATCH v2 2/2] connect: improve check for plink to reduce false positives brian m. carlson
2015-04-24 22:46 ` Pete Harlan
2015-04-24 22:48 ` brian m. carlson
2015-04-25 16:03 ` Torsten Bögershausen
2015-04-26 18:52 ` brian m. carlson
2015-04-26 20:30 ` [PATCH v3 0/3] Improve robustness of putty detection brian m. carlson
2015-04-26 20:30 ` [PATCH v3 1/3] connect: simplify SSH connection code path brian m. carlson
2015-04-26 20:30 ` [PATCH v3 2/3] t5601: fix quotation error leading to skipped tests brian m. carlson
2015-04-26 20:30 ` [PATCH v3 3/3] connect: improve check for plink to reduce false positives brian m. carlson
2015-04-27 7:57 ` Johannes Schindelin
2015-04-28 3:53 ` Jeff King
2015-06-26 13:15 ` Jeff King
2015-06-26 16:16 ` Junio C Hamano
2015-06-26 16:27 ` Jeff King
2015-06-26 17:13 ` Johannes Schindelin
2015-06-26 17:23 ` Jeff King
2015-06-26 20:43 ` brian m. carlson
2015-04-26 22:04 ` [PATCH v3 0/3] Improve robustness of putty detection Junio C Hamano
2015-04-27 15:46 ` Torsten Bögershausen
2015-04-28 4:15 ` Jeff King
2015-04-29 1:38 ` brian m. carlson
2015-04-24 6:37 ` [PATCH 2/2] connect: improve check for plink to reduce false positives Johannes Schindelin
2015-04-23 5:08 ` [BUG] having 'plink' anywhere in the GIT_SSH environment variables sets putty = true Torsten Bögershausen
2015-04-23 13:15 ` Patrick Sharp
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20150422220053.GA32268@peff.net \
--to=peff@peff.net \
--cc=git@vger.kernel.org \
--cc=jakanapes@gmail.com \
--cc=johannes.schindelin@gmx.de \
--cc=sandals@crustytoothpaste.net \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).