Skip to content

Commit

Permalink
Do not read directory
Browse files Browse the repository at this point in the history
  • Loading branch information
kddnewton committed Jul 18, 2024
1 parent f514987 commit aec088c
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
1 change: 1 addition & 0 deletions include/prism/util/pm_string.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include "prism/defines.h"

#include <assert.h>
#include <errno.h>
#include <stdbool.h>
#include <stddef.h>
#include <stdlib.h>
Expand Down
7 changes: 7 additions & 0 deletions src/util/pm_string.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit aec088c

Please sign in to comment.