From ceac8bebf60025a4da0997a4d73de1328c04e97d Mon Sep 17 00:00:00 2001 From: Christian Mollekopf Date: Mon, 6 Mar 2017 18:13:19 +0100 Subject: Ensure we don't try to open db's that are not available to our transaction. --- common/storage_lmdb.cpp | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/common/storage_lmdb.cpp b/common/storage_lmdb.cpp index ed385ad..e49ecae 100644 --- a/common/storage_lmdb.cpp +++ b/common/storage_lmdb.cpp @@ -93,6 +93,18 @@ public: const auto dbiName = name + db; if (sDbis.contains(dbiName)) { dbi = sDbis.value(dbiName); + //sDbis can contain dbi's that are not available to this transaction. + //We use mdb_dbi_flags to check if the dbi is valid for this transaction. + uint f; + if (mdb_dbi_flags(transaction, dbi, &f) == EINVAL) { + //In readonly mode we can just ignore this. In read-write we would have tried to concurrently create a db. + if (!readOnly) { + SinkWarning() << "Tried to create database in second transaction: " << dbiName; + } + dbi = 0; + transaction = 0; + return false; + } } else { MDB_dbi flagtableDbi; if (const int rc = mdb_dbi_open(transaction, "__flagtable", readOnly ? 0 : MDB_CREATE, &flagtableDbi)) { -- cgit v1.2.3