From dfc3020426265b343804319f8bcb380920a702b4 Mon Sep 17 00:00:00 2001 From: Leo Yuriev Date: Mon, 17 Apr 2017 19:35:36 +0300 Subject: [PATCH] mdbx: fix mdbx_canary_put(). --- mdbx.h | 2 +- src/mdbx.c | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/mdbx.h b/mdbx.h index 75688438..2af8b66f 100644 --- a/mdbx.h +++ b/mdbx.h @@ -1725,7 +1725,7 @@ typedef int MDBX_pgvisitor_func(size_t pgno, unsigned pgnumber, void *ctx, LIBMDBX_API int mdbx_env_pgwalk(MDB_txn *txn, MDBX_pgvisitor_func *visitor, void *ctx); -typedef struct mdbx_canary { size_t x, y, z, v; } mdbx_canary; +typedef struct mdbx_canary { uint64_t x, y, z, v; } mdbx_canary; LIBMDBX_API int mdbx_canary_put(MDB_txn *txn, const mdbx_canary *canary); LIBMDBX_API size_t mdbx_canary_get(MDB_txn *txn, mdbx_canary *canary); diff --git a/src/mdbx.c b/src/mdbx.c index 19424aba..eb29d3ab 100644 --- a/src/mdbx.c +++ b/src/mdbx.c @@ -9841,15 +9841,22 @@ int mdbx_canary_put(MDB_txn *txn, const mdbx_canary *canary) { if (unlikely(txn->mt_signature != MDBX_MT_SIGNATURE)) return MDBX_EBADSIGN; + if (unlikely(txn->mt_flags & MDB_TXN_BLOCKED)) + return MDB_BAD_TXN; + if (unlikely(F_ISSET(txn->mt_flags, MDB_TXN_RDONLY))) return EACCES; if (likely(canary)) { + if (txn->mt_canary.x == canary->x && txn->mt_canary.y == canary->y && + txn->mt_canary.z == canary->z && txn->mt_canary.v == canary->v) + return MDB_SUCCESS; txn->mt_canary.x = canary->x; txn->mt_canary.y = canary->y; txn->mt_canary.z = canary->z; } txn->mt_canary.v = txn->mt_txnid; + txn->mt_flags |= MDB_TXN_DIRTY; return MDB_SUCCESS; }