git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Nguyễn Thái Ngọc Duy" <pclouds@gmail.com>
To: git@vger.kernel.org
Cc: "Jonathan Niedier" <jrnieder@gmail.com>,
	"Morten Stenshorne" <mstensho@opera.com>,
	"Nguyễn Thái Ngọc Duy" <pclouds@gmail.com>
Subject: [PATCH] clone: tighten "local paths with colons" check a bit
Date: Fri, 27 Sep 2013 20:48:13 +0700	[thread overview]
Message-ID: <1380289693-593-1-git-send-email-pclouds@gmail.com> (raw)

commit 6000334 (clone: allow cloning local paths with colons in them -
2013-05-04) is added to make it possible to specify a path that has
colons in it without file://, e.g. ../foo:bar/somewhere. But the check
is a bit loose.

Consider the url '[foo]:bar', the '[]' unwrapping code will turn the
string to 'foo\0:bar'. The effect of this new string is the same as
'foo/:bar' to the expression "path < strchrnul(host, '/')", which
mistakes it as a sign of local paths while it's actually not.

Make sure we only check so when no protocol is specified and the url
is not started with '['.

Noticed-by: Morten Stenshorne <mstensho@opera.com>
Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
---
 I wanted to add a test then realized there were no ssh tests in the
 test suite. So laziness won :p

 connect.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/connect.c b/connect.c
index a0783d4..303f850 100644
--- a/connect.c
+++ b/connect.c
@@ -551,7 +551,7 @@ struct child_process *git_connect(int fd[2], const char *url_orig,
 	path = strchr(end, c);
 	if (path && !has_dos_drive_prefix(end)) {
 		if (c == ':') {
-			if (path < strchrnul(host, '/')) {
+			if (host != url || path < strchrnul(host, '/')) {
 				protocol = PROTO_SSH;
 				*path++ = '\0';
 			} else /* '/' in the host part, assume local path */
-- 
1.8.2.83.gc99314b

             reply	other threads:[~2013-09-27 13:45 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-09-27 13:48 Nguyễn Thái Ngọc Duy [this message]
2013-09-27 18:56 ` [PATCH] clone: tighten "local paths with colons" check a bit Jeff King
2013-09-27 21:56 ` Jonathan Nieder
2013-09-28 13:14   ` Torsten Bögershausen

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=1380289693-593-1-git-send-email-pclouds@gmail.com \
    --to=pclouds@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=jrnieder@gmail.com \
    --cc=mstensho@opera.com \
    /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).