summary refs log tree commit diff
path: root/src/Cache.cpp
diff options
context:
space:
mode:
authorNicolas Werner <nicolas.werner@hotmail.de>2021-03-12 17:13:56 +0100
committerNicolas Werner <nicolas.werner@hotmail.de>2021-03-12 17:14:18 +0100
commit6ad4065de4e3070a875a8784aaf2a522901c04a6 (patch)
tree08cbbf27e10f0f6d42ce3ed194aa897fa57478c6 /src/Cache.cpp
parentBump mtxclient version (diff)
downloadnheko-6ad4065de4e3070a875a8784aaf2a522901c04a6.tar.xz
Fix a few db access crashes
Diffstat (limited to 'src/Cache.cpp')
-rw-r--r--src/Cache.cpp6
1 files changed, 6 insertions, 0 deletions
diff --git a/src/Cache.cpp b/src/Cache.cpp
index 87dbfb8c..0817a2d1 100644
--- a/src/Cache.cpp
+++ b/src/Cache.cpp
@@ -787,6 +787,9 @@ Cache::isInitialized()
 std::string
 Cache::nextBatchToken()
 {
+        if (!env_.handle())
+                throw lmdb::error("Env already closed", MDB_INVALID);
+
         auto txn = lmdb::txn::begin(env_, nullptr, MDB_RDONLY);
         std::string_view token;
 
@@ -1816,6 +1819,9 @@ Cache::getTimelineRange(const std::string &room_id)
 std::optional<uint64_t>
 Cache::getTimelineIndex(const std::string &room_id, std::string_view event_id)
 {
+        if (event_id.empty() || room_id.empty())
+                return {};
+
         auto txn = lmdb::txn::begin(env_, nullptr, MDB_RDONLY);
 
         lmdb::dbi orderDb;