From: Matt Caswell Date: Wed, 16 May 2018 10:59:47 +0000 (+0100) Subject: Fix undefined behaviour in X509_NAME_cmp() X-Git-Tag: OpenSSL_1_1_1-pre7~30 X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=511190b691183a1fb160e7e05e2974dc73cab0c6;p=oweals%2Fopenssl.git Fix undefined behaviour in X509_NAME_cmp() If the lengths of both names is 0 then don't attempt to do a memcmp. Issue reported by Simon Friedberger, Robert Merget and Juraj Somorovsky. Reviewed-by: Matthias St. Pierre (Merged from https://github.com/openssl/openssl/pull/6291) --- diff --git a/crypto/x509/x509_cmp.c b/crypto/x509/x509_cmp.c index 3d4931be4e..67c187229e 100644 --- a/crypto/x509/x509_cmp.c +++ b/crypto/x509/x509_cmp.c @@ -173,7 +173,7 @@ int X509_NAME_cmp(const X509_NAME *a, const X509_NAME *b) ret = a->canon_enclen - b->canon_enclen; - if (ret) + if (ret != 0 || a->canon_enclen == 0) return ret; return memcmp(a->canon_enc, b->canon_enc, a->canon_enclen);