From 7ca36d55fbc4263b76f5327773f0e4a319fab65d Mon Sep 17 00:00:00 2001 From: Tomas Mraz Date: Tue, 29 Oct 2024 10:03:53 +0100 Subject: [PATCH] speed.c: Check for 0 block size MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Although this cannot really happen check for 0 block size to avoid division by 0. Fixes Coverity 1633936 Reviewed-by: Paul Dale Reviewed-by: Dmitry Belyavskiy Reviewed-by: Matt Caswell Reviewed-by: Saša Nedvědický (Merged from https://github.com/openssl/openssl/pull/25822) (cherry picked from commit 59f5f6c73cd2e1e2bd8ef405fdb6fadf0711f639) --- apps/speed.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/apps/speed.c b/apps/speed.c index eb233bc806b..ec8ff0662f3 100644 --- a/apps/speed.c +++ b/apps/speed.c @@ -1447,8 +1447,13 @@ static int SIG_verify_loop(void *args) static int check_block_size(EVP_CIPHER_CTX *ctx, int length) { const EVP_CIPHER *ciph = EVP_CIPHER_CTX_get0_cipher(ctx); + int blocksize = EVP_CIPHER_CTX_get_block_size(ctx); - if (length % EVP_CIPHER_get_block_size(ciph) != 0) { + if (ciph == NULL || blocksize <= 0) { + BIO_printf(bio_err, "\nInvalid cipher!\n"); + return 0; + } + if (length % blocksize != 0) { BIO_printf(bio_err, "\nRequested encryption length not a multiple of block size for %s!\n", EVP_CIPHER_get0_name(ciph)); -- 2.47.2