diff --git a/interfaces/common/src/sandbox_helper.cpp b/interfaces/common/src/sandbox_helper.cpp index d0a2e6f5522db8d3542a2f97515ff3d0f1e51720..f44fcef3bd4471ab7fa2b94a5af2e5abc963c24f 100644 --- a/interfaces/common/src/sandbox_helper.cpp +++ b/interfaces/common/src/sandbox_helper.cpp @@ -531,7 +531,7 @@ bool SandboxHelper::IsValidPath(const std::string &filePath) LOGE("Relative path is not allowed, path tail is /.."); return false; } - return true; + return !std::any_of(filePath.begin(), filePath.end(), [](char c) {return c == '\0';}); } bool SandboxHelper::CheckValidPath(const std::string &filePath) diff --git a/test/unittest/file_share_native/file_share_test.cpp b/test/unittest/file_share_native/file_share_test.cpp index 8b05e4b545de21a893c573963beb57854dae60ba..fdf2ff6aa20371b05ffadf8dcde78d41f6757f14 100644 --- a/test/unittest/file_share_native/file_share_test.cpp +++ b/test/unittest/file_share_native/file_share_test.cpp @@ -567,7 +567,21 @@ HWTEST_F(FileShareTest, File_share_IsValidPath_0002, testing::ext::TestSize.Leve EXPECT_FALSE(result); result = SandboxHelper::IsValidPath("/test/..test/.."); EXPECT_FALSE(result); + result = SandboxHelper::IsValidPath({"/test/\0test", 11}); + EXPECT_FALSE(result); + result = SandboxHelper::IsValidPath({"/test/test/\0", 12}); + EXPECT_FALSE(result); + result = SandboxHelper::IsValidPath({"/test\00/test", 11}); + EXPECT_FALSE(result); + result = SandboxHelper::IsValidPath({"/test/test/\00", 12}); + EXPECT_FALSE(result); + result = SandboxHelper::IsValidPath({"/test/\x0test", 11}); + EXPECT_FALSE(result); + result = SandboxHelper::IsValidPath("/test/test/\x0", 12); + EXPECT_FALSE(result); + result = SandboxHelper::IsValidPath("test/0/00/\test"); + EXPECT_TRUE(result); result = SandboxHelper::IsValidPath("test"); EXPECT_TRUE(result); result = SandboxHelper::IsValidPath("/test/test../test");