Don't set ctx->cipher until after a successful fetch
authorMatt Caswell <matt@openssl.org>
Mon, 5 Aug 2019 12:37:05 +0000 (13:37 +0100)
committerMatt Caswell <matt@openssl.org>
Wed, 7 Aug 2019 10:40:32 +0000 (11:40 +0100)
If an implict EVP_CIPHER_fetch fails then ctx->cipher should not be set
otherwise strange things will happen when trying to free the ctx.

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

crypto/evp/evp_enc.c

index 87c7bb099572143692eecf64cf121936d994014d..31e15a63c25ffa5c500b502d73b521c1899396c9 100644 (file)
@@ -197,9 +197,7 @@ int EVP_CipherInit_ex(EVP_CIPHER_CTX *ctx, const EVP_CIPHER *cipher,
         ctx->flags = flags;
     }
 
-    if (cipher != NULL)
-        ctx->cipher = cipher;
-    else
+    if (cipher == NULL)
         cipher = ctx->cipher;
 
     if (cipher->prov == NULL) {