From 1002bb9ff0e35b4195586199222f9bad77837162 Mon Sep 17 00:00:00 2001 From: Pauli Date: Fri, 19 Mar 2021 14:49:57 +1000 Subject: [PATCH] evp: fix coverity 1472682: argument cannot be negative Reviewed-by: Matt Caswell (Merged from https://github.com/openssl/openssl/pull/14620) --- crypto/evp/e_cast.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/crypto/evp/e_cast.c b/crypto/evp/e_cast.c index 8325a5f8d21..883030224ba 100644 --- a/crypto/evp/e_cast.c +++ b/crypto/evp/e_cast.c @@ -40,7 +40,11 @@ IMPLEMENT_BLOCK_CIPHER(cast5, ks, CAST, EVP_CAST_KEY, static int cast_init_key(EVP_CIPHER_CTX *ctx, const unsigned char *key, const unsigned char *iv, int enc) { - CAST_set_key(&data(ctx)->ks, EVP_CIPHER_CTX_key_length(ctx), key); + int keylen = EVP_CIPHER_CTX_key_length(ctx); + + if (keylen <= 0) + return 0; + CAST_set_key(&data(ctx)->ks, keylen, key); return 1; } -- 2.47.2