aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorPeter Eisentraut <peter_e@gmx.net>2015-04-09 20:45:34 -0400
committerPeter Eisentraut <peter_e@gmx.net>2015-04-09 20:45:34 -0400
commit8a0d34e4e45d44884ebdc6cb9d9ad9c3891d8505 (patch)
tree579c67902848faba47afd2b1c3bc040e9ede8135 /src
parenta6f3c1f1e2c365dd7dee1e944389d62bf62aa22e (diff)
downloadpostgresql-8a0d34e4e45d44884ebdc6cb9d9ad9c3891d8505.tar.gz
postgresql-8a0d34e4e45d44884ebdc6cb9d9ad9c3891d8505.zip
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>
Diffstat (limited to 'src')
-rw-r--r--src/interfaces/libpq/fe-secure-openssl.c18
1 files changed, 12 insertions, 6 deletions
diff --git a/src/interfaces/libpq/fe-secure-openssl.c b/src/interfaces/libpq/fe-secure-openssl.c
index 1b9f3a4a7b0..fee154904a6 100644
--- a/src/interfaces/libpq/fe-secure-openssl.c
+++ b/src/interfaces/libpq/fe-secure-openssl.c
@@ -806,9 +806,12 @@ pgtls_init(PGconn *conn)
if (ssl_open_connections++ == 0)
{
- /* These are only required for threaded libcrypto applications */
- CRYPTO_set_id_callback(pq_threadidcallback);
- CRYPTO_set_locking_callback(pq_lockingcallback);
+ /* 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);
+ if (CRYPTO_get_locking_callback() == NULL)
+ CRYPTO_set_locking_callback(pq_lockingcallback);
}
}
#endif /* ENABLE_THREAD_SAFETY */
@@ -885,9 +888,12 @@ destroy_ssl_system(void)
if (pq_init_crypto_lib && ssl_open_connections == 0)
{
- /* No connections left, unregister libcrypto callbacks */
- CRYPTO_set_locking_callback(NULL);
- CRYPTO_set_id_callback(NULL);
+ /* 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);
+ 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