1
0
mirror of https://github.com/postgres/postgres.git synced 2025-06-26 12:21:12 +03:00

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>
This commit is contained in:
Peter Eisentraut
2015-04-09 20:45:34 -04:00
parent a6f3c1f1e2
commit 8a0d34e4e4

View File

@ -806,9 +806,12 @@ 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
CRYPTO_set_id_callback(pq_threadidcallback); * make sure we don't stomp on them if they're already set. */
CRYPTO_set_locking_callback(pq_lockingcallback); if (CRYPTO_get_id_callback() == NULL)
CRYPTO_set_id_callback(pq_threadidcallback);
if (CRYPTO_get_locking_callback() == NULL)
CRYPTO_set_locking_callback(pq_lockingcallback);
} }
} }
#endif /* ENABLE_THREAD_SAFETY */ #endif /* ENABLE_THREAD_SAFETY */
@ -885,9 +888,12 @@ 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
CRYPTO_set_locking_callback(NULL); * registered different ones in the meantime. */
CRYPTO_set_id_callback(NULL); if (CRYPTO_get_locking_callback() == pq_lockingcallback)
CRYPTO_set_locking_callback(NULL);
if (CRYPTO_get_id_callback() == pq_threadidcallback)
CRYPTO_set_id_callback(NULL);
/* /*
* We don't free the lock array or the SSL_context. If we get another * We don't free the lock array or the SSL_context. If we get another