Issue 8401 - mdb_env_stat crashes if env is not open
Summary: mdb_env_stat crashes if env is not open
Status: VERIFIED INVALID
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: 2016-04-13 10:09 UTC by gahr@gahr.ch
Modified: 2020-03-22 22:29 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 gahr@gahr.ch 2016-04-13 10:09:20 UTC
Full_Name: Pietro Cerutti
Version: lmdb 0.9.18
OS: FreeBSD
URL: ftp://ftp.openldap.org/incoming/
Submission from: (NULL) (69.191.176.32)


mdb_env_stat crashes is the env was created but not opened. This happens because
mdb_env_stat calls mdb_env_pick_meta, which doesn't check whether the two pages
are NULL before dereferencing them.

Please note that there is no mention of the fact that the env must have been
opened before calling mdb_env_stat in the documentation [1].

The proposed patch is to check whether the environment is active before getting
the most recent page:

--- mdb.c.orig  2016-04-13 10:00:30.084676000 +0000
+"B2B mdb.c       2016-04-13 10:07:32.064085000 +0000
@@ -9432,7 +9432,7 @@
 {
        MDB_meta *meta;

-       if (env == NULL || arg == NULL)
+       if (env == NULL || !(env->me_flags & MDB_ENV_ACTIVE) || arg == NULL)
                return EINVAL;

        meta = mdb_env_pick_meta(env);

[1] http://symas.com/mdb/doc/group__mdb.html#gaf881dca452050efbd434cd16e4bae255
Comment 1 Howard Chu 2016-04-13 10:30:05 UTC
gahr@gahr.ch wrote:
> Full_Name: Pietro Cerutti
> Version: lmdb 0.9.18
> OS: FreeBSD
> URL: ftp://ftp.openldap.org/incoming/
> Submission from: (NULL) (69.191.176.32)
>
>
> mdb_env_stat crashes is the env was created but not opened. This happens because
> mdb_env_stat calls mdb_env_pick_meta, which doesn't check whether the two pages
> are NULL before dereferencing them.
>
> Please note that there is no mention of the fact that the env must have been
> opened before calling mdb_env_stat in the documentation [1].

You're not reading carefully.

http://symas.com/mdb/doc/group__mdb.html#gaad6be3d8dcd4ea01f8df436f41d158d4

"Before the handle may be used, it must be opened using mdb_env_open()."

Closing this ITS.

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