Skip to content

Commit

Permalink
FAPI: Fix possible null pointer access in fapi crypto.
Browse files Browse the repository at this point in the history
* In the cleanup function for an ossl hash context the variables
  were not checked before calling the ossl cleanup functions.
* An unneded cast was removed.

Signed-off-by: Juergen Repp <juergen_repp@web.de>
  • Loading branch information
JuergenReppSIT committed Feb 27, 2024
1 parent 7899089 commit 638f187
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions src/tss2-fapi/fapi_crypto.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down Expand Up @@ -1659,11 +1665,11 @@ ifapi_crypto_hash_start(IFAPI_CRYPTO_CONTEXT_BLOB **context,
}

*context = (IFAPI_CRYPTO_CONTEXT_BLOB *) mycontext;

return TSS2_RC_SUCCESS;

cleanup:
ifapi_crypto_context_free(mycontext);
*context = NULL;
return r;
}

Expand Down Expand Up @@ -1766,9 +1772,8 @@ ifapi_crypto_hash_abort(IFAPI_CRYPTO_CONTEXT_BLOB **context)
LOG_DEBUG("Null-Pointer passed");
return;
}
IFAPI_CRYPTO_CONTEXT *mycontext = (IFAPI_CRYPTO_CONTEXT *) * context;

ifapi_crypto_context_free(mycontext);
ifapi_crypto_context_free(*context);
*context = NULL;
}

Expand Down

0 comments on commit 638f187

Please sign in to comment.