From: Amos Jeffries Date: Fri, 1 May 2015 07:16:51 +0000 (-0700) Subject: Fix X509 server certificate domain matching X-Git-Tag: SQUID_3_4_13~2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=608216a4b49475130cb66f8baaac04dfc0cfabd7;p=thirdparty%2Fsquid.git Fix X509 server certificate domain matching The X509 certificate domain fields may contain non-ASCII encodings. Ensure the domain match algorithm is only passed UTF-8 ASCII-compatible strings. --- diff --git a/src/ssl/support.cc b/src/ssl/support.cc index 561569f556..726dfa8686 100644 --- a/src/ssl/support.cc +++ b/src/ssl/support.cc @@ -209,7 +209,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(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);