X-Git-Url: http://git.ipfire.org/?a=blobdiff_plain;f=daemon.c;h=d37f36e87022290e4489ebf07db56a3f0e14c8bb;hb=e8dbd76d57806fd1305612d56d56a4cc7665c599;hp=1b5ada6648da66d14dec6c399898916920582852;hpb=35eabd1579726d594e84fc8328a5c87693dd065a;p=thirdparty%2Fgit.git diff --git a/daemon.c b/daemon.c index 1b5ada6648..d37f36e870 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); }