Commit 8a0d34e4 authored by Peter Eisentraut's avatar Peter Eisentraut

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>
parent a6f3c1f1
...@@ -806,8 +806,11 @@ pgtls_init(PGconn *conn) ...@@ -806,8 +806,11 @@ pgtls_init(PGconn *conn)
if (ssl_open_connections++ == 0) if (ssl_open_connections++ == 0)
{ {
/* These are only required for threaded libcrypto applications */ /* These are only required for threaded libcrypto applications, but
* make sure we don't stomp on them if they're already set. */
if (CRYPTO_get_id_callback() == NULL)
CRYPTO_set_id_callback(pq_threadidcallback); CRYPTO_set_id_callback(pq_threadidcallback);
if (CRYPTO_get_locking_callback() == NULL)
CRYPTO_set_locking_callback(pq_lockingcallback); CRYPTO_set_locking_callback(pq_lockingcallback);
} }
} }
...@@ -885,8 +888,11 @@ destroy_ssl_system(void) ...@@ -885,8 +888,11 @@ destroy_ssl_system(void)
if (pq_init_crypto_lib && ssl_open_connections == 0) if (pq_init_crypto_lib && ssl_open_connections == 0)
{ {
/* No connections left, unregister libcrypto callbacks */ /* No connections left, unregister libcrypto callbacks, if no one
* registered different ones in the meantime. */
if (CRYPTO_get_locking_callback() == pq_lockingcallback)
CRYPTO_set_locking_callback(NULL); CRYPTO_set_locking_callback(NULL);
if (CRYPTO_get_id_callback() == pq_threadidcallback)
CRYPTO_set_id_callback(NULL); CRYPTO_set_id_callback(NULL);
/* /*
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment