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

[PATCH 1/2] Support addresses with ':' in git-daemon

From
ILIlari Liusvaara <ilari.liusvaara@elisanet.fi>
Date
Jan 26, 2010, 18:24 UTC
Message-ID
<1264530282-4783-2-git-send-email-ilari.liusvaara@elisanet.fi>
In-Reply-To
<1264530282-4783-1-git-send-email-ilari.liusvaara@elisanet.fi>

If host address could have ':' in it (e.g. numeric IPv6 address), then host and port could not be uniquely parsed. Fix this by parsing the "["<host>"]":<port> and "["<host>"]" notations. Currently the built-in git:// client would send <host>:<port> or <host> for such thing, but it doesn't matter as due to bugs, resolving address fails if <host> contains ':'.

Signed-off-by: Ilari Liusvaara <ilari.liusvaara@elisanet.fi>
---
 daemon.c |   34 ++++++++++++++++++++++++++++++----
 1 files changed, 30 insertions(+), 4 deletions(-)
diff --git a/daemon.c b/daemon.c
index 360635e..6c2bd97 100644
--- a/daemon.c
+++ b/daemon.c
@@ -399,6 +399,33 @@ static char *xstrdup_tolower(const char *str)
 	return dup;
 }
 
+static void parse_host_and_port(char *hostport, char **host,
+	char **port)
+{
+	if (*hostport == '[') {
+		char *end;
+
+		end = strchr(hostport, ']');
+		if (!end)
+			die("Invalid reqeuest ('[' without ']')");
+		*end = '\0';
+		*host = hostport + 1;
+		if (!end[1])
+			*port = NULL;
+		else if (end[1] == ':')
+			*port = end + 2;
+		else
+			die("Garbage after end of host part");
+	} else {
+		*host = hostport;
+		*port = strrchr(hostport, ':');
+		if (*port) {
+			*port = '\0';
+			++*port;
+		}
+	}
+}
+
 /*
  * Read the host as supplied by the client connection.
  */
@@ -415,11 +442,10 @@ static void parse_host_arg(char *extra_args, int buflen)
 			vallen = strlen(val) + 1;
 			if (*val) {
 				/* Split <host>:<port> at colon. */
-				char *host = val;
-				char *port = strrchr(host, ':');
+				char *host;
+				char *port;
+				parse_host_and_port(val, &host, &port);
 				if (port) {
-					*port = 0;
-					port++;
 					free(tcp_port);
 					tcp_port = xstrdup(port);
 				}
-- 
1.6.6.1.439.gf06b6
Previous: Ilari LiusvaaraNext: Tay Ray Chuan
Message 2 of 5 in “Allow using ':' in git:// hostname.”
  1. 0/2 Allow using ':' in git:// hostname.Ilari Liusvaara, Jan 26, 2010
  2. 1/2 Support addresses with ':' in git-daemonIlari Liusvaara, Jan 26, 2010
  3. Tay Ray ChuanJan 26, 2010
  4. 2/2 Allow use of []-wrapped addresses in git://Ilari Liusvaara, Jan 26, 2010
  5. Junio C HamanoJan 26, 2010

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.