]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
Fix X509 server certificate domain matching
authorAmos Jeffries <amosjeffries@squid-cache.org>
Fri, 1 May 2015 07:21:50 +0000 (00:21 -0700)
committerAmos Jeffries <squid3@treenet.co.nz>
Fri, 1 May 2015 07:21:50 +0000 (00:21 -0700)
The X509 certificate domain fields may contain non-ASCII encodings.
Ensure the domain match algorithm is only passed UTF-8 ASCII-compatible
strings.

src/ssl/support.cc

index dd06f5716bcbe7f835b835be1c4fa2187a14fa23..e7ade91318207bc3292d43f15b4ef3a1a619eb8d 100644 (file)
@@ -208,7 +208,13 @@ static int check_domain( void *check_data, ASN1_STRING *cn_data)
     if (cn_data->length > (int)sizeof(cn) - 1) {
         return 1; //if does not fit our buffer just ignore
     }
-    memcpy(cn, cn_data->data, cn_data->length);
+    char *s = reinterpret_cast<char*>(cn_data->data);
+    char *d = cn;
+    for (int i = 0; i < cn_data->length; ++i, ++d, ++s) {
+        if (*s == '\0')
+            return 1; // always a domain mismatch. contains 0x00
+        *d = *s;
+    }
     cn[cn_data->length] = '\0';
     debugs(83, 4, "Verifying server domain " << server << " to certificate name/subjectAltName " << cn);
     return matchDomainName(server, cn[0] == '*' ? cn + 1 : cn);