From 6ffffe0d5f155aa5d212df92d97c62e2de71baa3 Mon Sep 17 00:00:00 2001 From: Vsevolod Stakhov Date: Sun, 15 Jan 2017 17:38:25 +0000 Subject: [PATCH] [Minor] Check mmap return code --- src/controller.c | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/src/controller.c b/src/controller.c index 78445c606..25eb54db8 100644 --- a/src/controller.c +++ b/src/controller.c @@ -345,13 +345,24 @@ rspamd_check_encrypted_password (struct rspamd_controller_worker_ctx *ctx, if (cache->len == 0) { /* Mmap region */ +#ifdef MAP_NOCORE + m = mmap (NULL, password->len, PROT_WRITE, + MAP_PRIVATE | MAP_ANON | MAP_NOCORE, -1, 0); +#else m = mmap (NULL, password->len, PROT_WRITE, MAP_PRIVATE | MAP_ANON, -1, 0); - memcpy (m, password->begin, password->len); - (void)mprotect (m, password->len, PROT_READ); - (void)mlock (m, password->len); - cache->begin = m; - cache->len = password->len; +#endif + if (m != MAP_FAILED) { + memcpy (m, password->begin, password->len); + (void)mprotect (m, password->len, PROT_READ); + (void)mlock (m, password->len); + cache->begin = m; + cache->len = password->len; + } + else { + msg_err_ctx ("cannot store cached password, mmap failed: %s", + strerror (errno)); + } } } -- 2.39.5