fix_hostname: strip off a single trailing dot from host name
authorDaniel Stenberg <daniel@haxx.se>
Mon, 5 May 2014 11:47:52 +0000 (13:47 +0200)
committerDaniel Stenberg <daniel@haxx.se>
Tue, 6 May 2014 06:44:11 +0000 (08:44 +0200)
Primarily for SNI, we need the host name without a trailing dot.
"https://www.example.com." resolves fine but fails on SNI unless the dot
is removed.

Reported-by: Leon Winter
Bug: http://curl.haxx.se/mail/lib-2014-04/0161.html

lib/url.c

index 5952a9bec3b9402eb9e986eb02c24bc3fa192d40..c9339210c77f78ceac6a2c03c351f9f859dc7f0f 100644 (file)
--- a/lib/url.c
+++ b/lib/url.c
@@ -3502,9 +3502,17 @@ static void fix_hostname(struct SessionHandle *data,
 #elif defined(CURL_DISABLE_VERBOSE_STRINGS)
   (void)conn;
 #endif
+  size_t len;
 
   /* set the name we use to display the host name */
   host->dispname = host->name;
+
+  len = strlen(host->name);
+  if(host->name[len-1] == '.')
+    /* strip off a single trailing dot if present, primarily for SNI but
+       there's no use for it */
+    host->name[len-1]=0;
+
   if(!is_ASCII_name(host->name)) {
 #ifdef USE_LIBIDN
   /*************************************************************