mirror of
https://github.com/LibreOffice/online.git
synced 2025-08-16 17:42:05 +00:00
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 <ashnakash@gmail.com> Tested-by: Ashod Nakashian <ashnakash@gmail.com>
This commit is contained in:

committed by
Ashod Nakashian

parent
66a76f644b
commit
762ba09370
39
net/Ssl.cpp
39
net/Ssl.cpp
@ -26,14 +26,22 @@ 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)
|
||||
{
|
||||
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);
|
||||
}
|
||||
|
||||
#if OPENSSL_VERSION_NUMBER >= 0x0907000L
|
||||
OPENSSL_config(nullptr);
|
||||
#endif
|
||||
@ -42,15 +50,6 @@ SslContext::SslContext(const std::string& certFilePath,
|
||||
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);
|
||||
}
|
||||
|
||||
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)
|
||||
assert(n < CRYPTO_num_locks());
|
||||
if (Instance)
|
||||
{
|
||||
Mutexes[n]->lock();
|
||||
}
|
||||
else
|
||||
{
|
||||
Mutexes[n]->unlock();
|
||||
if (mode & CRYPTO_LOCK)
|
||||
{
|
||||
Instance->_mutexes[n]->lock();
|
||||
}
|
||||
else
|
||||
{
|
||||
Instance->_mutexes[n]->unlock();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
};
|
||||
|
Reference in New Issue
Block a user