From 20643e9a72de5f391c76d90bc80955937fadc31c Mon Sep 17 00:00:00 2001 From: Juergen Repp Date: Mon, 26 Feb 2024 11:37:53 +0100 Subject: [PATCH] FAPI: Fix possible null pointer access in fapi crypto. In the cleanup function for an ossl hash context the variables were not checked before calling the ossl cleanup functions. Signed-off-by: Juergen Repp --- src/tss2-fapi/fapi_crypto.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/tss2-fapi/fapi_crypto.c b/src/tss2-fapi/fapi_crypto.c index 418179406..31382079a 100644 --- a/src/tss2-fapi/fapi_crypto.c +++ b/src/tss2-fapi/fapi_crypto.c @@ -66,10 +66,16 @@ ifapi_crypto_context_free(IFAPI_CRYPTO_CONTEXT *ctx) if (!ctx) return; - EVP_MD_CTX_destroy(ctx->osslContext); + if (ctx->osslContext) { + EVP_MD_CTX_destroy(ctx->osslContext); + } #if OPENSSL_VERSION_NUMBER >= 0x30000000L - EVP_MD_free(ctx->osslHashAlgorithm); - OSSL_LIB_CTX_free(ctx->libctx); + if (ctx->osslHashAlgorithm) { + EVP_MD_free(ctx->osslHashAlgorithm); + } + if (ctx->libctx) { + OSSL_LIB_CTX_free(ctx->libctx); + } #endif SAFE_FREE(ctx); }