From: Amos Jeffries Date: Fri, 1 May 2015 07:25:27 +0000 (-0700) Subject: Fix X509 server certificate domain matching X-Git-Tag: SQUID_3_2_14~1 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=dafe961fe880759d12141573f3ec1512f7e71fd8;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 2fa4052cc1..696fb5a41d 100644 --- a/src/ssl/support.cc +++ b/src/ssl/support.cc @@ -195,7 +195,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);