From e5ca9a7e4a469ca3bdf9778d8161dcfbfa835625 Mon Sep 17 00:00:00 2001 From: Junior Martinez <67972863+jmartinez-silabs@users.noreply.github.com> Date: Tue, 16 Apr 2024 15:18:28 -0400 Subject: [PATCH] Add Null check for a function pointer that might not be set (#184) (#185) It is possible that the pkinfo of the used pk contect is uninitialized. Add a check to make sure it has a free function before calling it --- matter/mbedtls/tinycrypt/src/pk.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/matter/mbedtls/tinycrypt/src/pk.c b/matter/mbedtls/tinycrypt/src/pk.c index f498935ee8..6bfc165a65 100644 --- a/matter/mbedtls/tinycrypt/src/pk.c +++ b/matter/mbedtls/tinycrypt/src/pk.c @@ -95,8 +95,9 @@ void mbedtls_pk_free(mbedtls_pk_context *ctx) { if (ctx == NULL) return; - if (ctx->pk_info != NULL) + if ((ctx->pk_info != NULL) && (ctx->pk_info->ctx_free_func != NULL)) { ctx->pk_info->ctx_free_func(ctx->pk_ctx); + } mbedtls_platform_zeroize(ctx, sizeof(mbedtls_pk_context)); }