From a4071eeb87062f9c1f6570ff94ea57406667908b Mon Sep 17 00:00:00 2001 From: guomeicen Date: Tue, 8 Jul 2025 22:22:11 +0800 Subject: [PATCH 1/6] fix warning Signed-off-by: guomeicen --- .../cloudsync_kit_inner/include/cloud_sync_manager_impl.h | 1 + .../cloudsync_kit_inner/src/cloud_sync_manager_impl.cpp | 2 ++ interfaces/inner_api/native/cloudsync_kit_inner/BUILD.gn | 1 + test/unittests/cloudsync_api/cloudsync_impl/BUILD.gn | 2 ++ .../cloudsync_impl/cloud_sync_manager_impl_test.cpp | 4 ++++ 5 files changed, 10 insertions(+) diff --git a/frameworks/native/cloudsync_kit_inner/include/cloud_sync_manager_impl.h b/frameworks/native/cloudsync_kit_inner/include/cloud_sync_manager_impl.h index a3883aaab..78f154095 100644 --- a/frameworks/native/cloudsync_kit_inner/include/cloud_sync_manager_impl.h +++ b/frameworks/native/cloudsync_kit_inner/include/cloud_sync_manager_impl.h @@ -78,6 +78,7 @@ public: const std::shared_ptr downloadCallback) override; int32_t StopDowngrade(const std::string &bundleName) override; int32_t GetCloudFileInfo(const std::string &bundleName, CloudFileInfo &cloudFileInfo) override; + bool HasInvalidChars(const std::string &str); // file version int32_t GetHistoryVersionList(const std::string &uri, const int32_t versionNumLimit, std::vector &historyVersionList) override; diff --git a/frameworks/native/cloudsync_kit_inner/src/cloud_sync_manager_impl.cpp b/frameworks/native/cloudsync_kit_inner/src/cloud_sync_manager_impl.cpp index a661afab0..16d1b4e80 100644 --- a/frameworks/native/cloudsync_kit_inner/src/cloud_sync_manager_impl.cpp +++ b/frameworks/native/cloudsync_kit_inner/src/cloud_sync_manager_impl.cpp @@ -915,6 +915,8 @@ void LogAndDelete(const std::string& path, RemoveFn fn, const std::string& messa } } +bool HasInvalidChars(const std::string &str) + static bool IsPhotoPath(const std::string& path) { static const std::string prefix = "/storage/cloud/files/Photo/"; diff --git a/interfaces/inner_api/native/cloudsync_kit_inner/BUILD.gn b/interfaces/inner_api/native/cloudsync_kit_inner/BUILD.gn index 79d83dd64..891efb83a 100644 --- a/interfaces/inner_api/native/cloudsync_kit_inner/BUILD.gn +++ b/interfaces/inner_api/native/cloudsync_kit_inner/BUILD.gn @@ -22,6 +22,7 @@ config("private_config") { include_dirs = [ "${distributedfile_path}/frameworks/native/cloudsync_kit_inner_lite/include", "${distributedfile_path}/frameworks/native/cloudsync_kit_inner/include", + "${distributedfile_path}/interfaces/inner_api/native/cloudsync_kit_inner", "${distributedfile_path}/utils/log/include", ] diff --git a/test/unittests/cloudsync_api/cloudsync_impl/BUILD.gn b/test/unittests/cloudsync_api/cloudsync_impl/BUILD.gn index 5b7c57c7e..da73ca4f2 100644 --- a/test/unittests/cloudsync_api/cloudsync_impl/BUILD.gn +++ b/test/unittests/cloudsync_api/cloudsync_impl/BUILD.gn @@ -81,6 +81,8 @@ ohos_unittest("cloud_sync_manager_impl_test") { sources = [ "${distributedfile_path}/frameworks/native/cloudsync_kit_inner/src/cloud_sync_manager_impl.cpp", "${distributedfile_path}/test/mock/system_ability_manager_client_mock.cpp", + + "cloud_sync_manager_impl_test.cpp", ] diff --git a/test/unittests/cloudsync_api/cloudsync_impl/cloud_sync_manager_impl_test.cpp b/test/unittests/cloudsync_api/cloudsync_impl/cloud_sync_manager_impl_test.cpp index 2240aff5e..4c39b4d98 100644 --- a/test/unittests/cloudsync_api/cloudsync_impl/cloud_sync_manager_impl_test.cpp +++ b/test/unittests/cloudsync_api/cloudsync_impl/cloud_sync_manager_impl_test.cpp @@ -858,6 +858,10 @@ HWTEST_F(CloudSyncManagerImplTest, OnAddSystemAbilityTest001, TestSize.Level1) GTEST_LOG_(INFO) << "OnAddSystemAbilityTest001 End"; } + + + + /* * @tc.name: CleanGalleryDentryFile * @tc.desc: Verify the CleanGalleryDentryFile function. -- Gitee From 32e03a81b777465f324774d5c8f11341e2b54e5d Mon Sep 17 00:00:00 2001 From: guomeicen Date: Tue, 8 Jul 2025 14:26:55 +0000 Subject: [PATCH 2/6] update frameworks/native/cloudsync_kit_inner/src/cloud_sync_manager_impl.cpp. Signed-off-by: guomeicen --- .../src/cloud_sync_manager_impl.cpp | 23 +++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/frameworks/native/cloudsync_kit_inner/src/cloud_sync_manager_impl.cpp b/frameworks/native/cloudsync_kit_inner/src/cloud_sync_manager_impl.cpp index 16d1b4e80..f8fb1e67f 100644 --- a/frameworks/native/cloudsync_kit_inner/src/cloud_sync_manager_impl.cpp +++ b/frameworks/native/cloudsync_kit_inner/src/cloud_sync_manager_impl.cpp @@ -14,6 +14,8 @@ */ #include "cloud_download_callback_client.h" +#include "cloud_file_fault_event.h" +#include "cloud_report_cacher.h" #include "cloud_sync_manager_impl.h" #include "cloud_sync_callback_client.h" #include "downgrade_download_callback_client.h" @@ -915,7 +917,24 @@ void LogAndDelete(const std::string& path, RemoveFn fn, const std::string& messa } } -bool HasInvalidChars(const std::string &str) +bool CloudSyncManagerImpl::HasInvalidChars(const std::string &str) { + if (str.find('\0') != std::string::npos || + str.find("/../") != std::string::npos || + str.find("/./") != std::string::npos) { + std::string errMsg = std::string("path has invalid chars, path is") + GetAnonyString(str).c_str(); + CLOUD_SYNC_FAULT_REPORT({"", CloudFile::FaultScenarioCode::CLOUD_CHECK_SYNC, + CloudFile::FaultType::FILE, E_PATH, errMsg}); + return false; + } + if ((str.length() >= 3 && str.compare(0, 3, "../") == 0) || (str.length() >= 2 && str.compare(0, 2, "./") == 0)) { + std::string errMsg = std::string("path starts with invalid chars, path is") + GetAnonyString(str).c_str(); + CLOUD_SYNC_FAULT_REPORT( + {"", CloudFile::FaultScenarioCode::CLOUD_CHECK_SYNC, CloudFile::FaultType::FILE, E_PATH, errMsg}); + return false; + } + + return true; +} static bool IsPhotoPath(const std::string& path) { @@ -941,7 +960,7 @@ static std::string GetMediaPath(const std::string& path) void CloudSyncManagerImpl::CleanGalleryDentryFile(const std::string path) { - if (!IsPhotoPath(path)) { + if (!HasInvalidChars(path) || !IsPhotoPath(path)) { LOGE("CleanGalleryDentryFile path is not photo"); return; } -- Gitee From d576dac6a0037fef4ea2526821702bc62cfc16b5 Mon Sep 17 00:00:00 2001 From: guomeicen Date: Tue, 8 Jul 2025 14:28:19 +0000 Subject: [PATCH 3/6] update frameworks/native/cloudsync_kit_inner/src/cloud_sync_manager_impl.cpp. Signed-off-by: guomeicen --- .../cloudsync_kit_inner/src/cloud_sync_manager_impl.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/frameworks/native/cloudsync_kit_inner/src/cloud_sync_manager_impl.cpp b/frameworks/native/cloudsync_kit_inner/src/cloud_sync_manager_impl.cpp index f8fb1e67f..ea4d0655d 100644 --- a/frameworks/native/cloudsync_kit_inner/src/cloud_sync_manager_impl.cpp +++ b/frameworks/native/cloudsync_kit_inner/src/cloud_sync_manager_impl.cpp @@ -928,8 +928,8 @@ bool CloudSyncManagerImpl::HasInvalidChars(const std::string &str) { } if ((str.length() >= 3 && str.compare(0, 3, "../") == 0) || (str.length() >= 2 && str.compare(0, 2, "./") == 0)) { std::string errMsg = std::string("path starts with invalid chars, path is") + GetAnonyString(str).c_str(); - CLOUD_SYNC_FAULT_REPORT( - {"", CloudFile::FaultScenarioCode::CLOUD_CHECK_SYNC, CloudFile::FaultType::FILE, E_PATH, errMsg}); + CLOUD_SYNC_FAULT_REPORT({"", CloudFile::FaultScenarioCode::CLOUD_CHECK_SYNC, + CloudFile::FaultType::FILE, E_PATH, errMsg}); return false; } -- Gitee From 056cc846484b716afe8f5fe32596f571353b9cf0 Mon Sep 17 00:00:00 2001 From: guomeicen Date: Tue, 8 Jul 2025 14:30:57 +0000 Subject: [PATCH 4/6] update interfaces/inner_api/native/cloudsync_kit_inner/BUILD.gn. Signed-off-by: guomeicen --- interfaces/inner_api/native/cloudsync_kit_inner/BUILD.gn | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/interfaces/inner_api/native/cloudsync_kit_inner/BUILD.gn b/interfaces/inner_api/native/cloudsync_kit_inner/BUILD.gn index 891efb83a..f9f50600e 100644 --- a/interfaces/inner_api/native/cloudsync_kit_inner/BUILD.gn +++ b/interfaces/inner_api/native/cloudsync_kit_inner/BUILD.gn @@ -22,7 +22,7 @@ config("private_config") { include_dirs = [ "${distributedfile_path}/frameworks/native/cloudsync_kit_inner_lite/include", "${distributedfile_path}/frameworks/native/cloudsync_kit_inner/include", - + "${distributedfile_path}/interfaces/inner_api/native/cloud_file_kit_inner/big_data_statistics", "${distributedfile_path}/interfaces/inner_api/native/cloudsync_kit_inner", "${distributedfile_path}/utils/log/include", ] @@ -52,6 +52,8 @@ ohos_shared_library("cloudsync_kit_inner") { debug = false } sources = [ + "${distributedfile_path}/frameworks/native/cloud_file_kit_inner/src/big_data_statistics/cloud_file_fault_event.cpp", + "${distributedfile_path}/frameworks/native/cloud_file_kit_inner/src/big_data_statistics/cloud_report_cacher.cpp", "${distributedfile_path}/frameworks/native/cloudsync_kit_inner/src/cloud_download_callback_client.cpp", "${distributedfile_path}/frameworks/native/cloudsync_kit_inner/src/cloud_download_callback_stub.cpp", "${distributedfile_path}/frameworks/native/cloudsync_kit_inner/src/cloud_download_uri_manager.cpp", @@ -84,7 +86,9 @@ ohos_shared_library("cloudsync_kit_inner") { "ability_runtime:dataobs_manager", "c_utils:utils", "hilog:libhilog", + "hisysevent:libhisysevent", "ipc:ipc_single", + "json:nlohmann_json_static", "safwk:system_ability_fwk", "samgr:samgr_proxy", ] -- Gitee From 2e4de5bdac230d6a139db83e7cf354147a54b59b Mon Sep 17 00:00:00 2001 From: guomeicen Date: Tue, 8 Jul 2025 14:32:43 +0000 Subject: [PATCH 5/6] update test/unittests/cloudsync_api/cloudsync_impl/BUILD.gn. Signed-off-by: guomeicen --- test/unittests/cloudsync_api/cloudsync_impl/BUILD.gn | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/test/unittests/cloudsync_api/cloudsync_impl/BUILD.gn b/test/unittests/cloudsync_api/cloudsync_impl/BUILD.gn index da73ca4f2..c1fb1877d 100644 --- a/test/unittests/cloudsync_api/cloudsync_impl/BUILD.gn +++ b/test/unittests/cloudsync_api/cloudsync_impl/BUILD.gn @@ -79,15 +79,16 @@ ohos_unittest("cloud_sync_manager_impl_test") { module_out_path = "dfs_service/dfs_service" sources = [ + "${distributedfile_path}/frameworks/native/cloud_file_kit_inner/src/big_data_statistics/cloud_file_fault_event.cpp", + "${distributedfile_path}/frameworks/native/cloud_file_kit_inner/src/big_data_statistics/cloud_report_cacher.cpp", "${distributedfile_path}/frameworks/native/cloudsync_kit_inner/src/cloud_sync_manager_impl.cpp", "${distributedfile_path}/test/mock/system_ability_manager_client_mock.cpp", - - "cloud_sync_manager_impl_test.cpp", ] include_dirs = [ "${distributedfile_path}/frameworks/native/cloudsync_kit_inner/include", + "${distributedfile_path}/interfaces/inner_api/native/cloud_file_kit_inner/big_data_statistics", "${distributedfile_path}/interfaces/inner_api/native/cloudsync_kit_inner", "${distributedfile_path}/test/mock", "${distributedfile_path}/test/mock/ipc", @@ -110,6 +111,7 @@ ohos_unittest("cloud_sync_manager_impl_test") { "googletest:gmock_main", "googletest:gtest_main", "hilog:libhilog", + "hisysevent:libhisysevent", "ipc:ipc_single", "json:nlohmann_json_static", "samgr:samgr_proxy", -- Gitee From f8f49e26903cdb658c81fb2ef69f5188308318da Mon Sep 17 00:00:00 2001 From: guomeicen Date: Tue, 8 Jul 2025 14:34:55 +0000 Subject: [PATCH 6/6] update test/unittests/cloudsync_api/cloudsync_impl/cloud_sync_manager_impl_test.cpp. Signed-off-by: guomeicen --- .../cloud_sync_manager_impl_test.cpp | 102 +++++++++++++++++- 1 file changed, 98 insertions(+), 4 deletions(-) diff --git a/test/unittests/cloudsync_api/cloudsync_impl/cloud_sync_manager_impl_test.cpp b/test/unittests/cloudsync_api/cloudsync_impl/cloud_sync_manager_impl_test.cpp index 4c39b4d98..676bf8317 100644 --- a/test/unittests/cloudsync_api/cloudsync_impl/cloud_sync_manager_impl_test.cpp +++ b/test/unittests/cloudsync_api/cloudsync_impl/cloud_sync_manager_impl_test.cpp @@ -21,6 +21,7 @@ #include #include "cloud_sync_manager_impl.h" +#include "cloud_file_fault_event.h" #include "dfs_error.h" #include "icloud_sync_service.h" #include "iservice_registry.h" @@ -858,9 +859,102 @@ HWTEST_F(CloudSyncManagerImplTest, OnAddSystemAbilityTest001, TestSize.Level1) GTEST_LOG_(INFO) << "OnAddSystemAbilityTest001 End"; } - - - +/* + * @tc.name: HasInvalidChars + * @tc.desc: Verify the HasInvalidChars function. + * @tc.type: FUNC + */ +HWTEST_F(CloudSyncManagerImplTest, HasInvalidCharsTest001, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "HasInvalidCharsTest001 Start"; + try { + string path = "/storage/media/cloud/files/../Photo"; + bool ret = CloudSyncManagerImpl::GetInstance().HasInvalidChars(path); + EXPECT_FALSE(ret); + } catch (...) { + EXPECT_TRUE(false); + GTEST_LOG_(INFO) << " HasInvalidCharsTest001 FAILED"; + } + GTEST_LOG_(INFO) << "HasInvalidCharsTest001 End"; +} + +/* + * @tc.name: HasInvalidChars + * @tc.desc: Verify the HasInvalidChars function. + * @tc.type: FUNC + */ +HWTEST_F(CloudSyncManagerImplTest, HasInvalidCharsTest002, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "HasInvalidCharsTest002 Start"; + try { + string path = "/storage/media/cloud/files/./Photo"; + bool ret = CloudSyncManagerImpl::GetInstance().HasInvalidChars(path); + EXPECT_FALSE(ret); + } catch (...) { + EXPECT_TRUE(false); + GTEST_LOG_(INFO) << " HasInvalidCharsTest002 FAILED"; + } + GTEST_LOG_(INFO) << "HasInvalidCharsTest002 End"; +} + +/* + * @tc.name: HasInvalidChars + * @tc.desc: Verify the HasInvalidChars function. + * @tc.type: FUNC + */ +HWTEST_F(CloudSyncManagerImplTest, HasInvalidCharsTest003, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "HasInvalidCharsTest003 Start"; + try { + std::string path = "/storage/media/cloud/"; + path += '\0'; + path += "/files/Photo"; + bool ret = CloudSyncManagerImpl::GetInstance().HasInvalidChars(path); + EXPECT_FALSE(ret); + } catch (...) { + EXPECT_TRUE(false); + GTEST_LOG_(INFO) << " HasInvalidCharsTest003 FAILED"; + } + GTEST_LOG_(INFO) << "HasInvalidCharsTest003 End"; +} + +/* + * @tc.name: HasInvalidChars + * @tc.desc: Verify the HasInvalidChars function. + * @tc.type: FUNC + */ +HWTEST_F(CloudSyncManagerImplTest, HasInvalidCharsTest004, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "HasInvalidCharsTest004 Start"; + try { + string path = "./storage/media/cloud/files/Photo"; + bool ret = CloudSyncManagerImpl::GetInstance().HasInvalidChars(path); + EXPECT_FALSE(ret); + } catch (...) { + EXPECT_TRUE(false); + GTEST_LOG_(INFO) << " HasInvalidCharsTest004 FAILED"; + } + GTEST_LOG_(INFO) << "HasInvalidCharsTest004 End"; +} + +/* + * @tc.name: HasInvalidChars + * @tc.desc: Verify the HasInvalidChars function. + * @tc.type: FUNC + */ +HWTEST_F(CloudSyncManagerImplTest, HasInvalidCharsTest005, TestSize.Level1) +{ + GTEST_LOG_(INFO) << "HasInvalidCharsTest005 Start"; + try { + string path = "../storage/media/cloud/files/Photo"; + bool ret = CloudSyncManagerImpl::GetInstance().HasInvalidChars(path); + EXPECT_FALSE(ret); + } catch (...) { + EXPECT_TRUE(false); + GTEST_LOG_(INFO) << " HasInvalidCharsTest005 FAILED"; + } + GTEST_LOG_(INFO) << "HasInvalidCharsTest005 End"; +} /* * @tc.name: CleanGalleryDentryFile @@ -946,7 +1040,7 @@ HWTEST_F(CloudSyncManagerImplTest, CleanGalleryDentryFileTest004, TestSize.Level std::ofstream("/storage/media/cloud/files/Photo/1/666666.jpg"); std::string testDir = "/storage/666666.jpg"; CloudSyncManagerImpl::GetInstance().CleanGalleryDentryFile(testDir); - bool isExists = fs::exists("/storage/media/100/cloud/files/Photo/1/666666.jpg"); + bool isExists = fs::exists("/storage/media/cloud/files/Photo/1/666666.jpg"); system("rm -rf /storage/media/cloud/files/Photo/1/666666.jpg"); EXPECT_TRUE(isExists); } catch (...) { -- Gitee