From 4590d5da7a939066e8f37a20afe657cf24518da9 Mon Sep 17 00:00:00 2001 From: cuiruibin Date: Mon, 11 Aug 2025 14:41:26 +0800 Subject: [PATCH] =?UTF-8?q?AFS=E8=B7=AF=E5=BE=84=E6=A0=A1=E9=AA=8C?= =?UTF-8?q?=E5=8A=A0=E5=9B=BA=20Signed-off-by:=20cuiruibin=20?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- interfaces/common/src/sandbox_helper.cpp | 2 +- .../unittest/file_share_native/file_share_test.cpp | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/interfaces/common/src/sandbox_helper.cpp b/interfaces/common/src/sandbox_helper.cpp index d0a2e6f55..f44fcef3b 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 8b05e4b54..fdf2ff6aa 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"); -- Gitee