From: Pauli Date: Mon, 22 Mar 2021 02:09:19 +0000 (+1000) Subject: enc: fix coverity 1451499, 1451501, 1451506, 1451507, 1351511, 1451514, 1451517,... X-Git-Tag: openssl-3.0.0-alpha14~162 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=1634b2df9f12d3976129ba49e38638e3ab368e3d;p=thirdparty%2Fopenssl.git enc: fix coverity 1451499, 1451501, 1451506, 1451507, 1351511, 1451514, 1451517, 1451523, 1451526m 1451528, 1451539, 1451441, 1451549, 1451568 & 1451572: improper use of negative value Reviewed-by: Tomas Mraz (Merged from https://github.com/openssl/openssl/pull/14638) --- diff --git a/crypto/evp/e_aria.c b/crypto/evp/e_aria.c index f3a68eb09d1..3e64e45f89e 100644 --- a/crypto/evp/e_aria.c +++ b/crypto/evp/e_aria.c @@ -171,7 +171,7 @@ static int aria_ctr_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, const unsigned char *in, size_t len) { unsigned int num = EVP_CIPHER_CTX_num(ctx); - EVP_ARIA_KEY *dat = EVP_C_DATA(EVP_ARIA_KEY,ctx); + EVP_ARIA_KEY *dat = EVP_C_DATA(EVP_ARIA_KEY, ctx); CRYPTO_ctr128_encrypt(in, out, len, &dat->ks, ctx->iv, EVP_CIPHER_CTX_buf_noconst(ctx), &num, diff --git a/crypto/evp/e_camellia.c b/crypto/evp/e_camellia.c index 0d338b8b2fa..3e7cd769346 100644 --- a/crypto/evp/e_camellia.c +++ b/crypto/evp/e_camellia.c @@ -316,9 +316,13 @@ static int camellia_cfb1_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, static int camellia_ctr_cipher(EVP_CIPHER_CTX *ctx, unsigned char *out, const unsigned char *in, size_t len) { - unsigned int num = EVP_CIPHER_CTX_num(ctx); + int snum = EVP_CIPHER_CTX_num(ctx); + unsigned int num; EVP_CAMELLIA_KEY *dat = EVP_C_DATA(EVP_CAMELLIA_KEY,ctx); + if (snum < 0) + return 0; + num = snum; if (dat->stream.ctr) CRYPTO_ctr128_encrypt_ctr32(in, out, len, &dat->ks, ctx->iv, EVP_CIPHER_CTX_buf_noconst(ctx), &num, diff --git a/crypto/idea/i_cfb64.c b/crypto/idea/i_cfb64.c index b9db1639cf3..a477799edf6 100644 --- a/crypto/idea/i_cfb64.c +++ b/crypto/idea/i_cfb64.c @@ -33,6 +33,11 @@ void IDEA_cfb64_encrypt(const unsigned char *in, unsigned char *out, unsigned long ti[2]; unsigned char *iv, c, cc; + if (n < 0) { + *num = -1; + return; + } + iv = (unsigned char *)ivec; if (encrypt) { while (l--) { diff --git a/crypto/idea/i_ofb64.c b/crypto/idea/i_ofb64.c index 89ac18ce918..246886bdc43 100644 --- a/crypto/idea/i_ofb64.c +++ b/crypto/idea/i_ofb64.c @@ -35,6 +35,11 @@ void IDEA_ofb64_encrypt(const unsigned char *in, unsigned char *out, unsigned char *iv; int save = 0; + if (n < 0) { + *num = -1; + return; + } + iv = (unsigned char *)ivec; n2l(iv, v0); n2l(iv, v1); diff --git a/crypto/modes/cfb128.c b/crypto/modes/cfb128.c index fa94f047b55..f9c3c605369 100644 --- a/crypto/modes/cfb128.c +++ b/crypto/modes/cfb128.c @@ -30,6 +30,11 @@ void CRYPTO_cfb128_encrypt(const unsigned char *in, unsigned char *out, unsigned int n; size_t l = 0; + if (*num < 0) { + /* There is no good way to signal an error return from here */ + *num = -1; + return; + } n = *num; if (enc) { diff --git a/crypto/modes/ctr128.c b/crypto/modes/ctr128.c index b902ee9b0b7..2147751c588 100644 --- a/crypto/modes/ctr128.c +++ b/crypto/modes/ctr128.c @@ -155,7 +155,7 @@ void CRYPTO_ctr128_encrypt_ctr32(const unsigned char *in, unsigned char *out, { unsigned int n, ctr32; - n = *num; + n = *num; while (n && len) { *(out++) = *(in++) ^ ecount_buf[n]; diff --git a/crypto/modes/ofb128.c b/crypto/modes/ofb128.c index 829d724e2ae..0b213802083 100644 --- a/crypto/modes/ofb128.c +++ b/crypto/modes/ofb128.c @@ -29,6 +29,11 @@ void CRYPTO_ofb128_encrypt(const unsigned char *in, unsigned char *out, unsigned int n; size_t l = 0; + if (*num < 0) { + /* There is no good way to signal an error return from here */ + *num = -1; + return; + } n = *num; #if !defined(OPENSSL_SMALL_FOOTPRINT)