Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/openssl/openssl.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPauli <pauli@openssl.org>2021-06-07 02:49:04 +0300
committerPauli <pauli@openssl.org>2021-06-08 12:32:25 +0300
commitcec8854cc90794a0696c518efabd90e0279658db (patch)
treece94290424528b0a9be67dee76404e4a005728db /crypto/evp/evp_enc.c
parent3f617061eceb2f33fb40682cc7b14cc4f9a2143f (diff)
evp: fix Coverity 1485670 argument cannot be negative
Reviewed-by: Tomas Mraz <tomas@openssl.org> (Merged from https://github.com/openssl/openssl/pull/15635)
Diffstat (limited to 'crypto/evp/evp_enc.c')
-rw-r--r--crypto/evp/evp_enc.c11
1 files changed, 7 insertions, 4 deletions
diff --git a/crypto/evp/evp_enc.c b/crypto/evp/evp_enc.c
index f39e9b8c90..cf73ba230e 100644
--- a/crypto/evp/evp_enc.c
+++ b/crypto/evp/evp_enc.c
@@ -344,7 +344,7 @@ static int evp_cipher_init_internal(EVP_CIPHER_CTX *ctx,
n = EVP_CIPHER_CTX_get_iv_length(ctx);
if (!ossl_assert(n >= 0 && n <= (int)sizeof(ctx->iv)))
return 0;
- if (iv)
+ if (iv != NULL)
memcpy(ctx->oiv, iv, EVP_CIPHER_CTX_get_iv_length(ctx));
memcpy(ctx->iv, ctx->oiv, EVP_CIPHER_CTX_get_iv_length(ctx));
break;
@@ -352,8 +352,11 @@ static int evp_cipher_init_internal(EVP_CIPHER_CTX *ctx,
case EVP_CIPH_CTR_MODE:
ctx->num = 0;
/* Don't reuse IV for CTR mode */
- if (iv)
- memcpy(ctx->iv, iv, EVP_CIPHER_CTX_get_iv_length(ctx));
+ if (iv != NULL) {
+ if ((n = EVP_CIPHER_CTX_get_iv_length(ctx)) <= 0)
+ return 0;
+ memcpy(ctx->iv, iv, n);
+ }
break;
default:
@@ -361,7 +364,7 @@ static int evp_cipher_init_internal(EVP_CIPHER_CTX *ctx,
}
}
- if (key || (ctx->cipher->flags & EVP_CIPH_ALWAYS_CALL_INIT)) {
+ if (key != NULL || (ctx->cipher->flags & EVP_CIPH_ALWAYS_CALL_INIT)) {
if (!ctx->cipher->init(ctx, key, iv, enc))
return 0;
}