From a45da353d3feb5d8fc00685fa1ceda3816d5108f Mon Sep 17 00:00:00 2001 From: "W.C.A. Wijngaards" Date: Fri, 24 Jul 2026 17:04:38 +0200 Subject: [PATCH] - Fix to call OPENSSL_cleanup on exit when that is defined. --- config.h.in | 3 +++ configure | 6 ++++++ configure.ac | 2 +- daemon/daemon.c | 3 +++ doc/Changelog | 1 + testcode/unitmain.c | 3 +++ 6 files changed, 17 insertions(+), 1 deletion(-) diff --git a/config.h.in b/config.h.in index 1785ae5c0..ce8141b53 100644 --- a/config.h.in +++ b/config.h.in @@ -529,6 +529,9 @@ /* Define to 1 if you have the header file. */ #undef HAVE_OPENSSL_BN_H +/* Define to 1 if you have the `OPENSSL_cleanup' function. */ +#undef HAVE_OPENSSL_CLEANUP + /* Define to 1 if you have the `OPENSSL_config' function. */ #undef HAVE_OPENSSL_CONFIG diff --git a/configure b/configure index 7d9702d30..8c0a416cd 100755 --- a/configure +++ b/configure @@ -21093,6 +21093,12 @@ then : printf "%s\n" "#define HAVE_BIO_SET_CALLBACK_EX 1" >>confdefs.h fi +ac_fn_c_check_func "$LINENO" "OPENSSL_cleanup" "ac_cv_func_OPENSSL_cleanup" +if test "x$ac_cv_func_OPENSSL_cleanup" = xyes +then : + printf "%s\n" "#define HAVE_OPENSSL_CLEANUP 1" >>confdefs.h + +fi # these check_funcs need -lssl diff --git a/configure.ac b/configure.ac index 165645e13..254a6c630 100644 --- a/configure.ac +++ b/configure.ac @@ -1081,7 +1081,7 @@ else AC_MSG_RESULT([no]) fi AC_CHECK_HEADERS([openssl/conf.h openssl/engine.h openssl/bn.h openssl/dh.h openssl/dsa.h openssl/rsa.h openssl/core_names.h openssl/param_build.h],,, [AC_INCLUDES_DEFAULT]) -AC_CHECK_FUNCS([OPENSSL_config EVP_sha1 EVP_sha256 EVP_sha512 FIPS_mode EVP_default_properties_is_fips_enabled EVP_MD_CTX_new OpenSSL_add_all_digests OPENSSL_init_crypto EVP_cleanup ENGINE_cleanup ERR_load_crypto_strings CRYPTO_cleanup_all_ex_data ERR_free_strings RAND_cleanup DSA_SIG_set0 EVP_dss1 EVP_DigestVerify EVP_aes_256_cbc EVP_EncryptInit_ex HMAC_Init_ex CRYPTO_THREADID_set_callback EVP_MAC_CTX_set_params OSSL_PARAM_BLD_new BIO_set_callback_ex]) +AC_CHECK_FUNCS([OPENSSL_config EVP_sha1 EVP_sha256 EVP_sha512 FIPS_mode EVP_default_properties_is_fips_enabled EVP_MD_CTX_new OpenSSL_add_all_digests OPENSSL_init_crypto EVP_cleanup ENGINE_cleanup ERR_load_crypto_strings CRYPTO_cleanup_all_ex_data ERR_free_strings RAND_cleanup DSA_SIG_set0 EVP_dss1 EVP_DigestVerify EVP_aes_256_cbc EVP_EncryptInit_ex HMAC_Init_ex CRYPTO_THREADID_set_callback EVP_MAC_CTX_set_params OSSL_PARAM_BLD_new BIO_set_callback_ex OPENSSL_cleanup]) # these check_funcs need -lssl BAKLIBS="$LIBS" diff --git a/daemon/daemon.c b/daemon/daemon.c index 07d99ff66..ac2cd3144 100644 --- a/daemon/daemon.c +++ b/daemon/daemon.c @@ -1308,6 +1308,9 @@ daemon_delete(struct daemon* daemon) # if defined(HAVE_SSL) && defined(OPENSSL_THREADS) && !defined(THREADS_DISABLED) ub_openssl_lock_delete(); # endif +#ifdef HAVE_OPENSSL_CLEANUP + OPENSSL_cleanup(); +#endif #ifndef HAVE_ARC4RANDOM _ARC4_LOCK_DESTROY(); #endif diff --git a/doc/Changelog b/doc/Changelog index 6092efff5..b6f771b81 100644 --- a/doc/Changelog +++ b/doc/Changelog @@ -28,6 +28,7 @@ tls-upstream is set. - Merge #1479 from psumbera: Fix pthread detection on Solaris 11.4. + - Fix to call OPENSSL_cleanup on exit when that is defined. 23 July 2026: Wouter - Updated credits for Xuanchao Xie in 22 july changelog. diff --git a/testcode/unitmain.c b/testcode/unitmain.c index 62f37375f..985a9d552 100644 --- a/testcode/unitmain.c +++ b/testcode/unitmain.c @@ -1445,6 +1445,9 @@ main(int argc, char* argv[]) # ifdef HAVE_RAND_CLEANUP RAND_cleanup(); # endif +#ifdef HAVE_OPENSSL_CLEANUP + OPENSSL_cleanup(); +#endif #elif defined(HAVE_NSS) if(NSS_Shutdown() != SECSuccess) fatal_exit("could not shutdown NSS"); -- 2.47.3