Avoid SEGV when giving X509_sign a NULL private key.
authorPauli <paul.dale@oracle.com>
Thu, 6 Sep 2018 23:04:59 +0000 (09:04 +1000)
committerPauli <paul.dale@oracle.com>
Thu, 6 Sep 2018 23:04:59 +0000 (09:04 +1000)
Put a NULL check back in to avoid dereferencing the NULL pointer.

Reviewed-by: Tim Hudson <tjh@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/7146)

crypto/evp/pmeth_lib.c

index 6a0fc81f1ff2af5550c178e2048f5206575cc75e..ef923fdc5e4468539fdde776cf30fb974cb86cb4 100644 (file)
@@ -106,6 +106,8 @@ static EVP_PKEY_CTX *int_ctx_new(EVP_PKEY *pkey, ENGINE *e, int id)
     const EVP_PKEY_METHOD *pmeth;
 
     if (id == -1) {
+        if (pkey == NULL)
+            return 0;
         id = pkey->type;
     }
 #ifndef OPENSSL_NO_ENGINE
@@ -151,7 +153,7 @@ static EVP_PKEY_CTX *int_ctx_new(EVP_PKEY *pkey, ENGINE *e, int id)
     ret->pmeth = pmeth;
     ret->operation = EVP_PKEY_OP_UNDEFINED;
     ret->pkey = pkey;
-    if (pkey)
+    if (pkey != NULL)
         EVP_PKEY_up_ref(pkey);
 
     if (pmeth->init) {