From: Fabian Keil Date: Thu, 11 Sep 2025 12:27:03 +0000 (+0200) Subject: get_destination_from_headers(): Properly handle IPv6 addresses X-Git-Url: http://www.privoxy.org/gitweb/@user-manual@@actions-help-prefix@SET-IMAGE-BLOCKER?a=commitdiff_plain;h=9d366482cf00c8f7fe9a250eae22c183546a003b;p=privoxy.git get_destination_from_headers(): Properly handle IPv6 addresses --- diff --git a/parsers.c b/parsers.c index b08c381d..1b7e2de2 100644 --- a/parsers.c +++ b/parsers.c @@ -4891,7 +4891,7 @@ static jb_err parse_time_header(const char *header, time_t *result) * 2 : http = storage for the result (host, port and hostport). * * Returns : JB_ERR_MEMORY (or terminates) in case of memory problems, - * JB_ERR_PARSE if the host header couldn't be found, + * JB_ERR_PARSE if the host header couldn't be found or parsed, * JB_ERR_OK otherwise. * *********************************************************************/ @@ -4921,7 +4921,35 @@ jb_err get_destination_from_headers(const struct list *headers, struct http_requ http->hostport = p; freez(http->host); http->host = q; - q = strchr(http->host, ':'); + if (*p == '[') + { + /* Numeric IPv6 address delimited by brackets */ + p++; + + q = strchr(p, ']'); + if (q == NULL) + { + /* Missing closing bracket */ + return JB_ERR_PARSE; + } + + *q++ = '\0'; + + if (*q == '\0') + { + q = NULL; + } + else if (*q != ':') + { + /* Garbage after closing bracket */ + return JB_ERR_PARSE; + } + } + else + { + /* Plain non-escaped hostname */ + q = strchr(http->host, ':'); + } if (q != NULL) { /* Terminate hostname and evaluate port string */