diff --git a/src/storage/storage.c b/src/storage/storage.c index f349d8af2..8d7d5de26 100644 --- a/src/storage/storage.c +++ b/src/storage/storage.c @@ -240,6 +240,7 @@ storageInfo(const Storage *this, const String *fileExp, StorageInfoParam param) FUNCTION_LOG_PARAM(STRING, fileExp); FUNCTION_LOG_PARAM(BOOL, param.ignoreMissing); FUNCTION_LOG_PARAM(BOOL, param.followLink); + FUNCTION_LOG_PARAM(BOOL, param.noPathEnforce); FUNCTION_LOG_END(); ASSERT(this != NULL); @@ -250,7 +251,7 @@ storageInfo(const Storage *this, const String *fileExp, StorageInfoParam param) MEM_CONTEXT_TEMP_BEGIN() { // Build the path - String *file = storagePathP(this, fileExp); + String *file = storagePathP(this, fileExp, .noEnforce = param.noPathEnforce); // Call driver function result = storageInterfaceInfoP(this->driver, file, .followLink = param.followLink); diff --git a/src/storage/storage.h b/src/storage/storage.h index 6976fa332..a89402294 100644 --- a/src/storage/storage.h +++ b/src/storage/storage.h @@ -84,6 +84,7 @@ typedef struct StorageInfoParam VAR_PARAM_HEADER; bool ignoreMissing; bool followLink; + bool noPathEnforce; } StorageInfoParam; #define storageInfoP(this, fileExp, ...) \ diff --git a/test/src/module/storage/posixTest.c b/test/src/module/storage/posixTest.c index 257d802f6..ad7217353 100644 --- a/test/src/module/storage/posixTest.c +++ b/test/src/module/storage/posixTest.c @@ -161,6 +161,16 @@ testRun(void) TEST_ASSIGN(info, storageInfoP(storageTest, fileName, .ignoreMissing = true), "get file info (missing)"); TEST_RESULT_BOOL(info.exists, false, " check not exists"); + // ------------------------------------------------------------------------------------------------------------------------- + TEST_TITLE("info outside of base path"); + + TEST_ERROR( + storageInfoP(storageTest, STRDEF("/etc"), .ignoreMissing = true), AssertError, + hrnReplaceKey("absolute path '/etc' is not in base path '{[path]}'")); + TEST_RESULT_BOOL( + storageInfoP(storageTest, STRDEF("/etc"), .ignoreMissing = true, .noPathEnforce = true).exists, true, + "path not enforced"); + // ------------------------------------------------------------------------------------------------------------------------- struct utimbuf utimeTest = {.actime = 1000000000, .modtime = 1555160000}; THROW_ON_SYS_ERROR_FMT(utime(testPath(), &utimeTest) != 0, FileWriteError, "unable to set time for '%s'", testPath());