Skip to content

Commit

Permalink
ndb: potential fix for a crash in some nostrdb queries
Browse files Browse the repository at this point in the history
  • Loading branch information
jb55 committed Nov 13, 2023
1 parent 289e051 commit 518fdff
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions nostrdb/nostrdb.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)) {
Expand Down

0 comments on commit 518fdff

Please sign in to comment.