]> git.ipfire.org Git - thirdparty/cups.git/commitdiff
Fix IPv6 address encoding in the Host: header (Issue #903)
authorMichael R Sweet <msweet@msweet.org>
Fri, 1 Mar 2024 16:55:39 +0000 (11:55 -0500)
committerMichael R Sweet <msweet@msweet.org>
Fri, 1 Mar 2024 16:55:39 +0000 (11:55 -0500)
CHANGES.md
cups/http.c

index 9688cad8f14f79385640d5305ce34f8cab90189e..a5c92fdaafb9bc0d702d4219c04d2d85c532bca5 100644 (file)
@@ -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)
index 198087f2745af53a38f26032f5327c1f562a5140..a73a83b57e3dc8a8ba550af8c700f41a75cba883 100644 (file)
@@ -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;