aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authordec05eba <dec05eba@protonmail.com>2022-02-11 17:42:20 +0100
committerdec05eba <dec05eba@protonmail.com>2022-02-11 17:42:20 +0100
commit15d635f8e7d4c5f5e12f759a62d1b48ef2e67f70 (patch)
treebc244331adb665f8252b1b9977ec28c21dc59513 /src
parent0f453cd704cbd7e67c5febb0bbaaff3c029d97d2 (diff)
Check if file to read is really a file
Diffstat (limited to 'src')
-rw-r--r--src/fileutils.c7
1 files changed, 7 insertions, 0 deletions
diff --git a/src/fileutils.c b/src/fileutils.c
index 7f85ba8..b219c07 100644
--- a/src/fileutils.c
+++ b/src/fileutils.c
@@ -29,6 +29,13 @@ int file_get_content(const char *filepath, char **data, long *size) {
return -1;
}
+ int fd = fileno(file);
+ struct stat s;
+ if(fstat(fd, &s) == -1 || !S_ISREG(s.st_mode)) {
+ fclose(file);
+ return -1;
+ }
+
fseek(file, 0, SEEK_END);
*size = ftell(file);
if(*size == -1) {