From d327a36ad8c2602173da7bf2fb3b41db80950dc5 Mon Sep 17 00:00:00 2001 From: Howard Chu Date: Fri, 4 Oct 2013 02:55:34 -0700 Subject: [PATCH] Fix mdb_env_set_mapsize() Don't allow shrinking below minimum size for an already open env. --- libraries/liblmdb/mdb.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/libraries/liblmdb/mdb.c b/libraries/liblmdb/mdb.c index 0aae740614..ddde69d0b0 100644 --- a/libraries/liblmdb/mdb.c +++ b/libraries/liblmdb/mdb.c @@ -3319,6 +3319,14 @@ mdb_env_set_mapsize(MDB_env *env, size_t size) return EINVAL; if (!size) size = env->me_metas[mdb_env_pick_meta(env)]->mm_mapsize; + else if (size < env->me_mapsize) { + /* If the configured size is smaller, make sure it's + * still big enough. Silently round up to minimum if not. + */ + size_t minsize = (env->me_metas[mdb_env_pick_meta(env)]->mm_last_pg + 1) * env->me_psize; + if (size < minsize) + size = minsize; + } munmap(env->me_map, env->me_mapsize); env->me_mapsize = size; old = (env->me_flags & MDB_FIXEDMAP) ? env->me_map : NULL; -- 2.39.5