X-Git-Url: https://asedeno.scripts.mit.edu/gitweb/?a=blobdiff_plain;f=daemon.c;h=6c2bd977131752e05d3ac545af0d977d6d7ca672;hb=f22cd7fcc54a98277b3d2b82f1bb0b593658925c;hp=918e560b4e1d4b78bd2d3223db61e915c4a3ccbb;hpb=1f73566af5bec28cd8489c6139a9ede95817349c;p=git.git diff --git a/daemon.c b/daemon.c index 918e560b4..6c2bd9771 100644 --- a/daemon.c +++ b/daemon.c @@ -147,7 +147,6 @@ static char *path_ok(char *directory) { "IP", ip_address }, { "P", tcp_port }, { "D", directory }, - { "%", "%" }, { NULL } }; @@ -400,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. */ @@ -416,11 +442,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); }