From: Michael R Sweet Date: Fri, 1 Mar 2024 16:52:38 +0000 (-0500) Subject: Fix IPv6 address encoding in the Host: header (Issue #903) X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=462e85146773486be3bf82af5e99a89caeb188c3;p=thirdparty%2Fcups.git Fix IPv6 address encoding in the Host: header (Issue #903) --- diff --git a/CHANGES.md b/CHANGES.md index 1d2fb73fa0..59c508ce87 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -19,7 +19,8 @@ Changes in CUPS v2.5b1 (TBA) - Updated CUPS to require ZLIB. - Updated CUPS to require support for `poll` API. - Updated `cupsArray` APIs to support modern naming and types. -- Updated `cups_enum_dests()` timeout for listing available IPP printers (Issue #751) +- Updated `cups_enum_dests()` timeout for listing available IPP printers + (Issue #751) - Updated `httpAddrConnect2()` to handle `POLLHUP` together with `POLLIN` or `POLLOUT` (Issue #839) - Fixed use-after-free in `cupsdAcceptClient()` when we log warning during error @@ -30,7 +31,8 @@ Changes in CUPS v2.5b1 (TBA) (Issue #423) - Fixed extensive looping in scheduler (Issue #604) - Fixed printing multiple files on specific printers (Issue #643) -- Fixed printing of jobs with job name longer than 255 chars on older printers (Issue #644) +- Fixed printing of jobs with job name longer than 255 chars on older printers + (Issue #644) - Fixed segfault in `cupsGetNamedDest()` when trying to get default printer, but the default printer is not set (Issue #719) - Fixed ready media support for iOS 17+ (Issue #738) @@ -44,15 +46,17 @@ Changes in CUPS v2.5b1 (TBA) - Fixed memory leak when creating color profiles (Issue #814) - Fixed crash in `scan_ps()` if incoming argument is NULL (Issue #831) - Fixed setting job state reasons for successful jobs (Issue #832) -- Fixed infinite loop in IPP backend if hostname is IP address with Kerberos (Issue #838) +- Fixed infinite loop in IPP backend if hostname is IP address with Kerberos + (Issue #838) - Fixed crash in `ppdEmitString()` if there is no record for page size `Custom` (Issue #849) -- Fixed reporting `media-source-supported` when sharing printer which has numbers as strings - instead of keywords as `InputSlot` values (Issue #859) +- Fixed reporting `media-source-supported` when sharing printer which has + numbers as strings instead of keywords as `InputSlot` values (Issue #859) - Fixed IPP backend to support the "print-scaling" option with IPP printers (Issue #862) - Fixed Oki 407 freeze when printing larger jobs (Issue #877) - Fixed checking for required attributes during PPD generation (Issue #890) +- Fixed encoding of IPv6 addresses in HTTP requests (Issue #903) - Removed hash support for SHA2-512-224 and SHA2-512-256. - Removed `mantohtml` script for generating html pages (use `https://www.msweet.org/mantohtml/`) diff --git a/cups/http.c b/cups/http.c index c154412b17..744c1dba2e 100644 --- a/cups/http.c +++ b/cups/http.c @@ -3620,7 +3620,31 @@ http_create( http->version = HTTP_VERSION_1_1; if (host) - cupsCopyString(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... + cupsCopyString(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;