From 061fe51e8c8830c4e18bc97eb09bdbc3d4d78e47 Mon Sep 17 00:00:00 2001 From: Hallvard Furuseth Date: Sun, 19 Jul 2015 21:44:02 +0200 Subject: [PATCH] lmdb: ITS#7377 Catch mdb_put() to blocked/read-only txns. ...early enough that txn state is left unchanged. Change-Id: Ia475660f339f7b741eaaa126978f8419a19b67a0 --- mdb.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/mdb.c b/mdb.c index ae50dfbe..bdb322d5 100644 --- a/mdb.c +++ b/mdb.c @@ -7962,10 +7962,10 @@ int mdb_del(MDB_txn *txn, MDB_dbi dbi, MDB_val *key, MDB_val *data) { - if (!key || !TXN_DBI_EXIST(txn, dbi, DB_USRVALID)) + if (unlikely(!key || !TXN_DBI_EXIST(txn, dbi, DB_USRVALID))) return EINVAL; - if (txn->mt_flags & (MDB_TXN_RDONLY|MDB_TXN_BLOCKED)) + if (unlikely(txn->mt_flags & (MDB_TXN_RDONLY|MDB_TXN_BLOCKED))) return (txn->mt_flags & MDB_TXN_RDONLY) ? EACCES : MDB_BAD_TXN; if (!F_ISSET(txn->mt_dbs[dbi].md_flags, MDB_DUPSORT)) { @@ -8435,6 +8435,9 @@ mdb_put(MDB_txn *txn, MDB_dbi dbi, if (flags & ~(MDB_NOOVERWRITE|MDB_NODUPDATA|MDB_RESERVE|MDB_APPEND|MDB_APPENDDUP)) return EINVAL; + if (txn->mt_flags & (MDB_TXN_RDONLY|MDB_TXN_BLOCKED)) + return (txn->mt_flags & MDB_TXN_RDONLY) ? EACCES : MDB_BAD_TXN; + mdb_cursor_init(&mc, txn, dbi, &mx); return mdb_cursor_put(&mc, key, data, flags); }