From: Max Fillinger Date: Wed, 23 Nov 2022 15:49:12 +0000 (+0100) Subject: Check if pkcs11_cert is NULL before freeing it X-Git-Tag: v2.6_beta1~18 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=19c64f16baebbce966d55c62135d1ef066f7c8c2;p=thirdparty%2Fopenvpn.git Check if pkcs11_cert is NULL before freeing it When running openvpn --show-tls with mbedtls, it showed a null pointer error at the end because of this. Signed-off-by: Max Fillinger Acked-by: Arne Schwabe Message-Id: <20221123154912.28394-1-maximilian.fillinger@foxcrypto.com> URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg25530.html Signed-off-by: Gert Doering --- diff --git a/src/openvpn/ssl_mbedtls.c b/src/openvpn/ssl_mbedtls.c index ea06cf703..b0e42d8f7 100644 --- a/src/openvpn/ssl_mbedtls.c +++ b/src/openvpn/ssl_mbedtls.c @@ -165,7 +165,13 @@ tls_ctx_free(struct tls_root_ctx *ctx) free(ctx->crl); #if defined(ENABLE_PKCS11) - pkcs11h_certificate_freeCertificate(ctx->pkcs11_cert); + /* ...freeCertificate() can handle NULL ptrs, but if pkcs11 helper + * has not been initialized, it will ASSERT() - so, do not pass NULL + */ + if (ctx->pkcs11_cert) + { + pkcs11h_certificate_freeCertificate(ctx->pkcs11_cert); + } #endif free(ctx->allowed_ciphers);