]> git.ipfire.org Git - thirdparty/openssl.git/commitdiff
coverity: fix 1478169: dereference after NULL check
authorPauli <pauli@openssl.org>
Mon, 3 May 2021 22:23:10 +0000 (08:23 +1000)
committerPauli <pauli@openssl.org>
Thu, 6 May 2021 01:01:30 +0000 (11:01 +1000)
The code path shouldn't occur in our code but could in an application.

Reviewed-by: Shane Lontis <shane.lontis@oracle.com>
(Merged from https://github.com/openssl/openssl/pull/15128)

crypto/pkcs12/p12_p8e.c

index ac2c7ef5375cd6dfb4f1e27e9ac51122e88ce382..5351e11d34efcda23eebe2f566c5880b4e1b4769 100644 (file)
@@ -22,13 +22,21 @@ X509_SIG *PKCS8_encrypt_ex(int pbe_nid, const EVP_CIPHER *cipher,
     X509_SIG *p8 = NULL;
     X509_ALGOR *pbe;
 
-    if (pbe_nid == -1)
+    if (pbe_nid == -1) {
+        if (cipher == NULL) {
+            ERR_raise(ERR_LIB_PKCS12, ERR_R_PASSED_NULL_PARAMETER);
+            return NULL;
+        }
         pbe = PKCS5_pbe2_set_iv_ex(cipher, iter, salt, saltlen, NULL, -1,
                                    libctx);
-    else if (EVP_PBE_find(EVP_PBE_TYPE_PRF, pbe_nid, NULL, NULL, 0))
+    } else if (EVP_PBE_find(EVP_PBE_TYPE_PRF, pbe_nid, NULL, NULL, 0)) {
+        if (cipher == NULL) {
+            ERR_raise(ERR_LIB_PKCS12, ERR_R_PASSED_NULL_PARAMETER);
+            return NULL;
+        }
         pbe = PKCS5_pbe2_set_iv_ex(cipher, iter, salt, saltlen, NULL, pbe_nid,
                                    libctx);
-    else {
+    else {
         ERR_clear_error();
         pbe = PKCS5_pbe_set_ex(pbe_nid, iter, salt, saltlen, libctx);
     }