]> granicus.if.org Git - curl/commitdiff
Curl_http: strip off [brackets] from ipv6-only host headers
authorAndrei Cipu <acipu@ixiacom.com>
Sat, 10 Mar 2012 15:48:59 +0000 (16:48 +0100)
committerDaniel Stenberg <daniel@haxx.se>
Sat, 10 Mar 2012 15:48:59 +0000 (16:48 +0100)
Since the host name is passed in to the cookie engine it will not work
correctly if the brackets are left in the name.

Bug:http://curl.haxx.se/mail/lib-2012-03/0036.html

lib/http.c

index 374de7d21c9e2cffdd9aeecaf930e138a77fd2a7..c7a6df0150a0691dcf01710dc0b32b16820fe9dd 100644 (file)
@@ -1840,9 +1840,19 @@ CURLcode Curl_http(struct connectdata *conn, bool *done)
       /* ignore empty data */
       free(cookiehost);
     else {
-      char *colon = strchr(cookiehost, ':');
-      if(colon)
-        *colon = 0; /* The host must not include an embedded port number */
+      /* If the host begins with '[', we start searching for the port after
+         the bracket has been closed */
+      int startsearch = 0;
+      if(*cookiehost == '[') {
+        char *closingbracket = strchr(++cookiehost, ']');
+        if(closingbracket)
+          *closingbracket = 0;
+      }
+      else {
+        char *colon = strchr(cookiehost + startsearch, ':');
+        if(colon)
+          *colon = 0; /* The host must not include an embedded port number */
+      }
       Curl_safefree(conn->allocptr.cookiehost);
       conn->allocptr.cookiehost = cookiehost;
     }