aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ks_mmap.c10
1 files changed, 9 insertions, 1 deletions
diff --git a/ks_mmap.c b/ks_mmap.c
index 3ff06a3..7fef400 100644
--- a/ks_mmap.c
+++ b/ks_mmap.c
@@ -38,6 +38,7 @@
#include <sys/mman.h>
#include <string.h>
#include <sys/errno.h>
+#include <unistd.h>
#include "hal.h"
#include "hal_internal.h"
@@ -46,6 +47,10 @@
#define HAL_KS_MMAP_FILE ".cryptech_hal_keystore"
#endif
+#ifndef MAP_FILE
+#define MAP_FILE 0
+#endif
+
static hal_ks_keydb_t *db;
const hal_ks_keydb_t *hal_ks_get_keydb(void)
@@ -56,13 +61,16 @@ const hal_ks_keydb_t *hal_ks_get_keydb(void)
const char * const env = getenv("CRYPTECH_KEYSTORE");
const char * const home = getenv("HOME");
const char * const base = HAL_KS_MMAP_FILE;
- const unsigned pagemask = getpagesize() - 1;
+ const long pagemask = sysconf(_SC_PAGESIZE) - 1;
const size_t len = (sizeof(hal_ks_keydb_t) + pagemask) & ~pagemask;
char fn_[strlen(base) + (home == NULL ? 0 : strlen(home)) + 2];
const char *fn = fn_;
int fd;
+ if (pagemask < 0)
+ return NULL;
+
if (env != NULL)
fn = env;
else if (home == NULL)