From 5c4715aea7dc5bda704924448d2d74380f75c0b0 Mon Sep 17 00:00:00 2001 From: George Hazan Date: Fri, 7 Feb 2020 19:46:11 +0300 Subject: fixes #2205 (Unable to create new profile) --- plugins/Dbx_mdbx/src/dbcrypt.cpp | 29 ++++++++++++++++++++--------- 1 file changed, 20 insertions(+), 9 deletions(-) (limited to 'plugins/Dbx_mdbx/src/dbcrypt.cpp') diff --git a/plugins/Dbx_mdbx/src/dbcrypt.cpp b/plugins/Dbx_mdbx/src/dbcrypt.cpp index 8cdc884c6f..75a630aa72 100644 --- a/plugins/Dbx_mdbx/src/dbcrypt.cpp +++ b/plugins/Dbx_mdbx/src/dbcrypt.cpp @@ -202,11 +202,15 @@ int CDbxMDBX::InitCrypt() if (m_crypto != nullptr) return 0; - txn_ptr_ro txn(m_txn_ro); + int rc; + MDBX_val key = { DBKey_Crypto_Provider, sizeof(DBKey_Crypto_Provider) }, value; + { + txn_ptr_ro txn(m_txn_ro); + rc = mdbx_get(txn, m_dbCrypto, &key, &value); + } CRYPTO_PROVIDER *pProvider; - MDBX_val key = { DBKey_Crypto_Provider, sizeof(DBKey_Crypto_Provider) }, value; - if (mdbx_get(txn, m_dbCrypto, &key, &value) == MDBX_SUCCESS) { + if (rc == MDBX_SUCCESS) { pProvider = Crypto_GetProvider((const char*)value.iov_base); if (pProvider == nullptr) pProvider = SelectProvider(); @@ -220,7 +224,12 @@ int CDbxMDBX::InitCrypt() return 3; key.iov_len = sizeof(DBKey_Crypto_Key); key.iov_base = DBKey_Crypto_Key; - if (mdbx_get(txn, m_dbCrypto, &key, &value) == MDBX_SUCCESS && (value.iov_len == m_crypto->getKeyLength())) { + { + txn_ptr_ro txn(m_txn_ro); + rc = mdbx_get(txn, m_dbCrypto, &key, &value); + } + + if (rc == MDBX_SUCCESS && (value.iov_len == m_crypto->getKeyLength())) { if (!m_crypto->setKey((const BYTE*)value.iov_base, value.iov_len)) { CEnterPasswordDialog dlg(this); while (true) { @@ -243,11 +252,13 @@ int CDbxMDBX::InitCrypt() } key.iov_len = sizeof(DBKey_Crypto_IsEncrypted); key.iov_base = DBKey_Crypto_IsEncrypted; - - if (mdbx_get(txn, m_dbCrypto, &key, &value) == MDBX_SUCCESS) - m_bEncrypted = *(const bool*)value.iov_base; - else - m_bEncrypted = false; + { + txn_ptr_ro txn(m_txn_ro); + if (mdbx_get(txn, m_dbCrypto, &key, &value) == MDBX_SUCCESS) + m_bEncrypted = *(const bool *)value.iov_base; + else + m_bEncrypted = false; + } InitDialogs(); return 0; -- cgit v1.2.3