diff options
author | Pauli <ppzgs1@gmail.com> | 2021-03-19 09:11:02 +1000 |
---|---|---|
committer | Pauli <pauli@openssl.org> | 2021-03-26 08:46:01 +1000 |
commit | a02d70dd510e66eb2f916a723e30fd7e75b33eef (patch) | |
tree | 77a5fd7a18eb0a877e9023feb018ab33de15e1a8 /apps/speed.c | |
parent | 6a6844a219769aa9f58782fda2960c0ab5a4022b (diff) | |
download | openssl-a02d70dd510e66eb2f916a723e30fd7e75b33eef.zip openssl-a02d70dd510e66eb2f916a723e30fd7e75b33eef.tar.gz openssl-a02d70dd510e66eb2f916a723e30fd7e75b33eef.tar.bz2 |
apps: fix coverity 1358776, 1451513, 1451519, 1451531 & 1473387: unchecked return values
Reviewed-by: Tomas Mraz <tomas@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/14615)
Diffstat (limited to 'apps/speed.c')
-rw-r--r-- | apps/speed.c | 45 |
1 files changed, 28 insertions, 17 deletions
diff --git a/apps/speed.c b/apps/speed.c index 30e7036..0bd566e 100644 --- a/apps/speed.c +++ b/apps/speed.c @@ -729,7 +729,11 @@ static EVP_CIPHER_CTX *init_evp_cipher_ctx(const char *ciphername, goto end; } - EVP_CIPHER_CTX_set_key_length(ctx, keylen); + if (!EVP_CIPHER_CTX_set_key_length(ctx, keylen)) { + EVP_CIPHER_CTX_free(ctx); + ctx = NULL; + goto end; + } if (!EVP_CipherInit_ex(ctx, NULL, NULL, key, iv, 1)) { EVP_CIPHER_CTX_free(ctx); @@ -838,19 +842,19 @@ static int EVP_Update_loop_aead(void *args) if (decrypt) { for (count = 0; COND(c[D_EVP][testnum]); count++) { - EVP_DecryptInit_ex(ctx, NULL, NULL, NULL, iv); - EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_AEAD_SET_TAG, - sizeof(faketag), faketag); - EVP_DecryptUpdate(ctx, NULL, &outl, aad, sizeof(aad)); - EVP_DecryptUpdate(ctx, buf, &outl, buf, lengths[testnum]); - EVP_DecryptFinal_ex(ctx, buf + outl, &outl); + (void)EVP_DecryptInit_ex(ctx, NULL, NULL, NULL, iv); + (void)EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_AEAD_SET_TAG, + sizeof(faketag), faketag); + (void)EVP_DecryptUpdate(ctx, NULL, &outl, aad, sizeof(aad)); + (void)EVP_DecryptUpdate(ctx, buf, &outl, buf, lengths[testnum]); + (void)EVP_DecryptFinal_ex(ctx, buf + outl, &outl); } } else { for (count = 0; COND(c[D_EVP][testnum]); count++) { - EVP_EncryptInit_ex(ctx, NULL, NULL, NULL, iv); - EVP_EncryptUpdate(ctx, NULL, &outl, aad, sizeof(aad)); - EVP_EncryptUpdate(ctx, buf, &outl, buf, lengths[testnum]); - EVP_EncryptFinal_ex(ctx, buf + outl, &outl); + (void)EVP_EncryptInit_ex(ctx, NULL, NULL, NULL, iv); + (void)EVP_EncryptUpdate(ctx, NULL, &outl, aad, sizeof(aad)); + (void)EVP_EncryptUpdate(ctx, buf, &outl, buf, lengths[testnum]); + (void)EVP_EncryptFinal_ex(ctx, buf + outl, &outl); } } return count; @@ -3610,20 +3614,27 @@ static void multiblock_speed(const EVP_CIPHER *evp_cipher, int lengths_single, inp = app_malloc(mblengths[num - 1], "multiblock input buffer"); out = app_malloc(mblengths[num - 1] + 1024, "multiblock output buffer"); - ctx = EVP_CIPHER_CTX_new(); - EVP_EncryptInit_ex(ctx, evp_cipher, NULL, NULL, no_iv); + if ((ctx = EVP_CIPHER_CTX_new()) == NULL) + app_bail_out("failed to allocate cipher context\n"); + if (!EVP_EncryptInit_ex(ctx, evp_cipher, NULL, NULL, no_iv)) + app_bail_out("failed to initialise cipher context\n"); if ((keylen = EVP_CIPHER_CTX_key_length(ctx)) < 0) { BIO_printf(bio_err, "Impossible negative key length: %d\n", keylen); return; } key = app_malloc(keylen, "evp_cipher key"); - EVP_CIPHER_CTX_rand_key(ctx, key); - EVP_EncryptInit_ex(ctx, NULL, NULL, key, NULL); + if (!EVP_CIPHER_CTX_rand_key(ctx, key)) + app_bail_out("failed to generate random cipher key\n"); + if (!EVP_EncryptInit_ex(ctx, NULL, NULL, key, NULL)) + app_bail_out("failed to set cipher key\n"); OPENSSL_clear_free(key, keylen); - EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_AEAD_SET_MAC_KEY, sizeof(no_key), no_key); - alg_name = OBJ_nid2ln(EVP_CIPHER_nid(evp_cipher)); + if (!EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_AEAD_SET_MAC_KEY, + sizeof(no_key), no_key)) + app_bail_out("failed to set AEAD key\n"); + if ((alg_name = OBJ_nid2ln(EVP_CIPHER_nid(evp_cipher))) == NULL) + app_bail_out("failed to get cipher name\n"); for (j = 0; j < num; j++) { print_message(alg_name, 0, mblengths[j], seconds->sym); |