commit 6490a63b54afa20a86b7bb52580c4718e9459d59
parent 201ab6fa16b5ec2445f64e29b76d0e4e94d6a5f1
Author: William Casarin <jb55@jb55.com>
Date: Sat, 4 Nov 2023 11:57:20 +0900
ndb: fix potential crash in some tsid queries
Changelog-Fixed: Fix potential crash when opening multiple cursors
Diffstat:
1 file changed, 5 insertions(+), 2 deletions(-)
diff --git a/nostrdb.c b/nostrdb.c
@@ -678,7 +678,7 @@ int ndb_get_tsid(struct ndb_txn *txn, enum ndb_dbs db, const unsigned char *id,
{
MDB_val k, v;
MDB_cursor *cur;
- int success = 0;
+ int success = 0, rc;
struct ndb_tsid tsid;
// position at the most recent
@@ -687,7 +687,10 @@ int ndb_get_tsid(struct ndb_txn *txn, enum ndb_dbs db, const unsigned char *id,
k.mv_data = &tsid;
k.mv_size = sizeof(tsid);
- mdb_cursor_open(txn->mdb_txn, txn->lmdb->dbs[db], &cur);
+ if ((rc = mdb_cursor_open(txn->mdb_txn, txn->lmdb->dbs[db], &cur))) {
+ ndb_debug("ndb_get_tsid: failed to open cursor: '%s'\n", mdb_errstr(rc));
+ return 0;
+ }
// Position cursor at the next key greater than or equal to the specified key
if (mdb_cursor_get(cur, &k, &v, MDB_SET_RANGE)) {