Blame SOURCES/openssl-1.0.2k-name-sensitive.patch

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