https://bugs.openldap.org/show_bug.cgi?id=9949
Issue ID: 9949 Summary: MDB_RDONLY txn segfaults on newly created database Product: LMDB Version: unspecified Hardware: All OS: All Status: UNCONFIRMED Keywords: needs_review Severity: normal Priority: --- Component: liblmdb Assignee: bugs@openldap.org Reporter: jeffrey.reynolds@ticketmaster.com Target Milestone: ---
The very simple code will cause a seg fault.
``` auto env = create_env("env_name"); // creates the environment. not included here because this part is in rust // it will open or create the database. i don't think the problem lies in here.
MDB_txn* txn{}; mdb_txn_begin(*env, nullptr, MDB_RDONLY, &txn);
MDB_dbi dbi{}; mdb_dbi_open(txn, "db_name", MDB_CREATE, &dbi); ```
This segfaults on `liblmdb/mdb.c:11050`. Specifically `tracked->mc_next = *tp;` However, the problem isn't in mdb_dbi_open, it is failing because mt_cursors is never initialized.
A small change ` mdb_txn_begin(*env, nullptr, 0, &txn);` and mt_cursors will be initialized with the default env->me_txn0, that has a properly initialized mt_cursors, per this line `liblmdb/mdb.c:5581`, `txn->mt_cursors = (MDB_cursor **)(txn->mt_dbs + env->me_maxdbs);`
for the MDB_RDONLY transaction, it looks like it will initialize mt_cursors _if_ it happens to have a parent, `liblmdb/mdb.c:3178`, but otherwise it leaves it uninitialized.
Is this a bug, or do have i have to a parent to start a readonly transaction on a new database?
https://bugs.openldap.org/show_bug.cgi?id=9949
--- Comment #1 from Howard Chu hyc@openldap.org --- Please specify the version you're using.
https://bugs.openldap.org/show_bug.cgi?id=9949
--- Comment #2 from Howard Chu hyc@openldap.org --- Note that you can't create a DB in a readonly txn.
### E(mdb_env_create(&env)); E(mdb_env_set_maxdbs(env, 4)); E(mdb_env_open(env, "./testdb", MDB_FIXEDMAP /*|MDB_NOSYNC*/, 0664));
E(mdb_txn_begin(env, NULL, MDB_RDONLY, &txn)); E(mdb_dbi_open(txn, "db_name", MDB_CREATE, &dbi)); ### (gdb) br main Breakpoint 1 at 0x52d5: file 9949.c, line 25. (gdb) r Starting program: /home/hyc/OD/mdb/libraries/liblmdb/9949 [Thread debugging using libthread_db enabled] Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".
Breakpoint 1, main (argc=1, argv=0x7fffffffe5d8) at 9949.c:25 25 { (gdb) n 26 int i = 0, j = 0, rc; (gdb) 36 char sval[32] = ""; (gdb) 38 E(mdb_env_create(&env)); (gdb) 39 E(mdb_env_set_maxdbs(env, 4)); (gdb) 40 E(mdb_env_open(env, "./testdb", MDB_FIXEDMAP /*|MDB_NOSYNC*/, 0664)); (gdb) 42 E(mdb_txn_begin(env, NULL, MDB_RDONLY, &txn)); (gdb) 43 E(mdb_dbi_open(txn, "db_name", MDB_CREATE, &dbi)); (gdb) 9949.c:43: mdb_dbi_open(txn, "db_name", MDB_CREATE, &dbi): Permission denied
Program received signal SIGABRT, Aborted. 0x00007ffff7e11a7c in pthread_kill () from /lib/x86_64-linux-gnu/libc.so.6 (gdb)
https://bugs.openldap.org/show_bug.cgi?id=9949
--- Comment #3 from Jeffrey Reynolds jeffrey.reynolds@ticketmaster.com --- I'm not certain of the exact version since it was integrated into our source repo instead of being added as a external git repo, and the version wasn't mentioned, and the person who did it is no longer around,
but it was added on 5/11/18, i would expect it would have been 0.9.20 from looking at the repo history...
*Re: comment 2*
I see... So if i'm following, the database isn't actually created until the first transaction is opened against it, which can't be done if its a readonly transaction?
https://bugs.openldap.org/show_bug.cgi?id=9949
Howard Chu hyc@openldap.org changed:
What |Removed |Added ---------------------------------------------------------------------------- Resolution|--- |INVALID Status|UNCONFIRMED |RESOLVED
--- Comment #4 from Howard Chu hyc@openldap.org --- (In reply to Jeffrey Reynolds from comment #3)
I'm not certain of the exact version since it was integrated into our source repo instead of being added as a external git repo, and the version wasn't mentioned, and the person who did it is no longer around,
but it was added on 5/11/18, i would expect it would have been 0.9.20 from looking at the repo history...
None of the line numbers you quote match any known version of LMDB. In particular, 0.9.0 mdb.c has only 10263 lines and you referred to a mdb.c:11050. Sounds like you're using a locally customized version, so you're on your own.
*Re: comment 2*
I see... So if i'm following, the database isn't actually created until the first transaction is opened against it, which can't be done if its a readonly transaction?
Creating a DB requires a write operation, to record the DB's existence. So of course you can't do that in a readonly transaction.
No LMDB bug here, closing this ITS.
https://bugs.openldap.org/show_bug.cgi?id=9949
Quanah Gibson-Mount quanah@openldap.org changed:
What |Removed |Added ---------------------------------------------------------------------------- Status|RESOLVED |VERIFIED Keywords|needs_review |