hermes

HTTP GET/HEAD-only web server for static content.
git clone git://git.francescosaccone.com/hermes
Log | Files | Refs | README | LICENSE

commit 778b1b127b18d1cc76d6cbafef02c402e8ef3938
parent f862118b2d185e2a51500b2800d68ab1fed859fc
Author: Francesco Saccone <francesco@francescosaccone.com>
Date:   Tue,  1 Apr 2025 11:52:51 +0200

fix: also check if path is a regular file in is_file_readable

Signed-off-by: Francesco Saccone <francesco@francescosaccone.com>

Diffstat:
Mfile.c | 17++++++++++++++++-
1 file changed, 16 insertions(+), 1 deletion(-)

diff --git a/file.c b/file.c @@ -3,6 +3,7 @@ #include <stdio.h> #include <stdlib.h> #include <string.h> +#include <sys/stat.h> #include <unistd.h> char * @@ -23,7 +24,21 @@ get_mime_type_from_extension(char *extension) { int is_file_readable(char *path) { - return (access(path, R_OK) == 0); + struct stat file_stat; + + if (stat(path, &file_stat) != 0) { + return 0; + } + + if (!S_ISREG(file_stat.st_mode)) { + return 0; + } + + if (access(path, R_OK) != 0) { + return 0; + }; + + return 1; } char *