[PRISM] Ensure not opening directories

This commit is contained in:
Kevin Newton 2024-07-18 11:39:41 -04:00
parent 76ea5cde2a
commit 8e5ac5a87d
Notes: git 2024-07-18 17:03:44 +00:00
2 changed files with 8 additions and 0 deletions

View File

@ -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;

View File

@ -9,6 +9,7 @@
#include "prism/defines.h"
#include <assert.h>
#include <errno.h>
#include <stdbool.h>
#include <stddef.h>
#include <stdlib.h>