@matheusbsbs / matheus-bagliano / commits / e8dbd76d57
Fork 0

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 "["<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> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Ilari Liusvaara committed Jan 26, 2010 at 20:24 UTC e8dbd76d57806fd1305612d56d56a4cc7665c599
1 file changed +30 -4
daemon.c
+30 -4
@@ -445,6 +445,33 @@ static char *xstrdup_tolower(const char *str)
445 return dup;
446 }
447
448 +static void parse_host_and_port(char *hostport, char **host,
449 + char **port)
450 +{
451 + if (*hostport == '[') {
452 + char *end;
453 +
454 + end = strchr(hostport, ']');
455 + if (!end)
456 + die("Invalid reqeuest ('[' without ']')");
457 + *end = '\0';
458 + *host = hostport + 1;
459 + if (!end[1])
460 + *port = NULL;
461 + else if (end[1] == ':')
462 + *port = end + 2;
463 + else
464 + die("Garbage after end of host part");
465 + } else {
466 + *host = hostport;
467 + *port = strrchr(hostport, ':');
468 + if (*port) {
469 + *port = '\0';
470 + ++*port;
471 + }
472 + }
473 +}
474 +
475 /*
476 * Read the host as supplied by the client connection.
477 */
@@ -461,11 +488,10 @@ static void parse_host_arg(char *extra_args, int buflen)
488 vallen = strlen(val) + 1;
489 if (*val) {
490 /* Split <host>:<port> at colon. */
464 - char *host = val;
465 - char *port = strrchr(host, ':');
491 + char *host;
492 + char *port;
493 + parse_host_and_port(val, &host, &port);
494 if (port) {
467 - *port = 0;
468 - port++;
495 free(tcp_port);
496 tcp_port = xstrdup(port);
497 }