From aec088c8af0ea5e3bf2a9921ff0c7a34b6036e6e Mon Sep 17 00:00:00 2001 From: Kevin Newton Date: Thu, 18 Jul 2024 15:46:18 -0400 Subject: [PATCH] Do not read directory --- include/prism/util/pm_string.h | 1 + src/util/pm_string.c | 7 +++++++ 2 files changed, 8 insertions(+) diff --git a/include/prism/util/pm_string.h b/include/prism/util/pm_string.h index d23792c0bad..e4a20558d36 100644 --- a/include/prism/util/pm_string.h +++ b/include/prism/util/pm_string.h @@ -9,6 +9,7 @@ #include "prism/defines.h" #include +#include #include #include #include diff --git a/src/util/pm_string.c b/src/util/pm_string.c index dfc121b6a27..e9e597113f6 100644 --- a/src/util/pm_string.c +++ b/src/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;