]> git.ipfire.org Git - thirdparty/openssl.git/commitdiff
speed.c: Check for 0 block size
authorTomas Mraz <tomas@openssl.org>
Tue, 29 Oct 2024 09:03:53 +0000 (10:03 +0100)
committerTomas Mraz <tomas@openssl.org>
Thu, 31 Oct 2024 12:00:10 +0000 (13:00 +0100)
Although this cannot really happen check for 0 block size
to avoid division by 0.

Fixes Coverity 1633936

Reviewed-by: Paul Dale <ppzgs1@gmail.com>
Reviewed-by: Dmitry Belyavskiy <beldmit@gmail.com>
Reviewed-by: Matt Caswell <matt@openssl.org>
Reviewed-by: Saša Nedvědický <sashan@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/25822)

apps/speed.c

index a6da71fe6d65587221425bbaa3489b9f099731a4..c3bc223a9d7c4198cf4987ba1105d8218b468ecf 100644 (file)
@@ -1448,8 +1448,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));