From: Pauli Date: Thu, 18 Mar 2021 23:11:02 +0000 (+1000) Subject: apps: fix coverity 1358776, 1451513, 1451519, 1451531 & 1473387: unchecked return... X-Git-Tag: openssl-3.0.0-alpha14~135 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=a02d70dd510e66eb2f916a723e30fd7e75b33eef;p=thirdparty%2Fopenssl.git apps: fix coverity 1358776, 1451513, 1451519, 1451531 & 1473387: unchecked return values Reviewed-by: Tomas Mraz (Merged from https://github.com/openssl/openssl/pull/14615) --- diff --git a/apps/speed.c b/apps/speed.c index 30e703632f1..0bd566e8466 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);