From bd5d092a2b0fe64d5d9bd97b51fac3906e9701e0 Mon Sep 17 00:00:00 2001 From: Leo Yuriev Date: Sun, 28 May 2017 18:49:05 +0300 Subject: [PATCH] mdbx: check system pagesize (paranoia). Change-Id: I596c686a996f7d1521789f22900022c4da629e1b --- src/mdbx.c | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/src/mdbx.c b/src/mdbx.c index d0e4d65f..94202a87 100644 --- a/src/mdbx.c +++ b/src/mdbx.c @@ -3804,14 +3804,25 @@ int __cold mdbx_env_create(MDBX_env **penv) { env->me_fd = INVALID_HANDLE_VALUE; env->me_lfd = INVALID_HANDLE_VALUE; env->me_pid = mdbx_getpid(); - mdbx_env_setup_limits(env, env->me_os_psize = mdbx_syspagesize()); - if (!is_power2(env->me_os_psize)) - return MDBX_INCOMPATIBLE; + + int rc; + env->me_os_psize = mdbx_syspagesize(); + if (!is_power2(env->me_os_psize) || env->me_os_psize < MIN_PAGESIZE) { + mdbx_error("unsuitable system pageize %u", env->me_os_psize); + rc = MDBX_INCOMPATIBLE; + goto bailout; + } + mdbx_env_setup_limits(env, env->me_os_psize); + VALGRIND_CREATE_MEMPOOL(env, 0, 0); env->me_signature = MDBX_ME_SIGNATURE; - *penv = env; return MDBX_SUCCESS; + +bailout: + free(env); + *penv = nullptr; + return rc; } static int __cold mdbx_env_map(MDBX_env *env, void *addr, size_t usedsize) {