diff options
-rw-r--r-- | ks_mmap.c | 10 |
1 files changed, 9 insertions, 1 deletions
@@ -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) |