From 3c659c2737b26d8ee28c727b277325852df8dd09 Mon Sep 17 00:00:00 2001 From: Andreas Stöckel Date: Wed, 21 Jan 2015 01:24:37 +0100 Subject: Do only perform relative file lookups if a relative path is given (to allow users to include files without accidently including a global resource) --- src/plugins/filesystem/FileLocator.cpp | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'src/plugins/filesystem/FileLocator.cpp') diff --git a/src/plugins/filesystem/FileLocator.cpp b/src/plugins/filesystem/FileLocator.cpp index 467363b..af5244c 100644 --- a/src/plugins/filesystem/FileLocator.cpp +++ b/src/plugins/filesystem/FileLocator.cpp @@ -143,6 +143,11 @@ bool FileLocator::doLocate(Resource &resource, const std::string &path, } } + // If the path starts with "./" only perform relative lookups! + if (path.substr(0, 2) == "./") { + return false; + } + // Otherwise look in the search paths, search backwards, last defined search // paths have a higher precedence auto it = searchPaths.find(type); -- cgit v1.2.3 From b3ebc84c8dfa7379a3977ed7305fd7cf7fdd8ee7 Mon Sep 17 00:00:00 2001 From: Andreas Stöckel Date: Thu, 22 Jan 2015 02:43:13 +0100 Subject: Improved FileLocator --- src/plugins/filesystem/FileLocator.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'src/plugins/filesystem/FileLocator.cpp') diff --git a/src/plugins/filesystem/FileLocator.cpp b/src/plugins/filesystem/FileLocator.cpp index af5244c..6804c6d 100644 --- a/src/plugins/filesystem/FileLocator.cpp +++ b/src/plugins/filesystem/FileLocator.cpp @@ -131,7 +131,7 @@ bool FileLocator::doLocate(Resource &resource, const std::string &path, base /= path; // If we already found a fitting resource there, use that. - if (fs::exists(base)) { + if (fs::exists(base) && fs::is_file(base)) { std::string location = fs::canonical(base).generic_string(); #ifdef FILELOCATOR_DEBUG_PRINT std::cout << "FileLocator: Found \"" << path << "\" at " @@ -143,8 +143,8 @@ bool FileLocator::doLocate(Resource &resource, const std::string &path, } } - // If the path starts with "./" only perform relative lookups! - if (path.substr(0, 2) == "./") { + // If the path starts with "./" or "../" only perform relative lookups! + if (path.substr(0, 2) == "./" || path.substr(0, 3) == "../") { return false; } @@ -159,7 +159,7 @@ bool FileLocator::doLocate(Resource &resource, const std::string &path, #endif fs::path p{*it}; p /= path; - if (fs::exists(p)) { + if (fs::exists(p) && fs::is_file(p)) { std::string location = fs::canonical(p).generic_string(); #ifdef FILELOCATOR_DEBUG_PRINT std::cout << "FileLocator: Found \"" << path << "\" in " -- cgit v1.2.3 From 2fbb15a2d80b878af1919fea7331c945d6ab43a0 Mon Sep 17 00:00:00 2001 From: Andreas Stöckel Date: Fri, 23 Jan 2015 15:28:39 +0100 Subject: replaced nonexistant is_file with is_regular_file --- src/plugins/filesystem/FileLocator.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/plugins/filesystem/FileLocator.cpp') diff --git a/src/plugins/filesystem/FileLocator.cpp b/src/plugins/filesystem/FileLocator.cpp index 6804c6d..356394e 100644 --- a/src/plugins/filesystem/FileLocator.cpp +++ b/src/plugins/filesystem/FileLocator.cpp @@ -131,7 +131,7 @@ bool FileLocator::doLocate(Resource &resource, const std::string &path, base /= path; // If we already found a fitting resource there, use that. - if (fs::exists(base) && fs::is_file(base)) { + if (fs::exists(base) && fs::is_regular_file(base)) { std::string location = fs::canonical(base).generic_string(); #ifdef FILELOCATOR_DEBUG_PRINT std::cout << "FileLocator: Found \"" << path << "\" at " @@ -159,7 +159,7 @@ bool FileLocator::doLocate(Resource &resource, const std::string &path, #endif fs::path p{*it}; p /= path; - if (fs::exists(p) && fs::is_file(p)) { + if (fs::exists(p) && fs::is_regular_file(p)) { std::string location = fs::canonical(p).generic_string(); #ifdef FILELOCATOR_DEBUG_PRINT std::cout << "FileLocator: Found \"" << path << "\" in " -- cgit v1.2.3