{"thread":{"id":"22398","subject":"[PATCH 1/2] Support addresses with ':' in git-daemon","startedAt":"2010-01-26T18:24:40Z","lastAt":"2010-01-26T22:53:28Z","messageCount":5,"participants":["Ilari Liusvaara","Junio C Hamano","Tay Ray Chuan"],"isPatch":true,"patchVersion":1,"patchTotal":2},"messages":[{"id":"132707","messageId":"1264530282-4783-1-git-send-email-ilari.liusvaara@elisanet.fi","threadId":"22398","inReplyTo":null,"subject":"[PATCH 0/2] Allow using ':' in git:// hostname.","fromName":"Ilari Liusvaara","fromEmail":"ilari.liusvaara@elisanet.fi","sentAt":"2010-01-26T18:24:40Z","receivedAt":"2010-01-26T18:24:40Z","isPatch":true,"sender":{"key":"ilari.liusvaara@elisanet.fi","avatar":null},"body":"This series fixes two problems with using addresses containing ':'\n(e.g. IPv6 numeric addresses) with git://:\n\n1) ':' in hostname makes vhost headers impossible to parse\n\nIf there is ':' in address, the vhost headers become impossible\nto parse because ':' is also splits host and port and port is\noptional. Change git-daemon to be able to perform address unwrapping\nso there is uniquely parseable syntax for hostnames containg\n':' (this is compatible to how git-remote-gits encodes such vhost\nheaders and how git-daemon2[1] decodes them).\n\n2) Client double-unwraps addresses\n\nWith git://, the addresses are unwrapped twice, which breaks\naddress parsing for addresses enclosed by [], which in turn is\nrequired for hostnames containing ':'.  This is changed to unwarp\nthe addresses only once. This also changes wrapped addresses to\nbe sent as wrapped for vhost headers (the first patch adds ability\nto parse this).\n\n[1] The reference implementation of gits:// server daemon.\n\nIlari Liusvaara (2):\n  Support addresses with ':' in git-daemon\n  Allow use of []-wrapped addresses in git://\n\n connect.c |   10 ++++++++--\n daemon.c  |   34 ++++++++++++++++++++++++++++++----\n 2 files changed, 38 insertions(+), 6 deletions(-)\n"},{"id":"132704","messageId":"1264530282-4783-2-git-send-email-ilari.liusvaara@elisanet.fi","threadId":"22398","inReplyTo":"1264530282-4783-1-git-send-email-ilari.liusvaara@elisanet.fi","subject":"[PATCH 1/2] Support addresses with ':' in git-daemon","fromName":"Ilari Liusvaara","fromEmail":"ilari.liusvaara@elisanet.fi","sentAt":"2010-01-26T18:24:41Z","receivedAt":"2010-01-26T18:24:41Z","isPatch":true,"sender":{"key":"ilari.liusvaara@elisanet.fi","avatar":null},"body":"If host address could have ':' in it (e.g. numeric IPv6 address), then\nhost and port could not be uniquely parsed. Fix this by parsing the\n\"[\"<host>\"]\":<port> and \"[\"<host>\"]\" notations. Currently the built-in\ngit:// client would send <host>:<port> or <host> for such thing, but\nit doesn't matter as due to bugs, resolving address fails if <host>\ncontains ':'.\n\nSigned-off-by: Ilari Liusvaara <ilari.liusvaara@elisanet.fi>\n---\n daemon.c |   34 ++++++++++++++++++++++++++++++----\n 1 files changed, 30 insertions(+), 4 deletions(-)\n\ndiff --git a/daemon.c b/daemon.c\nindex 360635e..6c2bd97 100644\n--- a/daemon.c\n+++ b/daemon.c\n@@ -399,6 +399,33 @@ static char *xstrdup_tolower(const char *str)\n \treturn dup;\n }\n \n+static void parse_host_and_port(char *hostport, char **host,\n+\tchar **port)\n+{\n+\tif (*hostport == '[') {\n+\t\tchar *end;\n+\n+\t\tend = strchr(hostport, ']');\n+\t\tif (!end)\n+\t\t\tdie(\"Invalid reqeuest ('[' without ']')\");\n+\t\t*end = '\\0';\n+\t\t*host = hostport + 1;\n+\t\tif (!end[1])\n+\t\t\t*port = NULL;\n+\t\telse if (end[1] == ':')\n+\t\t\t*port = end + 2;\n+\t\telse\n+\t\t\tdie(\"Garbage after end of host part\");\n+\t} else {\n+\t\t*host = hostport;\n+\t\t*port = strrchr(hostport, ':');\n+\t\tif (*port) {\n+\t\t\t*port = '\\0';\n+\t\t\t++*port;\n+\t\t}\n+\t}\n+}\n+\n /*\n  * Read the host as supplied by the client connection.\n  */\n@@ -415,11 +442,10 @@ static void parse_host_arg(char *extra_args, int buflen)\n \t\t\tvallen = strlen(val) + 1;\n \t\t\tif (*val) {\n \t\t\t\t/* Split <host>:<port> at colon. */\n-\t\t\t\tchar *host = val;\n-\t\t\t\tchar *port = strrchr(host, ':');\n+\t\t\t\tchar *host;\n+\t\t\t\tchar *port;\n+\t\t\t\tparse_host_and_port(val, &host, &port);\n \t\t\t\tif (port) {\n-\t\t\t\t\t*port = 0;\n-\t\t\t\t\tport++;\n \t\t\t\t\tfree(tcp_port);\n \t\t\t\t\ttcp_port = xstrdup(port);\n \t\t\t\t}\n-- \n1.6.6.1.439.gf06b6\n"},{"id":"132705","messageId":"1264530282-4783-3-git-send-email-ilari.liusvaara@elisanet.fi","threadId":"22398","inReplyTo":"1264530282-4783-1-git-send-email-ilari.liusvaara@elisanet.fi","subject":"[PATCH 2/2] Allow use of []-wrapped addresses in git://","fromName":"Ilari Liusvaara","fromEmail":"ilari.liusvaara@elisanet.fi","sentAt":"2010-01-26T18:24:42Z","receivedAt":"2010-01-26T18:24:42Z","isPatch":true,"sender":{"key":"ilari.liusvaara@elisanet.fi","avatar":null},"body":"Allow using \"[\"<host>\"]\":<port> and \"[\"<host>\"]\" notations in git://\nhost addresses. This is needed to be able to connect to addresses\nthat contain ':' (e.g. numeric IPv6 addresses). Also send the host\nheader []-wrapped so it can actually be parsed by remote end.\n\nSigned-off-by: Ilari Liusvaara <ilari.liusvaara@elisanet.fi>\n---\n connect.c |   10 ++++++++--\n 1 files changed, 8 insertions(+), 2 deletions(-)\n\ndiff --git a/connect.c b/connect.c\nindex 3a12562..20054e4 100644\n--- a/connect.c\n+++ b/connect.c\n@@ -502,12 +502,18 @@ struct child_process *git_connect(int fd[2], const char *url_orig,\n \t\tc = ':';\n \t}\n \n+\t/*\n+\t * Don't do destructive transforms with git:// as that\n+\t * protocol code does '[]' dewrapping of its own.\n+\t */\n \tif (host[0] == '[') {\n \t\tend = strchr(host + 1, ']');\n \t\tif (end) {\n-\t\t\t*end = 0;\n+\t\t\tif (protocol != PROTO_GIT) {\n+\t\t\t\t*end = 0;\n+\t\t\t\thost++;\n+\t\t\t}\n \t\t\tend++;\n-\t\t\thost++;\n \t\t} else\n \t\t\tend = host;\n \t} else\n-- \n1.6.6.1.439.gf06b6\n"},{"id":"132710","messageId":"7vfx5szlgm.fsf@alter.siamese.dyndns.org","threadId":"22398","inReplyTo":"1264530282-4783-1-git-send-email-ilari.liusvaara@elisanet.fi","subject":"Re: [PATCH 0/2] Allow using ':' in git:// hostname.","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2010-01-26T19:59:21Z","receivedAt":"2010-01-26T19:59:21Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Seems like a maint material (together with your xmallocz() one).\nThanks.\n"},{"id":"132721","messageId":"be6fef0d1001261453v2fd624fdv88640aa706c0009@mail.gmail.com","threadId":"22398","inReplyTo":"1264530282-4783-2-git-send-email-ilari.liusvaara@elisanet.fi","subject":"Re: [PATCH 1/2] Support addresses with ':' in git-daemon","fromName":"Tay Ray Chuan","fromEmail":"rctay89@gmail.com","sentAt":"2010-01-26T22:53:28Z","receivedAt":"2010-01-26T22:53:28Z","isPatch":true,"sender":{"key":"rctay89@gmail.com","avatar":"https://avatars.githubusercontent.com/u/61553?v=4"},"body":"Hi,\n\nOn Wed, Jan 27, 2010 at 2:24 AM, Ilari Liusvaara\n<ilari.liusvaara@elisanet.fi> wrote:\n> diff --git a/daemon.c b/daemon.c\n> index 360635e..6c2bd97 100644\n> --- a/daemon.c\n> +++ b/daemon.c\n> @@ -399,6 +399,33 @@ static char *xstrdup_tolower(const char *str)\n>        return dup;\n>  }\n>\n> +static void parse_host_and_port(char *hostport, char **host,\n> +       char **port)\n> +{\n> +       if (*hostport == '[') {\n> +               char *end;\n> +\n> +               end = strchr(hostport, ']');\n> +               if (!end)\n> +                       die(\"Invalid reqeuest ('[' without ']')\");\n\ns/reqeuest/request/.\n\n-- \nCheers,\nRay Chuan\n"}]}