git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH] clone: tighten "local paths with colons" check a bit

From
Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Date
Sep 27, 2013, 13:48 UTC
Message-ID
<1380289693-593-1-git-send-email-pclouds@gmail.com>

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
Next: Jeff King
Message 1 of 4 in “clone: tighten "local paths with colons" check a bit”
  1. clone: tighten "local paths with colons" check a bitNguyễn Thái Ngọc Duy, Sep 27, 2013
  2. Jeff KingSep 27, 2013
  3. Jonathan NiederSep 27, 2013
  4. Torsten BögershausenSep 28, 2013

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.