From 6d1e109c82bbf77cfd90115924ed08932394cb1b Mon Sep 17 00:00:00 2001 From: iceman1001 Date: Tue, 8 Oct 2019 16:11:01 +0200 Subject: [PATCH] filechecks.. could fail stat call and directory could be symlinked --- client/fileutils.c | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/client/fileutils.c b/client/fileutils.c index 9c226dd3b..57aa939a7 100644 --- a/client/fileutils.c +++ b/client/fileutils.c @@ -77,13 +77,15 @@ int fileExists(const char *filename) { bool is_regular_file(const char *filename) { #ifdef _WIN32 struct _stat st; - _stat(filename, &st); - return S_ISREG(st.st_mode) != 0; + if (_stat(filename, &st) == -1) + return false; #else struct stat st; - stat(filename, &st); - return S_ISREG(st.st_mode) != 0; +// stat(filename, &st); + if (lstat(filename, &st) == -1) + return false; #endif + return S_ISREG(st.st_mode) != 0; } /** * @brief checks if path is directory. @@ -93,13 +95,15 @@ bool is_regular_file(const char *filename) { bool is_directory(const char *filename) { #ifdef _WIN32 struct _stat st; - _stat(filename, &st); - return S_ISDIR(st.st_mode) != 0; + if (_stat(filename, &st) == -1) + return false; #else struct stat st; - stat(filename, &st); - return S_ISDIR(st.st_mode) != 0; +// stat(filename, &st); + if (lstat(filename, &st) == -1) + return false; #endif + return S_ISDIR(st.st_mode) != 0; }