From 518fdffce9c2cb392b794ce5242b16caf26b60b4 Mon Sep 17 00:00:00 2001 From: William Casarin Date: Tue, 7 Nov 2023 09:49:59 +0900 Subject: [PATCH] ndb: potential fix for a crash in some nostrdb queries --- nostrdb/nostrdb.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/nostrdb/nostrdb.c b/nostrdb/nostrdb.c index 01e0bec7..d745b832 100644 --- a/nostrdb/nostrdb.c +++ b/nostrdb/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)) {