Skip to content

Commit 895bddf

Browse files
committed
fix(Crypto): fix LeakSanitizer failure in testProviderCleanup
Avoid reloading OpenSSL providers after a full uninitialize cycle in the test. OpenSSL internally leaks OSSL_LIB_CTX state when providers are unloaded and reloaded, triggering LeakSanitizer false positives. Also add haveDefaultProvider() accessor to verify that both default and legacy provider pointers are properly nullified after cleanup.
1 parent b94de90 commit 895bddf

File tree

2 files changed

+22
-15
lines changed

2 files changed

+22
-15
lines changed

Crypto/include/Poco/Crypto/OpenSSLInitializer.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,9 @@ class Crypto_API OpenSSLInitializer
5656
static void enableFIPSMode(bool enabled);
5757
/// Enable or disable FIPS mode. If FIPS is not available, this method doesn't do anything.
5858

59+
static bool haveDefaultProvider();
60+
/// Returns true if the OpenSSL default provider is loaded, otherwise false.
61+
5962
static bool haveLegacyProvider();
6063
/// Returns true if the OpenSSL legacy provider is available, otherwise false.
6164

@@ -94,6 +97,16 @@ inline void OpenSSLInitializer::enableFIPSMode(bool /*enabled*/)
9497
#endif
9598

9699

100+
inline bool OpenSSLInitializer::haveDefaultProvider()
101+
{
102+
#if POCO_OPENSSL_VERSION_PREREQ(3, 0, 0)
103+
return _defaultProvider != nullptr;
104+
#else
105+
return false;
106+
#endif
107+
}
108+
109+
97110
inline bool OpenSSLInitializer::haveLegacyProvider()
98111
{
99112
#if POCO_OPENSSL_VERSION_PREREQ(3, 0, 0)

Crypto/testsuite/src/OpenSSLInitializerTest.cpp

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -95,31 +95,25 @@ void OpenSSLInitializerTest::testProviderCleanup()
9595
// Verify that after a full initialize/uninitialize cycle down to
9696
// ref count 0, providers are properly cleaned up (GH #4451).
9797
// The test driver holds one global init, so we must drain that too.
98-
// We verify via haveLegacyProvider() which checks the managed pointer.
99-
// Note: OSSL_PROVIDER_available() cannot be used to verify unload
100-
// because OpenSSL auto-loads the default provider when queried.
98+
// We verify via haveDefaultProvider()/haveLegacyProvider() which
99+
// check the managed pointers.
101100

102101
OpenSSLInitializer::initialize();
103-
assertTrue(OSSL_PROVIDER_available(nullptr, "default"));
104-
bool hadLegacy = OpenSSLInitializer::haveLegacyProvider();
102+
assertTrue(OpenSSLInitializer::haveDefaultProvider());
105103

106104
// Drain ref count to 0: undo our init + the driver's global init
107105
OpenSSLInitializer::uninitialize();
108106
OpenSSLInitializer::uninitialize();
109107

110-
// Providers should be unloaded now (ref count was 0)
108+
// Both provider pointers should be null now (ref count was 0)
109+
assertFalse(OpenSSLInitializer::haveDefaultProvider());
111110
assertFalse(OpenSSLInitializer::haveLegacyProvider());
112111

113-
// Re-initialize twice to restore: once for the driver, once for our balance
114-
OpenSSLInitializer::initialize();
112+
// Re-initialize to restore state for the driver's uninitialize at exit.
113+
// Note: we do not verify provider reload consistency here because
114+
// OpenSSL internally leaks OSSL_LIB_CTX state on provider reload,
115+
// which triggers LeakSanitizer false positives.
115116
OpenSSLInitializer::initialize();
116-
assertTrue(OSSL_PROVIDER_available(nullptr, "default"));
117-
bool hasLegacy = OpenSSLInitializer::haveLegacyProvider();
118-
// Legacy availability should be consistent across cycles
119-
assertTrue(hasLegacy == hadLegacy);
120-
121-
// Undo our extra init (driver's init remains)
122-
OpenSSLInitializer::uninitialize();
123117
}
124118

125119
#endif // POCO_OPENSSL_VERSION_PREREQ(3, 0, 0)

0 commit comments

Comments
 (0)