From 6f37e5c605833db35b31677b4e1d1b773ec19f4c Mon Sep 17 00:00:00 2001 From: h30071384 Date: Fri, 5 Sep 2025 10:17:29 +0800 Subject: [PATCH] ufs_fuzz_part3 Signed-off-by: h30071384 --- test/fuzztest/BUILD.gn | 7 + .../fileaccessextgetroots_fuzzer/BUILD.gn | 68 +++++++++ .../fileaccessextgetroots_fuzzer/corpus/init | 16 +++ .../fileaccessextgetroots_fuzzer.cpp | 117 ++++++++++++++++ .../fileaccessextgetroots_fuzzer.h | 21 +++ .../fileaccessextgetroots_fuzzer/project.xml | 25 ++++ .../fileaccessextlistfile_fuzzer/BUILD.gn | 68 +++++++++ .../fileaccessextlistfile_fuzzer/corpus/init | 16 +++ .../fileaccessextlistfile_fuzzer.cpp | 132 ++++++++++++++++++ .../fileaccessextlistfile_fuzzer.h | 21 +++ .../fileaccessextlistfile_fuzzer/project.xml | 25 ++++ .../fileaccessextmkdir_fuzzer/BUILD.gn | 68 +++++++++ .../fileaccessextmkdir_fuzzer/corpus/init | 16 +++ .../fileaccessextmkdir_fuzzer.cpp | 119 ++++++++++++++++ .../fileaccessextmkdir_fuzzer.h | 21 +++ .../fileaccessextmkdir_fuzzer/project.xml | 25 ++++ .../fileaccessextmove_fuzzer/BUILD.gn | 68 +++++++++ .../fileaccessextmove_fuzzer/corpus/init | 16 +++ .../fileaccessextmove_fuzzer.cpp | 119 ++++++++++++++++ .../fileaccessextmove_fuzzer.h | 21 +++ .../fileaccessextmove_fuzzer/project.xml | 25 ++++ .../fileaccessextmovefile_fuzzer/BUILD.gn | 68 +++++++++ .../fileaccessextmovefile_fuzzer/corpus/init | 16 +++ .../fileaccessextmovefile_fuzzer.cpp | 120 ++++++++++++++++ .../fileaccessextmovefile_fuzzer.h | 21 +++ .../fileaccessextmovefile_fuzzer/project.xml | 25 ++++ .../fileaccessextmoveitem_fuzzer/BUILD.gn | 68 +++++++++ .../fileaccessextmoveitem_fuzzer/corpus/init | 16 +++ .../fileaccessextmoveitem_fuzzer.cpp | 127 +++++++++++++++++ .../fileaccessextmoveitem_fuzzer.h | 21 +++ .../fileaccessextmoveitem_fuzzer/project.xml | 25 ++++ .../fileaccessextopenfile_fuzzer/BUILD.gn | 68 +++++++++ .../fileaccessextopenfile_fuzzer/corpus/init | 16 +++ .../fileaccessextopenfile_fuzzer.cpp | 123 ++++++++++++++++ .../fileaccessextopenfile_fuzzer.h | 21 +++ .../fileaccessextopenfile_fuzzer/project.xml | 25 ++++ 36 files changed, 1774 insertions(+) create mode 100644 test/fuzztest/fileaccessextgetroots_fuzzer/BUILD.gn create mode 100644 test/fuzztest/fileaccessextgetroots_fuzzer/corpus/init create mode 100644 test/fuzztest/fileaccessextgetroots_fuzzer/fileaccessextgetroots_fuzzer.cpp create mode 100644 test/fuzztest/fileaccessextgetroots_fuzzer/fileaccessextgetroots_fuzzer.h create mode 100644 test/fuzztest/fileaccessextgetroots_fuzzer/project.xml create mode 100644 test/fuzztest/fileaccessextlistfile_fuzzer/BUILD.gn create mode 100644 test/fuzztest/fileaccessextlistfile_fuzzer/corpus/init create mode 100644 test/fuzztest/fileaccessextlistfile_fuzzer/fileaccessextlistfile_fuzzer.cpp create mode 100644 test/fuzztest/fileaccessextlistfile_fuzzer/fileaccessextlistfile_fuzzer.h create mode 100644 test/fuzztest/fileaccessextlistfile_fuzzer/project.xml create mode 100644 test/fuzztest/fileaccessextmkdir_fuzzer/BUILD.gn create mode 100644 test/fuzztest/fileaccessextmkdir_fuzzer/corpus/init create mode 100644 test/fuzztest/fileaccessextmkdir_fuzzer/fileaccessextmkdir_fuzzer.cpp create mode 100644 test/fuzztest/fileaccessextmkdir_fuzzer/fileaccessextmkdir_fuzzer.h create mode 100644 test/fuzztest/fileaccessextmkdir_fuzzer/project.xml create mode 100644 test/fuzztest/fileaccessextmove_fuzzer/BUILD.gn create mode 100644 test/fuzztest/fileaccessextmove_fuzzer/corpus/init create mode 100644 test/fuzztest/fileaccessextmove_fuzzer/fileaccessextmove_fuzzer.cpp create mode 100644 test/fuzztest/fileaccessextmove_fuzzer/fileaccessextmove_fuzzer.h create mode 100644 test/fuzztest/fileaccessextmove_fuzzer/project.xml create mode 100644 test/fuzztest/fileaccessextmovefile_fuzzer/BUILD.gn create mode 100644 test/fuzztest/fileaccessextmovefile_fuzzer/corpus/init create mode 100644 test/fuzztest/fileaccessextmovefile_fuzzer/fileaccessextmovefile_fuzzer.cpp create mode 100644 test/fuzztest/fileaccessextmovefile_fuzzer/fileaccessextmovefile_fuzzer.h create mode 100644 test/fuzztest/fileaccessextmovefile_fuzzer/project.xml create mode 100644 test/fuzztest/fileaccessextmoveitem_fuzzer/BUILD.gn create mode 100644 test/fuzztest/fileaccessextmoveitem_fuzzer/corpus/init create mode 100644 test/fuzztest/fileaccessextmoveitem_fuzzer/fileaccessextmoveitem_fuzzer.cpp create mode 100644 test/fuzztest/fileaccessextmoveitem_fuzzer/fileaccessextmoveitem_fuzzer.h create mode 100644 test/fuzztest/fileaccessextmoveitem_fuzzer/project.xml create mode 100644 test/fuzztest/fileaccessextopenfile_fuzzer/BUILD.gn create mode 100644 test/fuzztest/fileaccessextopenfile_fuzzer/corpus/init create mode 100644 test/fuzztest/fileaccessextopenfile_fuzzer/fileaccessextopenfile_fuzzer.cpp create mode 100644 test/fuzztest/fileaccessextopenfile_fuzzer/fileaccessextopenfile_fuzzer.h create mode 100644 test/fuzztest/fileaccessextopenfile_fuzzer/project.xml diff --git a/test/fuzztest/BUILD.gn b/test/fuzztest/BUILD.gn index bfacc990..3fe7c658 100644 --- a/test/fuzztest/BUILD.gn +++ b/test/fuzztest/BUILD.gn @@ -37,6 +37,13 @@ group("user_file_service_fuzz_test") { "fileaccessextgetfileinfo_fuzzer:FileAccessExtGetFileInfoFuzzTest", "fileaccessextaccess_fuzzer:FileAccessExtAccessFuzzTest", "fileaccessextconnection_fuzzer:FileAccessExtConnectionFuzzTest", + "fileaccessextopenfile_fuzzer:FileAccessExtOpenFileFuzzTest", + "fileaccessextmkdir_fuzzer:FileAccessExtMkdirFuzzTest", + "fileaccessextlistfile_fuzzer:FileAccessExtListFileFuzzTest", + "fileaccessextgetroots_fuzzer:FileAccessExtGetRootsFuzzTest", + "fileaccessextmoveitem_fuzzer:FileAccessExtMoveItemFuzzTest", + "fileaccessextmovefile_fuzzer:FileAccessExtMoveFileFuzzTest", + "fileaccessextmove_fuzzer:FileAccessExtMoveFuzzTest", "fileaccessservicebaseproxy_fuzzer:FileAccessServiceBaseProxyFuzzTest", "fileinfosharedmemory_fuzzer:FileInfoSharedMemoryFuzzTest", "useraccesscommonutils_fuzzer:UserAccessCommonUtilsFuzzTest", diff --git a/test/fuzztest/fileaccessextgetroots_fuzzer/BUILD.gn b/test/fuzztest/fileaccessextgetroots_fuzzer/BUILD.gn new file mode 100644 index 00000000..dd312a33 --- /dev/null +++ b/test/fuzztest/fileaccessextgetroots_fuzzer/BUILD.gn @@ -0,0 +1,68 @@ +# Copyright (c) 2025 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +#####################hydra-fuzz################### +import("//build/config/features.gni") +import("//build/test.gni") +import("//foundation/filemanagement/user_file_service/filemanagement_aafwk.gni") +ohos_fuzztest("FileAccessExtGetRootsFuzzTest") { + module_out_path = "user_file_service/user_file_service" + fuzz_config_file = + "${user_file_service_path}/test/fuzztest/fileaccessextgetroots_fuzzer" + include_dirs = [ + "${user_file_service_path}/interfaces/inner_api/file_access/include", + "${user_file_service_path}/test/fuzztest/privacy_comm/include", + "${user_file_service_path}/utils", + ] + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + sources = [ + "fileaccessextgetroots_fuzzer.cpp", + "${user_file_service_path}/test/fuzztest/privacy_comm/src/user_file_service_token_mock.cpp" + ] + + deps = [ + "${user_file_service_path}/interfaces/inner_api/file_access:file_access_ext_base_include", + "${user_file_service_path}/interfaces/inner_api/file_access:file_access_extension_ability_kit", + "${user_file_service_path}/services:file_access_service", + "${user_file_service_path}/services:file_access_service_base_include", + ] + + external_deps = [ + "ability_base:want", + "ability_base:zuri", + "ability_runtime:ability_context_native", + "ability_runtime:ability_manager", + "ability_runtime:app_manager", + "ability_runtime:runtime", + "ability_runtime:wantagent_innerkits", + "access_token:libaccesstoken_sdk", + "access_token:libnativetoken", + "access_token:libtoken_setproc", + "bundle_framework:appexecfwk_core", + "cJSON:cjson_static", + "c_utils:utils", + "hilog:libhilog", + "hitrace:hitrace_meter", + "ipc:ipc_core", + "safwk:system_ability_fwk", + "samgr:samgr_proxy", + "selinux_adapter:librestorecon", + ] + + defines = [ "private=public" ] +} diff --git a/test/fuzztest/fileaccessextgetroots_fuzzer/corpus/init b/test/fuzztest/fileaccessextgetroots_fuzzer/corpus/init new file mode 100644 index 00000000..7ade8a0f --- /dev/null +++ b/test/fuzztest/fileaccessextgetroots_fuzzer/corpus/init @@ -0,0 +1,16 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +FUZZ \ No newline at end of file diff --git a/test/fuzztest/fileaccessextgetroots_fuzzer/fileaccessextgetroots_fuzzer.cpp b/test/fuzztest/fileaccessextgetroots_fuzzer/fileaccessextgetroots_fuzzer.cpp new file mode 100644 index 00000000..5a293f55 --- /dev/null +++ b/test/fuzztest/fileaccessextgetroots_fuzzer/fileaccessextgetroots_fuzzer.cpp @@ -0,0 +1,117 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#include "fileaccessextgetroots_fuzzer.h" + +#include +#include + +#include "accesstoken_kit.h" +#include "file_access_helper.h" +#include "file_access_ext_base_proxy.h" +#include "file_info_shared_memory.h" +#include "iservice_registry.h" +#include "token_setproc.h" +#include "nativetoken_kit.h" + +#include "user_file_service_token_mock.h" + +namespace OHOS { +using namespace std; +using namespace FileAccessFwk; + +const int ABILITY_ID = 5003; +shared_ptr g_fah = nullptr; +const int UID_TRANSFORM_TMP = 20000000; +const int UID_DEFAULT = 0; + +template +T TypeCast(const uint8_t *data, int *pos = nullptr) +{ + if (pos) { + *pos += sizeof(T); + } + return *(reinterpret_cast(data)); +} + +shared_ptr GetFileAccessHelper() +{ + if (g_fah != nullptr) { + return g_fah; + } + auto saManager = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); + if (saManager == nullptr) { + return nullptr; + } + auto remoteObj = saManager->GetSystemAbility(ABILITY_ID); + AAFwk::Want want; + vector wantVec; + setuid(UID_TRANSFORM_TMP); + int ret = FileAccessHelper::GetRegisteredFileAccessExtAbilityInfo(wantVec); + if (ret != OHOS::FileAccessFwk::ERR_OK) { + printf("GetRegisteredFileAccessExtAbilityInfo failed."); + return nullptr; + } + bool sus = false; + for (size_t i = 0; i < wantVec.size(); i++) { + auto element = wantVec[i].GetElement(); + if (element.GetBundleName() == "com.ohos.UserFile.ExternalFileManager" && + element.GetAbilityName() == "FileExtensionAbility") { + want = wantVec[i]; + sus = true; + break; + } + } + if (!sus) { + printf("not found bundleName."); + return nullptr; + } + vector wants {want}; + g_fah = FileAccessHelper::Creator(remoteObj, wants); + setuid(UID_DEFAULT); + if (g_fah == nullptr) { + printf("creator fileAccessHelper return nullptr."); + return nullptr; + } + return g_fah; +} + +bool GetRootsFuzzTest(sptr proxy, const uint8_t *data, size_t size) +{ + (void)data; + vector rootInfoVec; + proxy->GetRoots(rootInfoVec); + return true; +} +} // namespace OHOS + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) +{ + OHOS::UserFileServiceTokenMock tokenMock; + tokenMock.SetFileManagerToken(); + auto helper = OHOS::GetFileAccessHelper(); + if (helper == nullptr) { + printf("helper is nullptr."); + return false; + } + auto proxy = helper->GetProxyByBundleName(OHOS::EXTERNAL_BNUDLE_NAME); + if (proxy == nullptr) { + printf("get proxy failed."); + return 0; + } + + OHOS::GetRootsFuzzTest(proxy, data, size); + return 0; +} diff --git a/test/fuzztest/fileaccessextgetroots_fuzzer/fileaccessextgetroots_fuzzer.h b/test/fuzztest/fileaccessextgetroots_fuzzer/fileaccessextgetroots_fuzzer.h new file mode 100644 index 00000000..01bddbe3 --- /dev/null +++ b/test/fuzztest/fileaccessextgetroots_fuzzer/fileaccessextgetroots_fuzzer.h @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef FILE_ACCESS_EXTGETROOTS_FUZZER_H +#define FILE_ACCESS_EXTGETROOTS_FUZZER_H + +#define FUZZ_PROJECT_NAME "fileaccessextgetroots_fuzzer" + +#endif \ No newline at end of file diff --git a/test/fuzztest/fileaccessextgetroots_fuzzer/project.xml b/test/fuzztest/fileaccessextgetroots_fuzzer/project.xml new file mode 100644 index 00000000..8cd95817 --- /dev/null +++ b/test/fuzztest/fileaccessextgetroots_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/test/fuzztest/fileaccessextlistfile_fuzzer/BUILD.gn b/test/fuzztest/fileaccessextlistfile_fuzzer/BUILD.gn new file mode 100644 index 00000000..7347b423 --- /dev/null +++ b/test/fuzztest/fileaccessextlistfile_fuzzer/BUILD.gn @@ -0,0 +1,68 @@ +# Copyright (c) 2025 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +#####################hydra-fuzz################### +import("//build/config/features.gni") +import("//build/test.gni") +import("//foundation/filemanagement/user_file_service/filemanagement_aafwk.gni") +ohos_fuzztest("FileAccessExtListFileFuzzTest") { + module_out_path = "user_file_service/user_file_service" + fuzz_config_file = + "${user_file_service_path}/test/fuzztest/fileaccessextlistfile_fuzzer" + include_dirs = [ + "${user_file_service_path}/interfaces/inner_api/file_access/include", + "${user_file_service_path}/test/fuzztest/privacy_comm/include", + "${user_file_service_path}/utils", + ] + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + sources = [ + "fileaccessextlistfile_fuzzer.cpp", + "${user_file_service_path}/test/fuzztest/privacy_comm/src/user_file_service_token_mock.cpp" + ] + + deps = [ + "${user_file_service_path}/interfaces/inner_api/file_access:file_access_ext_base_include", + "${user_file_service_path}/interfaces/inner_api/file_access:file_access_extension_ability_kit", + "${user_file_service_path}/services:file_access_service", + "${user_file_service_path}/services:file_access_service_base_include", + ] + + external_deps = [ + "ability_base:want", + "ability_base:zuri", + "ability_runtime:ability_context_native", + "ability_runtime:ability_manager", + "ability_runtime:app_manager", + "ability_runtime:runtime", + "ability_runtime:wantagent_innerkits", + "access_token:libaccesstoken_sdk", + "access_token:libnativetoken", + "access_token:libtoken_setproc", + "bundle_framework:appexecfwk_core", + "cJSON:cjson_static", + "c_utils:utils", + "hilog:libhilog", + "hitrace:hitrace_meter", + "ipc:ipc_core", + "safwk:system_ability_fwk", + "samgr:samgr_proxy", + "selinux_adapter:librestorecon", + ] + + defines = [ "private=public" ] +} diff --git a/test/fuzztest/fileaccessextlistfile_fuzzer/corpus/init b/test/fuzztest/fileaccessextlistfile_fuzzer/corpus/init new file mode 100644 index 00000000..7ade8a0f --- /dev/null +++ b/test/fuzztest/fileaccessextlistfile_fuzzer/corpus/init @@ -0,0 +1,16 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +FUZZ \ No newline at end of file diff --git a/test/fuzztest/fileaccessextlistfile_fuzzer/fileaccessextlistfile_fuzzer.cpp b/test/fuzztest/fileaccessextlistfile_fuzzer/fileaccessextlistfile_fuzzer.cpp new file mode 100644 index 00000000..d197a43c --- /dev/null +++ b/test/fuzztest/fileaccessextlistfile_fuzzer/fileaccessextlistfile_fuzzer.cpp @@ -0,0 +1,132 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#include "fileaccessextlistfile_fuzzer.h" + +#include +#include + +#include "accesstoken_kit.h" +#include "file_access_helper.h" +#include "file_access_ext_base_proxy.h" +#include "file_info_shared_memory.h" +#include "iservice_registry.h" +#include "token_setproc.h" +#include "nativetoken_kit.h" + +#include "user_file_service_token_mock.h" + +namespace OHOS { +using namespace std; +using namespace FileAccessFwk; + +const int ABILITY_ID = 5003; +shared_ptr g_fah = nullptr; +const int UID_TRANSFORM_TMP = 20000000; +const int UID_DEFAULT = 0; + +template +T TypeCast(const uint8_t *data, int *pos = nullptr) +{ + if (pos) { + *pos += sizeof(T); + } + return *(reinterpret_cast(data)); +} + +shared_ptr GetFileAccessHelper() +{ + if (g_fah != nullptr) { + return g_fah; + } + auto saManager = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); + if (saManager == nullptr) { + return nullptr; + } + auto remoteObj = saManager->GetSystemAbility(ABILITY_ID); + AAFwk::Want want; + vector wantVec; + setuid(UID_TRANSFORM_TMP); + int ret = FileAccessHelper::GetRegisteredFileAccessExtAbilityInfo(wantVec); + if (ret != OHOS::FileAccessFwk::ERR_OK) { + printf("GetRegisteredFileAccessExtAbilityInfo failed."); + return nullptr; + } + bool sus = false; + for (size_t i = 0; i < wantVec.size(); i++) { + auto element = wantVec[i].GetElement(); + if (element.GetBundleName() == "com.ohos.UserFile.ExternalFileManager" && + element.GetAbilityName() == "FileExtensionAbility") { + want = wantVec[i]; + sus = true; + break; + } + } + if (!sus) { + printf("not found bundleName."); + return nullptr; + } + vector wants {want}; + g_fah = FileAccessHelper::Creator(remoteObj, wants); + setuid(UID_DEFAULT); + if (g_fah == nullptr) { + printf("creator fileAccessHelper return nullptr."); + return nullptr; + } + return g_fah; +} + +bool ListFileFuzzTest(sptr proxy, const uint8_t *data, size_t size) +{ + if (data == nullptr || size < sizeof(int64_t)) { + return true; + } + + int pos = 0; + int64_t offset = TypeCast(data, &pos); + + FileInfo fileInfo; + fileInfo.uri = std::string(reinterpret_cast(data + pos), size - pos); + SharedMemoryInfo memInfo; + int result = SharedMemoryOperation::CreateSharedMemory("FileInfo List", DEFAULT_CAPACITY_200KB, memInfo); + if (result != OHOS::FileAccessFwk::ERR_OK) { + printf("CreateSharedMemory failed. ret : %d", result); + return false; + } + FileFilter filter; + proxy->ListFile(fileInfo, offset, filter, memInfo); + SharedMemoryOperation::DestroySharedMemory(memInfo); + return true; +} +} // namespace OHOS + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) +{ + OHOS::UserFileServiceTokenMock tokenMock; + tokenMock.SetFileManagerToken(); + auto helper = OHOS::GetFileAccessHelper(); + if (helper == nullptr) { + printf("helper is nullptr."); + return false; + } + auto proxy = helper->GetProxyByBundleName(OHOS::EXTERNAL_BNUDLE_NAME); + if (proxy == nullptr) { + printf("get proxy failed."); + return 0; + } + + OHOS::ListFileFuzzTest(proxy, data, size); + return 0; +} diff --git a/test/fuzztest/fileaccessextlistfile_fuzzer/fileaccessextlistfile_fuzzer.h b/test/fuzztest/fileaccessextlistfile_fuzzer/fileaccessextlistfile_fuzzer.h new file mode 100644 index 00000000..6f60366c --- /dev/null +++ b/test/fuzztest/fileaccessextlistfile_fuzzer/fileaccessextlistfile_fuzzer.h @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef FILE_ACCESS_EXTLISTFILE_FUZZER_H +#define FILE_ACCESS_EXTLISTFILE_FUZZER_H + +#define FUZZ_PROJECT_NAME "fileaccessextlistfile_fuzzer" + +#endif \ No newline at end of file diff --git a/test/fuzztest/fileaccessextlistfile_fuzzer/project.xml b/test/fuzztest/fileaccessextlistfile_fuzzer/project.xml new file mode 100644 index 00000000..8cd95817 --- /dev/null +++ b/test/fuzztest/fileaccessextlistfile_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/test/fuzztest/fileaccessextmkdir_fuzzer/BUILD.gn b/test/fuzztest/fileaccessextmkdir_fuzzer/BUILD.gn new file mode 100644 index 00000000..c3071cbc --- /dev/null +++ b/test/fuzztest/fileaccessextmkdir_fuzzer/BUILD.gn @@ -0,0 +1,68 @@ +# Copyright (c) 2025 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +#####################hydra-fuzz################### +import("//build/config/features.gni") +import("//build/test.gni") +import("//foundation/filemanagement/user_file_service/filemanagement_aafwk.gni") +ohos_fuzztest("FileAccessExtMkdirFuzzTest") { + module_out_path = "user_file_service/user_file_service" + fuzz_config_file = + "${user_file_service_path}/test/fuzztest/fileaccessextmkdir_fuzzer" + include_dirs = [ + "${user_file_service_path}/interfaces/inner_api/file_access/include", + "${user_file_service_path}/test/fuzztest/privacy_comm/include", + "${user_file_service_path}/utils", + ] + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + sources = [ + "fileaccessextmkdir_fuzzer.cpp", + "${user_file_service_path}/test/fuzztest/privacy_comm/src/user_file_service_token_mock.cpp" + ] + + deps = [ + "${user_file_service_path}/interfaces/inner_api/file_access:file_access_ext_base_include", + "${user_file_service_path}/interfaces/inner_api/file_access:file_access_extension_ability_kit", + "${user_file_service_path}/services:file_access_service", + "${user_file_service_path}/services:file_access_service_base_include", + ] + + external_deps = [ + "ability_base:want", + "ability_base:zuri", + "ability_runtime:ability_context_native", + "ability_runtime:ability_manager", + "ability_runtime:app_manager", + "ability_runtime:runtime", + "ability_runtime:wantagent_innerkits", + "access_token:libaccesstoken_sdk", + "access_token:libnativetoken", + "access_token:libtoken_setproc", + "bundle_framework:appexecfwk_core", + "cJSON:cjson_static", + "c_utils:utils", + "hilog:libhilog", + "hitrace:hitrace_meter", + "ipc:ipc_core", + "safwk:system_ability_fwk", + "samgr:samgr_proxy", + "selinux_adapter:librestorecon", + ] + + defines = [ "private=public" ] +} diff --git a/test/fuzztest/fileaccessextmkdir_fuzzer/corpus/init b/test/fuzztest/fileaccessextmkdir_fuzzer/corpus/init new file mode 100644 index 00000000..7ade8a0f --- /dev/null +++ b/test/fuzztest/fileaccessextmkdir_fuzzer/corpus/init @@ -0,0 +1,16 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +FUZZ \ No newline at end of file diff --git a/test/fuzztest/fileaccessextmkdir_fuzzer/fileaccessextmkdir_fuzzer.cpp b/test/fuzztest/fileaccessextmkdir_fuzzer/fileaccessextmkdir_fuzzer.cpp new file mode 100644 index 00000000..095bf8ee --- /dev/null +++ b/test/fuzztest/fileaccessextmkdir_fuzzer/fileaccessextmkdir_fuzzer.cpp @@ -0,0 +1,119 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#include "fileaccessextmkdir_fuzzer.h" + +#include +#include + +#include "accesstoken_kit.h" +#include "file_access_helper.h" +#include "file_access_ext_base_proxy.h" +#include "file_info_shared_memory.h" +#include "iservice_registry.h" +#include "token_setproc.h" +#include "nativetoken_kit.h" + +#include "user_file_service_token_mock.h" + +namespace OHOS { +using namespace std; +using namespace FileAccessFwk; + +const int ABILITY_ID = 5003; +shared_ptr g_fah = nullptr; +const int UID_TRANSFORM_TMP = 20000000; +const int UID_DEFAULT = 0; + +template +T TypeCast(const uint8_t *data, int *pos = nullptr) +{ + if (pos) { + *pos += sizeof(T); + } + return *(reinterpret_cast(data)); +} + +shared_ptr GetFileAccessHelper() +{ + if (g_fah != nullptr) { + return g_fah; + } + auto saManager = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); + if (saManager == nullptr) { + return nullptr; + } + auto remoteObj = saManager->GetSystemAbility(ABILITY_ID); + AAFwk::Want want; + vector wantVec; + setuid(UID_TRANSFORM_TMP); + int ret = FileAccessHelper::GetRegisteredFileAccessExtAbilityInfo(wantVec); + if (ret != OHOS::FileAccessFwk::ERR_OK) { + printf("GetRegisteredFileAccessExtAbilityInfo failed."); + return nullptr; + } + bool sus = false; + for (size_t i = 0; i < wantVec.size(); i++) { + auto element = wantVec[i].GetElement(); + if (element.GetBundleName() == "com.ohos.UserFile.ExternalFileManager" && + element.GetAbilityName() == "FileExtensionAbility") { + want = wantVec[i]; + sus = true; + break; + } + } + if (!sus) { + printf("not found bundleName."); + return nullptr; + } + vector wants {want}; + g_fah = FileAccessHelper::Creator(remoteObj, wants); + setuid(UID_DEFAULT); + if (g_fah == nullptr) { + printf("creator fileAccessHelper return nullptr."); + return nullptr; + } + return g_fah; +} + +bool MkdirFuzzTest(sptr proxy, const uint8_t *data, size_t size) +{ + int len = size / 3; + Urie parent(string(reinterpret_cast(data), len)); + string displayName(string(reinterpret_cast(data + len), len)); + Urie newFile(string(reinterpret_cast(data + len + len), len)); + proxy->Mkdir(parent, displayName, newFile); + return true; +} +} // namespace OHOS + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) +{ + OHOS::UserFileServiceTokenMock tokenMock; + tokenMock.SetFileManagerToken(); + auto helper = OHOS::GetFileAccessHelper(); + if (helper == nullptr) { + printf("helper is nullptr."); + return false; + } + auto proxy = helper->GetProxyByBundleName(OHOS::EXTERNAL_BNUDLE_NAME); + if (proxy == nullptr) { + printf("get proxy failed."); + return 0; + } + + OHOS::MkdirFuzzTest(proxy, data, size); + return 0; +} diff --git a/test/fuzztest/fileaccessextmkdir_fuzzer/fileaccessextmkdir_fuzzer.h b/test/fuzztest/fileaccessextmkdir_fuzzer/fileaccessextmkdir_fuzzer.h new file mode 100644 index 00000000..714a45a3 --- /dev/null +++ b/test/fuzztest/fileaccessextmkdir_fuzzer/fileaccessextmkdir_fuzzer.h @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef FILE_ACCESS_EXTMKDIR_FUZZER_H +#define FILE_ACCESS_EXTMKDIR_FUZZER_H + +#define FUZZ_PROJECT_NAME "fileaccessextmkdir_fuzzer" + +#endif \ No newline at end of file diff --git a/test/fuzztest/fileaccessextmkdir_fuzzer/project.xml b/test/fuzztest/fileaccessextmkdir_fuzzer/project.xml new file mode 100644 index 00000000..8cd95817 --- /dev/null +++ b/test/fuzztest/fileaccessextmkdir_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/test/fuzztest/fileaccessextmove_fuzzer/BUILD.gn b/test/fuzztest/fileaccessextmove_fuzzer/BUILD.gn new file mode 100644 index 00000000..a1b30297 --- /dev/null +++ b/test/fuzztest/fileaccessextmove_fuzzer/BUILD.gn @@ -0,0 +1,68 @@ +# Copyright (c) 2025 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +#####################hydra-fuzz################### +import("//build/config/features.gni") +import("//build/test.gni") +import("//foundation/filemanagement/user_file_service/filemanagement_aafwk.gni") +ohos_fuzztest("FileAccessExtMoveFuzzTest") { + module_out_path = "user_file_service/user_file_service" + fuzz_config_file = + "${user_file_service_path}/test/fuzztest/fileaccessextmove_fuzzer" + include_dirs = [ + "${user_file_service_path}/interfaces/inner_api/file_access/include", + "${user_file_service_path}/test/fuzztest/privacy_comm/include", + "${user_file_service_path}/utils", + ] + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + sources = [ + "fileaccessextmove_fuzzer.cpp", + "${user_file_service_path}/test/fuzztest/privacy_comm/src/user_file_service_token_mock.cpp" + ] + + deps = [ + "${user_file_service_path}/interfaces/inner_api/file_access:file_access_ext_base_include", + "${user_file_service_path}/interfaces/inner_api/file_access:file_access_extension_ability_kit", + "${user_file_service_path}/services:file_access_service", + "${user_file_service_path}/services:file_access_service_base_include", + ] + + external_deps = [ + "ability_base:want", + "ability_base:zuri", + "ability_runtime:ability_context_native", + "ability_runtime:ability_manager", + "ability_runtime:app_manager", + "ability_runtime:runtime", + "ability_runtime:wantagent_innerkits", + "access_token:libaccesstoken_sdk", + "access_token:libnativetoken", + "access_token:libtoken_setproc", + "bundle_framework:appexecfwk_core", + "cJSON:cjson_static", + "c_utils:utils", + "hilog:libhilog", + "hitrace:hitrace_meter", + "ipc:ipc_core", + "safwk:system_ability_fwk", + "samgr:samgr_proxy", + "selinux_adapter:librestorecon", + ] + + defines = [ "private=public" ] +} diff --git a/test/fuzztest/fileaccessextmove_fuzzer/corpus/init b/test/fuzztest/fileaccessextmove_fuzzer/corpus/init new file mode 100644 index 00000000..7ade8a0f --- /dev/null +++ b/test/fuzztest/fileaccessextmove_fuzzer/corpus/init @@ -0,0 +1,16 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +FUZZ \ No newline at end of file diff --git a/test/fuzztest/fileaccessextmove_fuzzer/fileaccessextmove_fuzzer.cpp b/test/fuzztest/fileaccessextmove_fuzzer/fileaccessextmove_fuzzer.cpp new file mode 100644 index 00000000..ac3d7f43 --- /dev/null +++ b/test/fuzztest/fileaccessextmove_fuzzer/fileaccessextmove_fuzzer.cpp @@ -0,0 +1,119 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#include "fileaccessextmove_fuzzer.h" + +#include +#include + +#include "accesstoken_kit.h" +#include "file_access_helper.h" +#include "file_access_ext_base_proxy.h" +#include "file_info_shared_memory.h" +#include "iservice_registry.h" +#include "token_setproc.h" +#include "nativetoken_kit.h" + +#include "user_file_service_token_mock.h" + +namespace OHOS { +using namespace std; +using namespace FileAccessFwk; + +const int ABILITY_ID = 5003; +shared_ptr g_fah = nullptr; +const int UID_TRANSFORM_TMP = 20000000; +const int UID_DEFAULT = 0; + +template +T TypeCast(const uint8_t *data, int *pos = nullptr) +{ + if (pos) { + *pos += sizeof(T); + } + return *(reinterpret_cast(data)); +} + +shared_ptr GetFileAccessHelper() +{ + if (g_fah != nullptr) { + return g_fah; + } + auto saManager = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); + if (saManager == nullptr) { + return nullptr; + } + auto remoteObj = saManager->GetSystemAbility(ABILITY_ID); + AAFwk::Want want; + vector wantVec; + setuid(UID_TRANSFORM_TMP); + int ret = FileAccessHelper::GetRegisteredFileAccessExtAbilityInfo(wantVec); + if (ret != OHOS::FileAccessFwk::ERR_OK) { + printf("GetRegisteredFileAccessExtAbilityInfo failed."); + return nullptr; + } + bool sus = false; + for (size_t i = 0; i < wantVec.size(); i++) { + auto element = wantVec[i].GetElement(); + if (element.GetBundleName() == "com.ohos.UserFile.ExternalFileManager" && + element.GetAbilityName() == "FileExtensionAbility") { + want = wantVec[i]; + sus = true; + break; + } + } + if (!sus) { + printf("not found bundleName."); + return nullptr; + } + vector wants {want}; + g_fah = FileAccessHelper::Creator(remoteObj, wants); + setuid(UID_DEFAULT); + if (g_fah == nullptr) { + printf("creator fileAccessHelper return nullptr."); + return nullptr; + } + return g_fah; +} + +bool MoveFuzzTest(sptr proxy, const uint8_t *data, size_t size) +{ + int len = size / 3; + Urie sourceFile(string(reinterpret_cast(data), len)); + string targetParent(string(reinterpret_cast(data + len), len)); + Urie newFile(string(reinterpret_cast(data + len + len), len)); + proxy->Move(sourceFile, targetParent, newFile); + return true; +} +} // namespace OHOS + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) +{ + OHOS::UserFileServiceTokenMock tokenMock; + tokenMock.SetFileManagerToken(); + auto helper = OHOS::GetFileAccessHelper(); + if (helper == nullptr) { + printf("helper is nullptr."); + return false; + } + auto proxy = helper->GetProxyByBundleName(OHOS::EXTERNAL_BNUDLE_NAME); + if (proxy == nullptr) { + printf("get proxy failed."); + return 0; + } + + OHOS::MoveFuzzTest(proxy, data, size); + return 0; +} diff --git a/test/fuzztest/fileaccessextmove_fuzzer/fileaccessextmove_fuzzer.h b/test/fuzztest/fileaccessextmove_fuzzer/fileaccessextmove_fuzzer.h new file mode 100644 index 00000000..0dc29f0b --- /dev/null +++ b/test/fuzztest/fileaccessextmove_fuzzer/fileaccessextmove_fuzzer.h @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef FILE_ACCESS_EXTMOVE_FUZZER_H +#define FILE_ACCESS_EXTMOVE_FUZZER_H + +#define FUZZ_PROJECT_NAME "fileaccessextmove_fuzzer" + +#endif \ No newline at end of file diff --git a/test/fuzztest/fileaccessextmove_fuzzer/project.xml b/test/fuzztest/fileaccessextmove_fuzzer/project.xml new file mode 100644 index 00000000..8cd95817 --- /dev/null +++ b/test/fuzztest/fileaccessextmove_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/test/fuzztest/fileaccessextmovefile_fuzzer/BUILD.gn b/test/fuzztest/fileaccessextmovefile_fuzzer/BUILD.gn new file mode 100644 index 00000000..4d7f9e32 --- /dev/null +++ b/test/fuzztest/fileaccessextmovefile_fuzzer/BUILD.gn @@ -0,0 +1,68 @@ +# Copyright (c) 2025 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +#####################hydra-fuzz################### +import("//build/config/features.gni") +import("//build/test.gni") +import("//foundation/filemanagement/user_file_service/filemanagement_aafwk.gni") +ohos_fuzztest("FileAccessExtMoveFileFuzzTest") { + module_out_path = "user_file_service/user_file_service" + fuzz_config_file = + "${user_file_service_path}/test/fuzztest/fileaccessextmovefile_fuzzer" + include_dirs = [ + "${user_file_service_path}/interfaces/inner_api/file_access/include", + "${user_file_service_path}/test/fuzztest/privacy_comm/include", + "${user_file_service_path}/utils", + ] + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + sources = [ + "fileaccessextmovefile_fuzzer.cpp", + "${user_file_service_path}/test/fuzztest/privacy_comm/src/user_file_service_token_mock.cpp" + ] + + deps = [ + "${user_file_service_path}/interfaces/inner_api/file_access:file_access_ext_base_include", + "${user_file_service_path}/interfaces/inner_api/file_access:file_access_extension_ability_kit", + "${user_file_service_path}/services:file_access_service", + "${user_file_service_path}/services:file_access_service_base_include", + ] + + external_deps = [ + "ability_base:want", + "ability_base:zuri", + "ability_runtime:ability_context_native", + "ability_runtime:ability_manager", + "ability_runtime:app_manager", + "ability_runtime:runtime", + "ability_runtime:wantagent_innerkits", + "access_token:libaccesstoken_sdk", + "access_token:libnativetoken", + "access_token:libtoken_setproc", + "bundle_framework:appexecfwk_core", + "cJSON:cjson_static", + "c_utils:utils", + "hilog:libhilog", + "hitrace:hitrace_meter", + "ipc:ipc_core", + "safwk:system_ability_fwk", + "samgr:samgr_proxy", + "selinux_adapter:librestorecon", + ] + + defines = [ "private=public" ] +} diff --git a/test/fuzztest/fileaccessextmovefile_fuzzer/corpus/init b/test/fuzztest/fileaccessextmovefile_fuzzer/corpus/init new file mode 100644 index 00000000..7ade8a0f --- /dev/null +++ b/test/fuzztest/fileaccessextmovefile_fuzzer/corpus/init @@ -0,0 +1,16 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +FUZZ \ No newline at end of file diff --git a/test/fuzztest/fileaccessextmovefile_fuzzer/fileaccessextmovefile_fuzzer.cpp b/test/fuzztest/fileaccessextmovefile_fuzzer/fileaccessextmovefile_fuzzer.cpp new file mode 100644 index 00000000..3f0f5d70 --- /dev/null +++ b/test/fuzztest/fileaccessextmovefile_fuzzer/fileaccessextmovefile_fuzzer.cpp @@ -0,0 +1,120 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#include "fileaccessextmovefile_fuzzer.h" + +#include +#include + +#include "accesstoken_kit.h" +#include "file_access_helper.h" +#include "file_access_ext_base_proxy.h" +#include "file_info_shared_memory.h" +#include "iservice_registry.h" +#include "token_setproc.h" +#include "nativetoken_kit.h" + +#include "user_file_service_token_mock.h" + +namespace OHOS { +using namespace std; +using namespace FileAccessFwk; + +const int ABILITY_ID = 5003; +shared_ptr g_fah = nullptr; +const int UID_TRANSFORM_TMP = 20000000; +const int UID_DEFAULT = 0; + +template +T TypeCast(const uint8_t *data, int *pos = nullptr) +{ + if (pos) { + *pos += sizeof(T); + } + return *(reinterpret_cast(data)); +} + +shared_ptr GetFileAccessHelper() +{ + if (g_fah != nullptr) { + return g_fah; + } + auto saManager = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); + if (saManager == nullptr) { + return nullptr; + } + auto remoteObj = saManager->GetSystemAbility(ABILITY_ID); + AAFwk::Want want; + vector wantVec; + setuid(UID_TRANSFORM_TMP); + int ret = FileAccessHelper::GetRegisteredFileAccessExtAbilityInfo(wantVec); + if (ret != OHOS::FileAccessFwk::ERR_OK) { + printf("GetRegisteredFileAccessExtAbilityInfo failed."); + return nullptr; + } + bool sus = false; + for (size_t i = 0; i < wantVec.size(); i++) { + auto element = wantVec[i].GetElement(); + if (element.GetBundleName() == "com.ohos.UserFile.ExternalFileManager" && + element.GetAbilityName() == "FileExtensionAbility") { + want = wantVec[i]; + sus = true; + break; + } + } + if (!sus) { + printf("not found bundleName."); + return nullptr; + } + vector wants {want}; + g_fah = FileAccessHelper::Creator(remoteObj, wants); + setuid(UID_DEFAULT); + if (g_fah == nullptr) { + printf("creator fileAccessHelper return nullptr."); + return nullptr; + } + return g_fah; +} + +bool MoveFileFuzzTest(sptr proxy, const uint8_t *data, size_t size) +{ + int len = size / 3; + Urie sourceFile(string(reinterpret_cast(data), len)); + Urie targetParent(string(reinterpret_cast(data + len), len)); + string fileName(string(reinterpret_cast(data + len + len), len)); + Urie newFile; + proxy->MoveFile(sourceFile, targetParent, fileName, newFile); + return true; +} +} // namespace OHOS + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) +{ + OHOS::UserFileServiceTokenMock tokenMock; + tokenMock.SetFileManagerToken(); + auto helper = OHOS::GetFileAccessHelper(); + if (helper == nullptr) { + printf("helper is nullptr."); + return false; + } + auto proxy = helper->GetProxyByBundleName(OHOS::EXTERNAL_BNUDLE_NAME); + if (proxy == nullptr) { + printf("get proxy failed."); + return 0; + } + + OHOS::MoveFileFuzzTest(proxy, data, size); + return 0; +} diff --git a/test/fuzztest/fileaccessextmovefile_fuzzer/fileaccessextmovefile_fuzzer.h b/test/fuzztest/fileaccessextmovefile_fuzzer/fileaccessextmovefile_fuzzer.h new file mode 100644 index 00000000..2fcc14d2 --- /dev/null +++ b/test/fuzztest/fileaccessextmovefile_fuzzer/fileaccessextmovefile_fuzzer.h @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef FILE_ACCESS_EXTMOVEFILE_FUZZER_H +#define FILE_ACCESS_EXTMOVEFILE_FUZZER_H + +#define FUZZ_PROJECT_NAME "fileaccessextmovefile_fuzzer" + +#endif \ No newline at end of file diff --git a/test/fuzztest/fileaccessextmovefile_fuzzer/project.xml b/test/fuzztest/fileaccessextmovefile_fuzzer/project.xml new file mode 100644 index 00000000..8cd95817 --- /dev/null +++ b/test/fuzztest/fileaccessextmovefile_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/test/fuzztest/fileaccessextmoveitem_fuzzer/BUILD.gn b/test/fuzztest/fileaccessextmoveitem_fuzzer/BUILD.gn new file mode 100644 index 00000000..e3a8e9c2 --- /dev/null +++ b/test/fuzztest/fileaccessextmoveitem_fuzzer/BUILD.gn @@ -0,0 +1,68 @@ +# Copyright (c) 2025 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +#####################hydra-fuzz################### +import("//build/config/features.gni") +import("//build/test.gni") +import("//foundation/filemanagement/user_file_service/filemanagement_aafwk.gni") +ohos_fuzztest("FileAccessExtMoveItemFuzzTest") { + module_out_path = "user_file_service/user_file_service" + fuzz_config_file = + "${user_file_service_path}/test/fuzztest/fileaccessextmoveitem_fuzzer" + include_dirs = [ + "${user_file_service_path}/interfaces/inner_api/file_access/include", + "${user_file_service_path}/test/fuzztest/privacy_comm/include", + "${user_file_service_path}/utils", + ] + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + sources = [ + "fileaccessextmoveitem_fuzzer.cpp", + "${user_file_service_path}/test/fuzztest/privacy_comm/src/user_file_service_token_mock.cpp" + ] + + deps = [ + "${user_file_service_path}/interfaces/inner_api/file_access:file_access_ext_base_include", + "${user_file_service_path}/interfaces/inner_api/file_access:file_access_extension_ability_kit", + "${user_file_service_path}/services:file_access_service", + "${user_file_service_path}/services:file_access_service_base_include", + ] + + external_deps = [ + "ability_base:want", + "ability_base:zuri", + "ability_runtime:ability_context_native", + "ability_runtime:ability_manager", + "ability_runtime:app_manager", + "ability_runtime:runtime", + "ability_runtime:wantagent_innerkits", + "access_token:libaccesstoken_sdk", + "access_token:libnativetoken", + "access_token:libtoken_setproc", + "bundle_framework:appexecfwk_core", + "cJSON:cjson_static", + "c_utils:utils", + "hilog:libhilog", + "hitrace:hitrace_meter", + "ipc:ipc_core", + "safwk:system_ability_fwk", + "samgr:samgr_proxy", + "selinux_adapter:librestorecon", + ] + + defines = [ "private=public" ] +} diff --git a/test/fuzztest/fileaccessextmoveitem_fuzzer/corpus/init b/test/fuzztest/fileaccessextmoveitem_fuzzer/corpus/init new file mode 100644 index 00000000..7ade8a0f --- /dev/null +++ b/test/fuzztest/fileaccessextmoveitem_fuzzer/corpus/init @@ -0,0 +1,16 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +FUZZ \ No newline at end of file diff --git a/test/fuzztest/fileaccessextmoveitem_fuzzer/fileaccessextmoveitem_fuzzer.cpp b/test/fuzztest/fileaccessextmoveitem_fuzzer/fileaccessextmoveitem_fuzzer.cpp new file mode 100644 index 00000000..647d1d33 --- /dev/null +++ b/test/fuzztest/fileaccessextmoveitem_fuzzer/fileaccessextmoveitem_fuzzer.cpp @@ -0,0 +1,127 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#include "fileaccessextmoveitem_fuzzer.h" + +#include +#include + +#include "accesstoken_kit.h" +#include "file_access_helper.h" +#include "file_access_ext_base_proxy.h" +#include "file_info_shared_memory.h" +#include "iservice_registry.h" +#include "token_setproc.h" +#include "nativetoken_kit.h" + +#include "user_file_service_token_mock.h" + +namespace OHOS { +using namespace std; +using namespace FileAccessFwk; + +const int ABILITY_ID = 5003; +shared_ptr g_fah = nullptr; +const int UID_TRANSFORM_TMP = 20000000; +const int UID_DEFAULT = 0; + +template +T TypeCast(const uint8_t *data, int *pos = nullptr) +{ + if (pos) { + *pos += sizeof(T); + } + return *(reinterpret_cast(data)); +} + +shared_ptr GetFileAccessHelper() +{ + if (g_fah != nullptr) { + return g_fah; + } + auto saManager = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); + if (saManager == nullptr) { + return nullptr; + } + auto remoteObj = saManager->GetSystemAbility(ABILITY_ID); + AAFwk::Want want; + vector wantVec; + setuid(UID_TRANSFORM_TMP); + int ret = FileAccessHelper::GetRegisteredFileAccessExtAbilityInfo(wantVec); + if (ret != OHOS::FileAccessFwk::ERR_OK) { + printf("GetRegisteredFileAccessExtAbilityInfo failed."); + return nullptr; + } + bool sus = false; + for (size_t i = 0; i < wantVec.size(); i++) { + auto element = wantVec[i].GetElement(); + if (element.GetBundleName() == "com.ohos.UserFile.ExternalFileManager" && + element.GetAbilityName() == "FileExtensionAbility") { + want = wantVec[i]; + sus = true; + break; + } + } + if (!sus) { + printf("not found bundleName."); + return nullptr; + } + vector wants {want}; + g_fah = FileAccessHelper::Creator(remoteObj, wants); + setuid(UID_DEFAULT); + if (g_fah == nullptr) { + printf("creator fileAccessHelper return nullptr."); + return nullptr; + } + return g_fah; +} + +bool MoveItemFuzzTest(sptr proxy, const uint8_t *data, size_t size) +{ + if (data == nullptr || size < sizeof(bool)) { + return true; + } + + vector moveResult; + int32_t retCode = 0; + int pos = 0; + bool force = TypeCast(data, &pos); + int len = (size - pos) / 2; + Urie sourceFile(string(reinterpret_cast(data + pos), len)); + Urie targetParent(string(reinterpret_cast(data + pos + len), len)); + + proxy->MoveItem(sourceFile, targetParent, moveResult, retCode, force); + return true; +} +} // namespace OHOS + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) +{ + OHOS::UserFileServiceTokenMock tokenMock; + tokenMock.SetFileManagerToken(); + auto helper = OHOS::GetFileAccessHelper(); + if (helper == nullptr) { + printf("helper is nullptr."); + return false; + } + auto proxy = helper->GetProxyByBundleName(OHOS::EXTERNAL_BNUDLE_NAME); + if (proxy == nullptr) { + printf("get proxy failed."); + return 0; + } + + OHOS::MoveItemFuzzTest(proxy, data, size); + return 0; +} diff --git a/test/fuzztest/fileaccessextmoveitem_fuzzer/fileaccessextmoveitem_fuzzer.h b/test/fuzztest/fileaccessextmoveitem_fuzzer/fileaccessextmoveitem_fuzzer.h new file mode 100644 index 00000000..df8f6548 --- /dev/null +++ b/test/fuzztest/fileaccessextmoveitem_fuzzer/fileaccessextmoveitem_fuzzer.h @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef FILE_ACCESS_EXTMOVEITEM_FUZZER_H +#define FILE_ACCESS_EXTMOVEITEM_FUZZER_H + +#define FUZZ_PROJECT_NAME "fileaccessextmoveitem_fuzzer" + +#endif \ No newline at end of file diff --git a/test/fuzztest/fileaccessextmoveitem_fuzzer/project.xml b/test/fuzztest/fileaccessextmoveitem_fuzzer/project.xml new file mode 100644 index 00000000..8cd95817 --- /dev/null +++ b/test/fuzztest/fileaccessextmoveitem_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/test/fuzztest/fileaccessextopenfile_fuzzer/BUILD.gn b/test/fuzztest/fileaccessextopenfile_fuzzer/BUILD.gn new file mode 100644 index 00000000..afdd69c7 --- /dev/null +++ b/test/fuzztest/fileaccessextopenfile_fuzzer/BUILD.gn @@ -0,0 +1,68 @@ +# Copyright (c) 2025 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +#####################hydra-fuzz################### +import("//build/config/features.gni") +import("//build/test.gni") +import("//foundation/filemanagement/user_file_service/filemanagement_aafwk.gni") +ohos_fuzztest("FileAccessExtOpenFileFuzzTest") { + module_out_path = "user_file_service/user_file_service" + fuzz_config_file = + "${user_file_service_path}/test/fuzztest/fileaccessextopenfile_fuzzer" + include_dirs = [ + "${user_file_service_path}/interfaces/inner_api/file_access/include", + "${user_file_service_path}/test/fuzztest/privacy_comm/include", + "${user_file_service_path}/utils", + ] + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + sources = [ + "fileaccessextopenfile_fuzzer.cpp", + "${user_file_service_path}/test/fuzztest/privacy_comm/src/user_file_service_token_mock.cpp" + ] + + deps = [ + "${user_file_service_path}/interfaces/inner_api/file_access:file_access_ext_base_include", + "${user_file_service_path}/interfaces/inner_api/file_access:file_access_extension_ability_kit", + "${user_file_service_path}/services:file_access_service", + "${user_file_service_path}/services:file_access_service_base_include", + ] + + external_deps = [ + "ability_base:want", + "ability_base:zuri", + "ability_runtime:ability_context_native", + "ability_runtime:ability_manager", + "ability_runtime:app_manager", + "ability_runtime:runtime", + "ability_runtime:wantagent_innerkits", + "access_token:libaccesstoken_sdk", + "access_token:libnativetoken", + "access_token:libtoken_setproc", + "bundle_framework:appexecfwk_core", + "cJSON:cjson_static", + "c_utils:utils", + "hilog:libhilog", + "hitrace:hitrace_meter", + "ipc:ipc_core", + "safwk:system_ability_fwk", + "samgr:samgr_proxy", + "selinux_adapter:librestorecon", + ] + + defines = [ "private=public" ] +} diff --git a/test/fuzztest/fileaccessextopenfile_fuzzer/corpus/init b/test/fuzztest/fileaccessextopenfile_fuzzer/corpus/init new file mode 100644 index 00000000..7ade8a0f --- /dev/null +++ b/test/fuzztest/fileaccessextopenfile_fuzzer/corpus/init @@ -0,0 +1,16 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +FUZZ \ No newline at end of file diff --git a/test/fuzztest/fileaccessextopenfile_fuzzer/fileaccessextopenfile_fuzzer.cpp b/test/fuzztest/fileaccessextopenfile_fuzzer/fileaccessextopenfile_fuzzer.cpp new file mode 100644 index 00000000..047b6faa --- /dev/null +++ b/test/fuzztest/fileaccessextopenfile_fuzzer/fileaccessextopenfile_fuzzer.cpp @@ -0,0 +1,123 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +#include "fileaccessextopenfile_fuzzer.h" + +#include +#include + +#include "accesstoken_kit.h" +#include "file_access_helper.h" +#include "file_access_ext_base_proxy.h" +#include "file_info_shared_memory.h" +#include "iservice_registry.h" +#include "token_setproc.h" +#include "nativetoken_kit.h" + +#include "user_file_service_token_mock.h" + +namespace OHOS { +using namespace std; +using namespace FileAccessFwk; + +const int ABILITY_ID = 5003; +shared_ptr g_fah = nullptr; +const int UID_TRANSFORM_TMP = 20000000; +const int UID_DEFAULT = 0; + +template +T TypeCast(const uint8_t *data, int *pos = nullptr) +{ + if (pos) { + *pos += sizeof(T); + } + return *(reinterpret_cast(data)); +} + +shared_ptr GetFileAccessHelper() +{ + if (g_fah != nullptr) { + return g_fah; + } + auto saManager = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); + if (saManager == nullptr) { + return nullptr; + } + auto remoteObj = saManager->GetSystemAbility(ABILITY_ID); + AAFwk::Want want; + vector wantVec; + setuid(UID_TRANSFORM_TMP); + int ret = FileAccessHelper::GetRegisteredFileAccessExtAbilityInfo(wantVec); + if (ret != OHOS::FileAccessFwk::ERR_OK) { + printf("GetRegisteredFileAccessExtAbilityInfo failed."); + return nullptr; + } + bool sus = false; + for (size_t i = 0; i < wantVec.size(); i++) { + auto element = wantVec[i].GetElement(); + if (element.GetBundleName() == "com.ohos.UserFile.ExternalFileManager" && + element.GetAbilityName() == "FileExtensionAbility") { + want = wantVec[i]; + sus = true; + break; + } + } + if (!sus) { + printf("not found bundleName."); + return nullptr; + } + vector wants {want}; + g_fah = FileAccessHelper::Creator(remoteObj, wants); + setuid(UID_DEFAULT); + if (g_fah == nullptr) { + printf("creator fileAccessHelper return nullptr."); + return nullptr; + } + return g_fah; +} + +bool OpenFileFuzzTest(sptr proxy, const uint8_t *data, size_t size) +{ + if (data == nullptr || size < sizeof(int32_t) + sizeof(int)) { + return true; + } + + int pos = 0; + int32_t flags = TypeCast(data, &pos); + int fd = TypeCast(data + pos, &pos); + Urie uri(string(reinterpret_cast(data + pos), size - sizeof(int32_t) - sizeof(int))); + proxy->OpenFile(uri, flags, fd); + return true; +} +} // namespace OHOS + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) +{ + OHOS::UserFileServiceTokenMock tokenMock; + tokenMock.SetFileManagerToken(); + auto helper = OHOS::GetFileAccessHelper(); + if (helper == nullptr) { + printf("helper is nullptr."); + return false; + } + auto proxy = helper->GetProxyByBundleName(OHOS::EXTERNAL_BNUDLE_NAME); + if (proxy == nullptr) { + printf("get proxy failed."); + return 0; + } + + OHOS::OpenFileFuzzTest(proxy, data, size); + return 0; +} diff --git a/test/fuzztest/fileaccessextopenfile_fuzzer/fileaccessextopenfile_fuzzer.h b/test/fuzztest/fileaccessextopenfile_fuzzer/fileaccessextopenfile_fuzzer.h new file mode 100644 index 00000000..0ae07e2d --- /dev/null +++ b/test/fuzztest/fileaccessextopenfile_fuzzer/fileaccessextopenfile_fuzzer.h @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef FILE_ACCESS_EXTOPENFILE_FUZZER_H +#define FILE_ACCESS_EXTOPENFILE_FUZZER_H + +#define FUZZ_PROJECT_NAME "fileaccessextopenfile_fuzzer" + +#endif \ No newline at end of file diff --git a/test/fuzztest/fileaccessextopenfile_fuzzer/project.xml b/test/fuzztest/fileaccessextopenfile_fuzzer/project.xml new file mode 100644 index 00000000..8cd95817 --- /dev/null +++ b/test/fuzztest/fileaccessextopenfile_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + -- Gitee