RT3841: memset() cipher_data when allocated
authorRich Salz <rsalz@akamai.com>
Fri, 8 May 2015 16:23:56 +0000 (12:23 -0400)
committerRich Salz <rsalz@openssl.org>
Wed, 13 May 2015 17:05:07 +0000 (13:05 -0400)
If an EVP implementation (such as an engine) fails out early, it's
possible to call EVP_CIPHER_CTX_cleanup() which will call
ctx->cipher->cleanup() before the cipher_data has been initialized
via ctx->cipher->init().  Guarantee it's all-bytes-zero as soon as
it is allocated.

Reviewed-by: Matt Caswell <matt@openssl.org>
crypto/evp/evp_enc.c

index 242874c5f646237ba15039280c97b3e8cfe669bb..aea7accf6fe0fb5e4c8a81694cd4ac57b61a06a0 100644 (file)
@@ -165,6 +165,7 @@ int EVP_CipherInit_ex(EVP_CIPHER_CTX *ctx, const EVP_CIPHER *cipher,
                 EVPerr(EVP_F_EVP_CIPHERINIT_EX, ERR_R_MALLOC_FAILURE);
                 return 0;
             }
+            memset(ctx->cipher_data, 0, ctx->cipher->ctx_size);
         } else {
             ctx->cipher_data = NULL;
         }