From: Michael R Sweet Date: Fri, 1 Mar 2024 16:55:39 +0000 (-0500) Subject: Fix IPv6 address encoding in the Host: header (Issue #903) X-Git-Tag: v2.4.8~22 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=9730c99f7580fe37e1e5960905717c6410c6df9b;p=thirdparty%2Fcups.git Fix IPv6 address encoding in the Host: header (Issue #903) --- diff --git a/CHANGES.md b/CHANGES.md index 9688cad8f1..a5c92fdaaf 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -27,6 +27,7 @@ Changes in CUPS v2.4.8 (TBA) - Fixed IPP backend to support the "print-scaling" option with IPP printers (Issue #862) - Fixed checking for required attributes during PPD generation (Issue #890) +- Fixed encoding of IPv6 addresses in HTTP requests (Issue #903) Changes in CUPS v2.4.7 (2023-09-20) diff --git a/cups/http.c b/cups/http.c index 198087f274..a73a83b57e 100644 --- a/cups/http.c +++ b/cups/http.c @@ -4024,7 +4024,31 @@ http_create( http->version = HTTP_VERSION_1_1; if (host) - strlcpy(http->hostname, host, sizeof(http->hostname)); + { + DEBUG_printf(("5http_create: host=\"%s\"", host)); + + if (!strncmp(host, "fe80::", 6)) + { + // IPv6 link local address, convert to IPvFuture format... + char *zoneid; // Pointer to zoneid separator + + snprintf(http->hostname, sizeof(http->hostname), "[v1.%s]", host); + if ((zoneid = strchr(http->hostname, '%')) != NULL) + *zoneid = '+'; + } + else if (isxdigit(host[0]) && isxdigit(host[1]) && isxdigit(host[2]) && isxdigit(host[3]) && host[4] == ':') + { + // IPv6 address, convert to URI format... + snprintf(http->hostname, sizeof(http->hostname), "[%s]", host); + } + else + { + // Not an IPv6 numeric address... + strlcpy(http->hostname, host, sizeof(http->hostname)); + } + + DEBUG_printf(("5http_create: http->hostname=\"%s\"", http->hostname)); + } if (port == 443) /* Always use encryption for https */ http->encryption = HTTP_ENCRYPTION_ALWAYS;