commit 518fdffce9c2cb392b794ce5242b16caf26b60b4
parent 289e051202459514d5b2489b94bee5f03454ad49
Author: William Casarin <jb55@jb55.com>
Date: Tue, 7 Nov 2023 09:49:59 +0900
ndb: potential fix for a crash in some nostrdb queries
Diffstat:
1 file changed, 5 insertions(+), 2 deletions(-)
diff --git 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)) {