Issue 8760 - LMDB: seg fault on opening a new database
Summary: LMDB: seg fault on opening a new database
Status: VERIFIED FIXED
Alias: None
Product: LMDB
Classification: Unclassified
Component: liblmdb (show other issues)
Version: unspecified
Hardware: All All
: --- normal
Target Milestone: ---
Assignee: OpenLDAP project
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2017-10-23 03:41 UTC by github@nicwatson.org
Modified: 2020-03-12 15:56 UTC (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this issue.
Description github@nicwatson.org 2017-10-23 03:41:34 UTC
Full_Name: Nic Watson
Version: LMDB 0.9.21
OS: Ubuntu 16.04.3 LTS
URL: https://gist.github.com/jnwatson/86b43b0515fe552a087d741d4ab43922
Submission from: (NULL) (108.56.136.246)


See the URL for the minimal C program to reproduce the crash and the gdb
backtrace.

LMDB will seg fault in mdb_dbi_open when creating a new database if the
environment was opened read-only.

This was found trying to update py-lmdb from 0.9.19 to 0.9.21.  Two unit tests
crashed that didn't crash before, both on the same line in mdb.c.  The program
in the URL is derived from one of the tests.

The change was introduced in commit e8e82933.  In mdb.c, line 9772
(https://github.com/LMDB/lmdb/blob/LMDB_0.9.21/libraries/liblmdb/mdb.c#L9772)
the mdb_cursor_put was wrapped in the macro WITH_CURSOR_TRACKING.  In that
macro, the variable tp is assigned the address of an entry of the passed-in
cursor's transaction's mt_cursors array.  However, mt_cursors isn't initialized
in this case.
Comment 1 Howard Chu 2017-10-26 17:12:46 UTC
github@nicwatson.org wrote:
> Full_Name: Nic Watson
> Version: LMDB 0.9.21
> OS: Ubuntu 16.04.3 LTS
> URL: https://gist.github.com/jnwatson/86b43b0515fe552a087d741d4ab43922
> Submission from: (NULL) (108.56.136.246)
> 
> 
> See the URL for the minimal C program to reproduce the crash and the gdb
> backtrace.
> 
> LMDB will seg fault in mdb_dbi_open when creating a new database if the
> environment was opened read-only.

Thanks for the report, but this doesn't seem like a bug. Trying to create 
something when the environment was opened read-only is clearly a misuse of the 
API, and SEGVs are expected when the API is misused.

-- 
   -- Howard Chu
   CTO, Symas Corp.           http://www.symas.com
   Director, Highland Sun     http://highlandsun.com/hyc/
   Chief Architect, OpenLDAP  http://www.openldap.org/project/

Comment 2 Howard Chu 2017-10-26 18:11:46 UTC
changed notes
changed state Open to Test
moved from Incoming to Software Bugs
Comment 3 Quanah Gibson-Mount 2018-02-09 18:47:55 UTC
changed notes
changed state Test to Release
Comment 4 OpenLDAP project 2018-03-22 19:26:33 UTC
regressed in 0.9.19, fixed in mdb.master
fixed in mdb.RE09 (0.9.22/OL 2.4.46)
Comment 5 Quanah Gibson-Mount 2018-03-22 19:26:33 UTC
changed notes
changed state Release to Closed