Skip to content

Commit

Permalink
Be more pedantic about file opens.
Browse files Browse the repository at this point in the history
  • Loading branch information
jorisvink committed Feb 2, 2025
1 parent 7c81641 commit b5a7a63
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions src/utils.c
Original file line number Diff line number Diff line change
Expand Up @@ -399,6 +399,7 @@ int
sanctum_file_open(const char *path)
{
int fd;
struct stat st;

PRECOND(path != NULL);

Expand All @@ -408,6 +409,20 @@ sanctum_file_open(const char *path)
return (-1);
}

if (fstat(fd, &st) == -1) {
sanctum_log(LOG_NOTICE,
"failed to fstat '%s': %s", path, errno_s);
(void)close(fd);
return (-1);
}

if (!S_ISREG(st.st_mode)) {
sanctum_log(LOG_NOTICE,
"'%s': not a regular file", path);
(void)close(fd);
return (-1);
}

return (fd);
}

Expand Down

0 comments on commit b5a7a63

Please sign in to comment.