diff options
author | Pauli <pauli@openssl.org> | 2021-05-17 09:38:29 +1000 |
---|---|---|
committer | Pauli <pauli@openssl.org> | 2021-05-18 13:24:41 +1000 |
commit | 3c18459235331e0562cfd2a9de5ab87040bf55f2 (patch) | |
tree | 771f6ced65a34c25e936fe8a12d99bdf5159d66b /crypto | |
parent | 634da876e0d6d95a23c5d005b1ac4354a04310d2 (diff) |
evp: fix coverity 1484885 negative integer to size_t conversion
Theoretically, the IV length can come back negative which would explode.
Reviewed-by: Tomas Mraz <tomas@openssl.org>
Reviewed-by: Shane Lontis <shane.lontis@oracle.com>
(Merged from https://github.com/openssl/openssl/pull/15300)
Diffstat (limited to 'crypto')
-rw-r--r-- | crypto/evp/p_seal.c | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/crypto/evp/p_seal.c b/crypto/evp/p_seal.c index 36900e0352..9371d110e9 100644 --- a/crypto/evp/p_seal.c +++ b/crypto/evp/p_seal.c @@ -20,7 +20,7 @@ int EVP_SealInit(EVP_CIPHER_CTX *ctx, const EVP_CIPHER *type, EVP_PKEY **pubk, int npubk) { unsigned char key[EVP_MAX_KEY_LENGTH]; - int i; + int i, len; int rv = 0; if (type) { @@ -34,15 +34,19 @@ int EVP_SealInit(EVP_CIPHER_CTX *ctx, const EVP_CIPHER *type, if (EVP_CIPHER_CTX_rand_key(ctx, key) <= 0) return 0; - if (EVP_CIPHER_CTX_iv_length(ctx) - && RAND_bytes(iv, EVP_CIPHER_CTX_iv_length(ctx)) <= 0) + len = EVP_CIPHER_CTX_iv_length(ctx); + if (len < 0 || RAND_bytes(iv, len) <= 0) + goto err; + + len = EVP_CIPHER_CTX_key_length(ctx); + if (len < 0) goto err; if (!EVP_EncryptInit_ex(ctx, NULL, NULL, key, iv)) goto err; for (i = 0; i < npubk; i++) { - size_t keylen = EVP_CIPHER_CTX_key_length(ctx); + size_t keylen = len; EVP_PKEY_CTX *pctx = NULL; if ((pctx = EVP_PKEY_CTX_new(pubk[i], NULL)) == NULL) { |