bbd2dd
diff -up openssl-1.0.2k/ssl/ssl_cert.c.name-sensitive openssl-1.0.2k/ssl/ssl_cert.c
bbd2dd
--- openssl-1.0.2k/ssl/ssl_cert.c.name-sensitive	2017-01-26 14:22:04.000000000 +0100
bbd2dd
+++ openssl-1.0.2k/ssl/ssl_cert.c	2018-06-18 13:43:12.452502627 +0200
bbd2dd
@@ -855,9 +855,33 @@ int SSL_CTX_add_client_CA(SSL_CTX *ctx,
bbd2dd
     return (add_client_CA(&(ctx->client_CA), x));
bbd2dd
 }
bbd2dd
 
bbd2dd
-static int xname_cmp(const X509_NAME *const *a, const X509_NAME *const *b)
bbd2dd
+static int xname_cmp(const X509_NAME *a, const X509_NAME *b)
bbd2dd
 {
bbd2dd
-    return (X509_NAME_cmp(*a, *b));
bbd2dd
+    unsigned char *abuf = NULL, *bbuf = NULL;
bbd2dd
+    int alen, blen, ret;
bbd2dd
+
bbd2dd
+    /* X509_NAME_cmp() itself casts away constness in this way, so
bbd2dd
+     * assume it's safe:
bbd2dd
+     */
bbd2dd
+    alen = i2d_X509_NAME((X509_NAME *)a, &abuf);
bbd2dd
+    blen = i2d_X509_NAME((X509_NAME *)b, &bbuf);
bbd2dd
+
bbd2dd
+    if (alen < 0 || blen < 0)
bbd2dd
+        ret = -2;
bbd2dd
+    else if (alen != blen)
bbd2dd
+        ret = alen - blen;
bbd2dd
+    else /* alen == blen */
bbd2dd
+        ret = memcmp(abuf, bbuf, alen);
bbd2dd
+
bbd2dd
+    OPENSSL_free(abuf);
bbd2dd
+    OPENSSL_free(bbuf);
bbd2dd
+
bbd2dd
+    return ret;
bbd2dd
+}
bbd2dd
+
bbd2dd
+static int xname_sk_cmp(const X509_NAME *const *a, const X509_NAME *const *b)
bbd2dd
+{
bbd2dd
+    return xname_cmp(*a, *b);
bbd2dd
 }
bbd2dd
 
bbd2dd
 #ifndef OPENSSL_NO_STDIO
bbd2dd
@@ -876,7 +900,7 @@ STACK_OF(X509_NAME) *SSL_load_client_CA_
bbd2dd
     X509_NAME *xn = NULL;
bbd2dd
     STACK_OF(X509_NAME) *ret = NULL, *sk;
bbd2dd
 
bbd2dd
-    sk = sk_X509_NAME_new(xname_cmp);
bbd2dd
+    sk = sk_X509_NAME_new(xname_sk_cmp);
bbd2dd
 
bbd2dd
     in = BIO_new(BIO_s_file_internal());
bbd2dd
 
bbd2dd
@@ -948,7 +972,7 @@ int SSL_add_file_cert_subjects_to_stack(
bbd2dd
     int ret = 1;
bbd2dd
     int (*oldcmp) (const X509_NAME *const *a, const X509_NAME *const *b);
bbd2dd
 
bbd2dd
-    oldcmp = sk_X509_NAME_set_cmp_func(stack, xname_cmp);
bbd2dd
+    oldcmp = sk_X509_NAME_set_cmp_func(stack, xname_sk_cmp);
bbd2dd
 
bbd2dd
     in = BIO_new(BIO_s_file_internal());
bbd2dd