Skip to content

Commit 8a0d34e

Browse files
committed
libpq: Don't overwrite existing OpenSSL thread callbacks
If someone else already set the callbacks, don't overwrite them with ours. When unsetting the callbacks, only unset them if they point to ours. Author: Jan Urbański <wulczer@wulczer.org>
1 parent a6f3c1f commit 8a0d34e

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

src/interfaces/libpq/fe-secure-openssl.c

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -806,9 +806,12 @@ pgtls_init(PGconn *conn)
806806

807807
if (ssl_open_connections++ == 0)
808808
{
809-
/* These are only required for threaded libcrypto applications */
810-
CRYPTO_set_id_callback(pq_threadidcallback);
811-
CRYPTO_set_locking_callback(pq_lockingcallback);
809+
/* These are only required for threaded libcrypto applications, but
810+
* make sure we don't stomp on them if they're already set. */
811+
if (CRYPTO_get_id_callback() == NULL)
812+
CRYPTO_set_id_callback(pq_threadidcallback);
813+
if (CRYPTO_get_locking_callback() == NULL)
814+
CRYPTO_set_locking_callback(pq_lockingcallback);
812815
}
813816
}
814817
#endif /* ENABLE_THREAD_SAFETY */
@@ -885,9 +888,12 @@ destroy_ssl_system(void)
885888

886889
if (pq_init_crypto_lib && ssl_open_connections == 0)
887890
{
888-
/* No connections left, unregister libcrypto callbacks */
889-
CRYPTO_set_locking_callback(NULL);
890-
CRYPTO_set_id_callback(NULL);
891+
/* No connections left, unregister libcrypto callbacks, if no one
892+
* registered different ones in the meantime. */
893+
if (CRYPTO_get_locking_callback() == pq_lockingcallback)
894+
CRYPTO_set_locking_callback(NULL);
895+
if (CRYPTO_get_id_callback() == pq_threadidcallback)
896+
CRYPTO_set_id_callback(NULL);
891897

892898
/*
893899
* We don't free the lock array or the SSL_context. If we get another

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy