From e8dbd76d57806fd1305612d56d56a4cc7665c599 Mon Sep 17 00:00:00 2001 From: Ilari Liusvaara Date: Tue, 26 Jan 2010 20:24:41 +0200 Subject: Support addresses with ':' in git-daemon 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 "[""]": and "[""]" notations. Currently the built-in git:// client would send : or for such thing, but it doesn't matter as due to bugs, resolving address fails if contains ':'. Signed-off-by: Ilari Liusvaara Signed-off-by: Junio C Hamano diff --git a/daemon.c b/daemon.c index 1b5ada6..d37f36e 100644 --- a/daemon.c +++ b/daemon.c @@ -445,6 +445,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. */ @@ -461,11 +488,10 @@ static void parse_host_arg(char *extra_args, int buflen) vallen = strlen(val) + 1; if (*val) { /* Split : 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); } -- cgit v0.10.2-6-g49f6 From 9aa5053d9ffc7fade885b58a34175b4907b1a4f8 Mon Sep 17 00:00:00 2001 From: Ilari Liusvaara Date: Tue, 26 Jan 2010 20:24:42 +0200 Subject: Allow use of []-wrapped addresses in git:// Allow using "[""]": and "[""]" notations in git:// host addresses. This is needed to be able to connect to addresses that contain ':' (e.g. numeric IPv6 addresses). Also send the host header []-wrapped so it can actually be parsed by remote end. Signed-off-by: Ilari Liusvaara Signed-off-by: Junio C Hamano diff --git a/connect.c b/connect.c index 7945e38..5145d16 100644 --- a/connect.c +++ b/connect.c @@ -523,12 +523,18 @@ struct child_process *git_connect(int fd[2], const char *url_orig, c = ':'; } + /* + * Don't do destructive transforms with git:// as that + * protocol code does '[]' dewrapping of its own. + */ if (host[0] == '[') { end = strchr(host + 1, ']'); if (end) { - *end = 0; + if (protocol != PROTO_GIT) { + *end = 0; + host++; + } end++; - host++; } else end = host; } else -- cgit v0.10.2-6-g49f6