]> git.ipfire.org Git - thirdparty/openvpn.git/commitdiff
Check if pkcs11_cert is NULL before freeing it
authorMax Fillinger <maximilian.fillinger@foxcrypto.com>
Wed, 23 Nov 2022 15:49:12 +0000 (16:49 +0100)
committerGert Doering <gert@greenie.muc.de>
Wed, 23 Nov 2022 21:08:05 +0000 (22:08 +0100)
When running openvpn --show-tls with mbedtls, it showed a null pointer
error at the end because of this.

Signed-off-by: Max Fillinger <maximilian.fillinger@foxcrypto.com>
Acked-by: Arne Schwabe <arne@rfc2549.org>
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 <gert@greenie.muc.de>
(cherry picked from commit 19c64f16baebbce966d55c62135d1ef066f7c8c2)

src/openvpn/ssl_mbedtls.c

index be0e57f154e20deb7603147c09f33a6ba39da9d2..9958099ceaf3c35ace20be52c139943ed8d420d4 100644 (file)
@@ -168,7 +168,13 @@ tls_ctx_free(struct tls_root_ctx *ctx)
         }
 
 #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
 
         if (ctx->allowed_ciphers)