net/Ssl.cpp | 39 ++++++++++++++++++++++----------------- net/Ssl.hpp | 3 ++- 2 files changed, 24 insertions(+), 18 deletions(-)
New commits: commit 762ba09370800a38c5bf48b6950188a31a9d0cdf Author: Ashod Nakashian <ashod.nakash...@collabora.co.uk> Date: Mon Apr 3 21:06:51 2017 -0400 wsd: fix SSL initialization/uninitialization error Valgrind found a number of erroneous data access during the construction and destruction of SslContext. Change-Id: Ie5072798a3660ed8acc707ba32ac196fa2d0f8af Reviewed-on: https://gerrit.libreoffice.org/36055 Reviewed-by: Ashod Nakashian <ashnak...@gmail.com> Tested-by: Ashod Nakashian <ashnak...@gmail.com> diff --git a/net/Ssl.cpp b/net/Ssl.cpp index d6d13575..e350257c 100644 --- a/net/Ssl.cpp +++ b/net/Ssl.cpp @@ -26,31 +26,30 @@ extern "C" }; } -std::unique_ptr<SslContext> SslContext::Instance; -std::vector<std::unique_ptr<std::mutex>> SslContext::Mutexes; +std::unique_ptr<SslContext> SslContext::Instance(nullptr); SslContext::SslContext(const std::string& certFilePath, const std::string& keyFilePath, const std::string& caFilePath) : _ctx(nullptr) { -#if OPENSSL_VERSION_NUMBER >= 0x0907000L - OPENSSL_config(nullptr); -#endif - - SSL_library_init(); - SSL_load_error_strings(); - OpenSSL_add_all_algorithms(); - const std::vector<char> rand = Util::rng::getBytes(512); RAND_seed(&rand[0], rand.size()); // Initialize multi-threading support. for (int x = 0; x < CRYPTO_num_locks(); ++x) { - Mutexes.emplace_back(new std::mutex); + _mutexes.emplace_back(new std::mutex); } +#if OPENSSL_VERSION_NUMBER >= 0x0907000L + OPENSSL_config(nullptr); +#endif + + SSL_library_init(); + SSL_load_error_strings(); + OpenSSL_add_all_algorithms(); + CRYPTO_set_locking_callback(&SslContext::lock); CRYPTO_set_id_callback(&SslContext::id); CRYPTO_set_dynlock_create_callback(&SslContext::dynlockCreate); @@ -130,6 +129,8 @@ SslContext::~SslContext() CRYPTO_set_id_callback(0); CONF_modules_free(); + + _mutexes.clear(); } void SslContext::uninitialize() @@ -140,13 +141,17 @@ void SslContext::uninitialize() void SslContext::lock(int mode, int n, const char* /*file*/, int /*line*/) { - if (mode & CRYPTO_LOCK) - { - Mutexes[n]->lock(); - } - else + assert(n < CRYPTO_num_locks()); + if (Instance) { - Mutexes[n]->unlock(); + if (mode & CRYPTO_LOCK) + { + Instance->_mutexes[n]->lock(); + } + else + { + Instance->_mutexes[n]->unlock(); + } } } diff --git a/net/Ssl.hpp b/net/Ssl.hpp index 7c13474a..b6fc0427 100644 --- a/net/Ssl.hpp +++ b/net/Ssl.hpp @@ -65,7 +65,8 @@ private: private: static std::unique_ptr<SslContext> Instance; - static std::vector<std::unique_ptr<std::mutex>> Mutexes; + + std::vector<std::unique_ptr<std::mutex>> _mutexes; SSL_CTX* _ctx; }; _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits