Prevent crash in X509_NAME_cmp() etc. when cert has no issuer or no serialNumber
authorDr. David von Oheimb <David.von.Oheimb@siemens.com>
Wed, 8 Apr 2020 11:39:15 +0000 (13:39 +0200)
committerDr. David von Oheimb <David.von.Oheimb@siemens.com>
Sat, 18 Apr 2020 17:54:17 +0000 (19:54 +0200)
Reviewed-by: Kurt Roeckx <kurt@roeckx.be>
Reviewed-by: Matt Caswell <matt@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/11386)

crypto/x509/x509_cmp.c

index 5b00038659a73ae01eb7513f308ea16b44684185..654b7b5a68673231e4e27cd0ceff0754a33fcbce 100644 (file)
@@ -21,6 +21,10 @@ int X509_issuer_and_serial_cmp(const X509 *a, const X509 *b)
     int i;
     const X509_CINF *ai, *bi;
 
+    if (b == NULL)
+        return a != NULL;
+    if (a == NULL)
+        return -1;
     ai = &a->cert_info;
     bi = &b->cert_info;
     i = ASN1_INTEGER_cmp(&ai->serialNumber, &bi->serialNumber);
@@ -161,8 +165,12 @@ int X509_NAME_cmp(const X509_NAME *a, const X509_NAME *b)
 {
     int ret;
 
-    /* Ensure canonical encoding is present and up to date */
+    if (b == NULL)
+        return a != NULL;
+    if (a == NULL)
+        return -1;
 
+    /* Ensure canonical encoding is present and up to date */
     if (!a->canon_enc || a->modified) {
         ret = i2d_X509_NAME((X509_NAME *)a, NULL);
         if (ret < 0)