Coverity CID 1444954: Integer handling issues
authorPauli <paul.dale@oracle.com>
Tue, 7 May 2019 00:59:14 +0000 (10:59 +1000)
committerPauli <paul.dale@oracle.com>
Tue, 7 May 2019 23:52:58 +0000 (09:52 +1000)
Reviewed-by: Matt Caswell <matt@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/8888)

crypto/evp/evp_enc.c

index 1eb894b..0ccea35 100644 (file)
@@ -957,9 +957,11 @@ int EVP_CIPHER_CTX_ctrl(EVP_CIPHER_CTX *ctx, int type, int arg, void *ptr)
 
 int EVP_CIPHER_CTX_rand_key(EVP_CIPHER_CTX *ctx, unsigned char *key)
 {
+    int kl;
     if (ctx->cipher->flags & EVP_CIPH_RAND_KEY)
         return EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_RAND_KEY, 0, key);
-    if (RAND_priv_bytes(key, EVP_CIPHER_CTX_key_length(ctx)) <= 0)
+    kl = EVP_CIPHER_CTX_key_length(ctx);
+    if (kl <= 0 || RAND_priv_bytes(key, kl) <= 0)
         return 0;
     return 1;
 }