From: Howard Chu Date: Fri, 4 Oct 2013 09:55:34 +0000 (-0700) Subject: Fix mdb_env_set_mapsize() X-Git-Tag: OPENLDAP_REL_ENG_2_4_37~27^2~1 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=d327a36ad8c2602173da7bf2fb3b41db80950dc5;p=openldap Fix mdb_env_set_mapsize() Don't allow shrinking below minimum size for an already open env. --- 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;