diff options
author | Kevin Newton <[email protected]> | 2024-07-18 11:39:41 -0400 |
---|---|---|
committer | Kevin Newton <[email protected]> | 2024-07-18 13:03:25 -0400 |
commit | 8e5ac5a87d8c10f4e94bb71ece3d83c78a53876e (patch) | |
tree | 1bd764b85169386b252ad8d71cbe921de5ccbfb3 | |
parent | 76ea5cde2a0f4834a5228104249b6b3346ddfc94 (diff) |
[PRISM] Ensure not opening directories
Notes
Notes:
Merged: https://github.com/ruby/ruby/pull/11196
-rw-r--r-- | prism/util/pm_string.c | 7 | ||||
-rw-r--r-- | prism/util/pm_string.h | 1 |
2 files changed, 8 insertions, 0 deletions
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 <assert.h> +#include <errno.h> #include <stdbool.h> #include <stddef.h> #include <stdlib.h> |