summaryrefslogtreecommitdiff
path: root/prism/util/pm_string.c
diff options
context:
space:
mode:
authorKevin Newton <[email protected]>2024-07-18 11:39:41 -0400
committerKevin Newton <[email protected]>2024-07-18 13:03:25 -0400
commit8e5ac5a87d8c10f4e94bb71ece3d83c78a53876e (patch)
tree1bd764b85169386b252ad8d71cbe921de5ccbfb3 /prism/util/pm_string.c
parent76ea5cde2a0f4834a5228104249b6b3346ddfc94 (diff)
[PRISM] Ensure not opening directories
Notes
Notes: Merged: https://github.com/ruby/ruby/pull/11196
Diffstat (limited to 'prism/util/pm_string.c')
-rw-r--r--prism/util/pm_string.c7
1 files changed, 7 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;