From b669983c6f0e60f13e73c9d94528870174d3d090 Mon Sep 17 00:00:00 2001 From: Torben Hansen <50673096+torben-hansen@users.noreply.github.com> Date: Mon, 9 Dec 2024 11:18:20 -0800 Subject: [PATCH] Prevent accidental null dereference --- crypto/fipsmodule/cipher/cipher.c | 28 +++++++++++++++++++++------- 1 file changed, 21 insertions(+), 7 deletions(-) diff --git a/crypto/fipsmodule/cipher/cipher.c b/crypto/fipsmodule/cipher/cipher.c index d3a13921de..18168136f4 100644 --- a/crypto/fipsmodule/cipher/cipher.c +++ b/crypto/fipsmodule/cipher/cipher.c @@ -689,18 +689,32 @@ int EVP_CIPHER_CTX_set_key_length(EVP_CIPHER_CTX *c, unsigned key_len) { return 1; } -int EVP_CIPHER_nid(const EVP_CIPHER *cipher) { return cipher->nid; } +int EVP_CIPHER_nid(const EVP_CIPHER *cipher) { + if (cipher != NULL) { + return cipher->nid; + } + return 0; +} -unsigned EVP_CIPHER_block_size(const EVP_CIPHER *cipher) { - return cipher->block_size; +size_t EVP_CIPHER_block_size(const EVP_CIPHER *cipher) { + if (cipher != NULL) { + return cipher->block_size; + } + return 0; } -unsigned EVP_CIPHER_key_length(const EVP_CIPHER *cipher) { - return cipher->key_len; +size_t EVP_CIPHER_key_length(const EVP_CIPHER *cipher) { + if (cipher != NULL) { + return cipher->key_len; + } + return 0; } -unsigned EVP_CIPHER_iv_length(const EVP_CIPHER *cipher) { - return cipher->iv_len; +size_t EVP_CIPHER_iv_length(const EVP_CIPHER *cipher) { + if (cipher != NULL) { + return cipher->iv_len; + } + return 0; } uint32_t EVP_CIPHER_flags(const EVP_CIPHER *cipher) {