diff --git a/prism/util/pm_string.c b/prism/util/pm_string.c index dfc121b6a2..e9e597113f 100644 --- a/prism/util/pm_string.c +++ b/prism/util/pm_string.c @@ -116,6 +116,13 @@ pm_string_mapped_init(pm_string_t *string, const char *filepath) { return false; } + // Ensure it is a file and not a directory + if (S_ISDIR(sb.st_mode)) { + errno = EISDIR; + close(fd); + return false; + } + // mmap the file descriptor to virtually get the contents size_t size = (size_t) sb.st_size; uint8_t *source = NULL; diff --git a/prism/util/pm_string.h b/prism/util/pm_string.h index d23792c0ba..e4a20558d3 100644 --- a/prism/util/pm_string.h +++ b/prism/util/pm_string.h @@ -9,6 +9,7 @@ #include "prism/defines.h" #include +#include #include #include #include