From 32c57e93eae74cef0e2928f2d473aa4f1363c13d Mon Sep 17 00:00:00 2001 From: lyq Date: Mon, 30 Jun 2025 16:18:20 +0800 Subject: [PATCH 01/14] add fuzz Signed-off-by: lyq Change-Id: I238bd5d094d79dd99d7a9aefd62ceee354f655ae --- test/fuzztest/fuzztest_bundlemanager/BUILD.gn | 4 + .../bmscheckabilityenableinstall_fuzzer.cpp | 61 ---- .../bmsinstalldhostimpl_fuzzer/BUILD.gn | 190 +++++++++++ .../bmsinstalldhostimpl_fuzzer.cpp | 313 ++++++++++++++++++ .../bmsinstalldhostimpl_fuzzer.h | 21 ++ .../bmsinstalldhostimpl_fuzzer/corpus/init | 1 + .../bmsinstalldhostimpl_fuzzer/project.xml | 25 ++ .../bmsinstalldloadcallback_fuzzer/BUILD.gn | 190 +++++++++++ .../bmsinstalldloadcallback_fuzzer.cpp | 51 +++ .../bmsinstalldloadcallback_fuzzer.h | 21 ++ .../corpus/init | 1 + .../project.xml | 25 ++ .../bmsinstalldpermissionmgr_fuzzer/BUILD.gn | 190 +++++++++++ .../bmsinstalldpermissionmgr_fuzzer.cpp | 0 .../bmsinstalldpermissionmgr_fuzzer.h | 21 ++ .../corpus/init | 1 + .../project.xml | 25 ++ .../bmsinstalldservice_fuzzer/BUILD.gn | 187 +++++++++++ .../bmsinstalldservice_fuzzer.cpp | 51 +++ .../bmsinstalldservice_fuzzer.h | 21 ++ .../bmsinstalldservice_fuzzer/corpus/init | 1 + .../bmsinstalldservice_fuzzer/project.xml | 25 ++ 22 files changed, 1364 insertions(+), 61 deletions(-) create mode 100644 test/fuzztest/fuzztest_bundlemanager/bmsinstalldhostimpl_fuzzer/BUILD.gn create mode 100644 test/fuzztest/fuzztest_bundlemanager/bmsinstalldhostimpl_fuzzer/bmsinstalldhostimpl_fuzzer.cpp create mode 100644 test/fuzztest/fuzztest_bundlemanager/bmsinstalldhostimpl_fuzzer/bmsinstalldhostimpl_fuzzer.h create mode 100644 test/fuzztest/fuzztest_bundlemanager/bmsinstalldhostimpl_fuzzer/corpus/init create mode 100644 test/fuzztest/fuzztest_bundlemanager/bmsinstalldhostimpl_fuzzer/project.xml create mode 100644 test/fuzztest/fuzztest_bundlemanager/bmsinstalldloadcallback_fuzzer/BUILD.gn create mode 100644 test/fuzztest/fuzztest_bundlemanager/bmsinstalldloadcallback_fuzzer/bmsinstalldloadcallback_fuzzer.cpp create mode 100644 test/fuzztest/fuzztest_bundlemanager/bmsinstalldloadcallback_fuzzer/bmsinstalldloadcallback_fuzzer.h create mode 100644 test/fuzztest/fuzztest_bundlemanager/bmsinstalldloadcallback_fuzzer/corpus/init create mode 100644 test/fuzztest/fuzztest_bundlemanager/bmsinstalldloadcallback_fuzzer/project.xml create mode 100644 test/fuzztest/fuzztest_bundlemanager/bmsinstalldpermissionmgr_fuzzer/BUILD.gn create mode 100644 test/fuzztest/fuzztest_bundlemanager/bmsinstalldpermissionmgr_fuzzer/bmsinstalldpermissionmgr_fuzzer.cpp create mode 100644 test/fuzztest/fuzztest_bundlemanager/bmsinstalldpermissionmgr_fuzzer/bmsinstalldpermissionmgr_fuzzer.h create mode 100644 test/fuzztest/fuzztest_bundlemanager/bmsinstalldpermissionmgr_fuzzer/corpus/init create mode 100644 test/fuzztest/fuzztest_bundlemanager/bmsinstalldpermissionmgr_fuzzer/project.xml create mode 100644 test/fuzztest/fuzztest_bundlemanager/bmsinstalldservice_fuzzer/BUILD.gn create mode 100644 test/fuzztest/fuzztest_bundlemanager/bmsinstalldservice_fuzzer/bmsinstalldservice_fuzzer.cpp create mode 100644 test/fuzztest/fuzztest_bundlemanager/bmsinstalldservice_fuzzer/bmsinstalldservice_fuzzer.h create mode 100644 test/fuzztest/fuzztest_bundlemanager/bmsinstalldservice_fuzzer/corpus/init create mode 100644 test/fuzztest/fuzztest_bundlemanager/bmsinstalldservice_fuzzer/project.xml diff --git a/test/fuzztest/fuzztest_bundlemanager/BUILD.gn b/test/fuzztest/fuzztest_bundlemanager/BUILD.gn index aac85405bc..a9241dbc74 100644 --- a/test/fuzztest/fuzztest_bundlemanager/BUILD.gn +++ b/test/fuzztest/fuzztest_bundlemanager/BUILD.gn @@ -90,6 +90,10 @@ group("bundlemanagerfuzztest") { "bmsgetnameforuid_fuzzer:BMSGetNameForUidFuzzTest", "bmsgetpermissiondef_fuzzer:BMSGetPermissionDefFuzzTest", "bmshapmoduleinfo_fuzzer:BMSHapModuleInfoFuzzTest", + "bmsinstalldhostimpl_fuzzer:BMSInstalldHostImplFuzzTest", + "bmsinstalldloadcallback_fuzzer:BMSInstalldLoadCallbackFuzzTest", + "bmsinstalldpermissionmgr_fuzzer:BMSInstalldPermissionMgrFuzzTest", + "bmsinstalldservice_fuzzer:BMSInstalldServiceFuzzTest", "bmsinstallparam_fuzzer:BMSInstallParamFuzzTest", "bmsisexistfirstinstallbundleinfo_fuzzer:BMSIsExistFirstInstallBundleInfoFuzzTest", "bmsonqueryrpcidfinished_fuzzer:BMSOnQueryRpcIdFinishedFuzzTest", diff --git a/test/fuzztest/fuzztest_bundlemanager/bmscheckabilityenableinstall_fuzzer/bmscheckabilityenableinstall_fuzzer.cpp b/test/fuzztest/fuzztest_bundlemanager/bmscheckabilityenableinstall_fuzzer/bmscheckabilityenableinstall_fuzzer.cpp index 5f8a86cc78..e69de29bb2 100644 --- a/test/fuzztest/fuzztest_bundlemanager/bmscheckabilityenableinstall_fuzzer/bmscheckabilityenableinstall_fuzzer.cpp +++ b/test/fuzztest/fuzztest_bundlemanager/bmscheckabilityenableinstall_fuzzer/bmscheckabilityenableinstall_fuzzer.cpp @@ -1,61 +0,0 @@ -/* - * 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 -#include -#include -#include -#define private public -#include "bundle_distributed_manager.h" -#include "bmscheckabilityenableinstall_fuzzer.h" -#include "bms_fuzztest_util.h" - -using Want = OHOS::AAFwk::Want; -using namespace OHOS::AppExecFwk; -using namespace OHOS::AppExecFwk::BMSFuzzTestUtil; -namespace OHOS { -std::string DEVICE_ID_NORMAL = "deviceId"; -std::string BUNDLE_NAME_TEST = "com.example.bundlekit.test"; -std::string MODULE_NAME_MY_APPLICATION = "com.example.MyModuleName"; -std::string ABILITY_NAME_MY_APPLICATION = "com.example.MyApplication.MainAbility"; -bool DoSomethingInterestingWithMyAPI(const uint8_t* data, size_t size) -{ - std::shared_ptr BundleDistributedManager_ = - std::make_shared(); - if (BundleDistributedManager_ == nullptr) { - return false; - } - FuzzedDataProvider fdp(data, size); - Want want; - std::string deviceId = DEVICE_ID_NORMAL; - std::string bundleName = BUNDLE_NAME_TEST; - std::string moduleName = MODULE_NAME_MY_APPLICATION; - std::string abilityName = ABILITY_NAME_MY_APPLICATION; - want.SetElementName(deviceId, bundleName, moduleName, abilityName); - int32_t missionId = fdp.ConsumeIntegral(); - int32_t userId = GenerateRandomUser(fdp); - sptr callerToken = nullptr; - BundleDistributedManager_->CheckAbilityEnableInstall(want, missionId, userId, callerToken); - return true; -} -} - -// Fuzzer entry point. -extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) -{ - // Run your code on data. - OHOS::DoSomethingInterestingWithMyAPI(data, size); - return 0; -} \ No newline at end of file diff --git a/test/fuzztest/fuzztest_bundlemanager/bmsinstalldhostimpl_fuzzer/BUILD.gn b/test/fuzztest/fuzztest_bundlemanager/bmsinstalldhostimpl_fuzzer/BUILD.gn new file mode 100644 index 0000000000..681550070c --- /dev/null +++ b/test/fuzztest/fuzztest_bundlemanager/bmsinstalldhostimpl_fuzzer/BUILD.gn @@ -0,0 +1,190 @@ +# 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/ohos.gni") +import("//build/test.gni") +import("../../../../appexecfwk.gni") +import("../../../../services/bundlemgr/appexecfwk_bundlemgr.gni") +module_output_path = fuzz_test_path + +##############################fuzztest########################################## +ohos_fuzztest("BMSInstalldHostImplFuzzTest") { + fuzz_config_file = "../../../fuzztest/fuzztest_bundlemanager/bmsinstalldhostimpl_fuzzer" + + use_exceptions = true + module_out_path = module_output_path + include_dirs = [ + "${test_path}/fuzztest", + "${services_path}/bundlemgr/include/installd", + ] + sources = bundle_mgr_source + sources += [ + "${services_path}/bundlemgr/src/aot/aot_executor.cpp", + "${services_path}/bundlemgr/src/installd/installd_host_impl.cpp", + "${services_path}/bundlemgr/src/installd/installd_operator.cpp", + "${services_path}/bundlemgr/src/installd/installd_service.cpp", + "${services_path}/bundlemgr/src/installd/installd_permission_mgr.cpp", + ] + + sources += bundle_install_sources + + sources += [ "bmsinstalldhostimpl_fuzzer.cpp" ] + + configs = [ "${services_path}/bundlemgr/test:bundlemgr_test_config" ] + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + + deps = [ "${core_path}:appexecfwk_core" ] + deps += bundle_install_deps + + external_deps = [ + "ability_base:want", + "ability_runtime:app_manager", + "access_token:el5_filekey_manager_sdk", + "access_token:libprivacy_sdk", + "access_token:libtokenid_sdk", + "appspawn:hnpapi", + "appverify:libhapverify", + "bounds_checking_function:libsec_shared", + "common_event_service:cesfwk_innerkits", + "eventhandler:libeventhandler", + "hilog:libhilog", + "hitrace:hitrace_meter", + "init:libbegetutil", + "jsoncpp:jsoncpp", + "safwk:system_ability_fwk", + "samgr:samgr_proxy", + "selinux_adapter:librestorecon", + ] + external_deps += bundle_install_external_deps + + defines = [] + if (code_signature_enable) { + sources += [ + "${services_path}/bundlemgr/src/aot/aot_sign_data_cache_mgr.cpp", + "${services_path}/bundlemgr/src/code_sign_helper.cpp", + ] + include_dirs += [ "${services_path}/bundlemgr/include" ] + external_deps += [ + "bounds_checking_function:libsec_shared", + "code_signature:libcode_sign_utils", + "ets_runtime:libcompiler_service", + ] + defines += [ "CODE_SIGNATURE_ENABLE" ] + } + + if (configpolicy_enable) { + external_deps += [ "config_policy:configpolicy_util" ] + defines += [ "CONFIG_POLOCY_ENABLE" ] + } + + if (bundle_framework_app_control) { + defines += [ "BUNDLE_FRAMEWORK_APP_CONTROL" ] + sources += [ + "${services_path}/bundlemgr/src/app_control/app_control_manager.cpp", + "${services_path}/bundlemgr/src/app_control/app_control_manager_host_impl.cpp", + "${services_path}/bundlemgr/src/app_control/app_control_manager_rdb.cpp", + "${services_path}/bundlemgr/src/app_control/app_jump_interceptor_event_subscriber.cpp", + "${services_path}/bundlemgr/src/app_control/app_jump_interceptor_manager_rdb.cpp", + ] + include_dirs += [ "${services_path}/bundlemgr/include/app_control" ] + external_deps += [ "c_utils:utils" ] + } + if (current_cpu == "arm64") { + defines += [ "USE_BUNDLE_EXTENSION" ] + } + + if (build_selinux) { + external_deps += [ "selinux_adapter:libhap_restorecon" ] + } + if (account_enable) { + external_deps += [ "os_account:os_account_innerkits" ] + defines += [ "ACCOUNT_ENABLE" ] + } + if (bundle_framework_free_install) { + sources += aging + sources += free_install + sources += distributed_manager + external_deps += [ + "ability_runtime:ability_manager", + "ability_runtime:app_manager", + "battery_manager:batterysrv_client", + "device_usage_statistics:usagestatsinner", + "display_manager:displaymgr", + "power_manager:powermgr_client", + "syscap_codec:syscap_interface_shared", + ] + defines += [ "BUNDLE_FRAMEWORK_FREE_INSTALL" ] + } + if (global_resmgr_enable) { + defines += [ "GLOBAL_RESMGR_ENABLE" ] + external_deps += [ "resource_management:global_resmgr" ] + } + if (hicollie_enable) { + external_deps += [ "hicollie:libhicollie" ] + defines += [ "HICOLLIE_ENABLE" ] + } + + if (hisysevent_enable) { + sources += [ "${services_path}/bundlemgr/src/inner_event_report.cpp" ] + external_deps += [ "hisysevent:libhisysevent" ] + defines += [ "HISYSEVENT_ENABLE" ] + } + + if (bundle_framework_quick_fix) { + include_dirs += [ "${services_path}/bundlemgr/src/include/quick_fix" ] + sources += quick_fix + defines += [ "BUNDLE_FRAMEWORK_QUICK_FIX" ] + } + + if (storage_service_enable) { + external_deps += [ "storage_service:storage_manager_sa_proxy" ] + defines += [ "STORAGE_SERVICE_ENABLE" ] + } + + external_deps += [ "kv_store:distributeddata_inner" ] + configs += [ "${services_path}/bundlemgr:rdb_config" ] + external_deps += [ "relational_store:native_rdb" ] + sources += [ + "${services_path}/bundlemgr/src/bundle_data_storage_rdb.cpp", + "${services_path}/bundlemgr/src/preinstall_data_storage_rdb.cpp", + "${services_path}/bundlemgr/src/rdb/bms_rdb_open_callback.cpp", + "${services_path}/bundlemgr/src/rdb/rdb_data_manager.cpp", + ] + if (udmf_enabled) { + defines += [ "BUNDLE_FRAMEWORK_UDMF_ENABLED" ] + external_deps += [ "udmf:udmf_client" ] + external_deps += [ "udmf:utd_client" ] + } + + if (user_auth_framework_impl_enabled) { + external_deps += [ "user_auth_framework:userauth_client" ] + defines += [ "BMS_USER_AUTH_FRAMEWORK_ENABLED" ] + include_dirs += [ "${services_path}/bundlemgr/include/user_auth" ] + sources += user_auth + } + + if (bms_device_info_manager_part_enabled) { + external_deps += [ + "device_info_manager:distributed_device_profile_common", + "device_info_manager:distributed_device_profile_sdk", + ] + defines += [ "BMS_DEVICE_INFO_MANAGER_ENABLE" ] + } +} \ No newline at end of file diff --git a/test/fuzztest/fuzztest_bundlemanager/bmsinstalldhostimpl_fuzzer/bmsinstalldhostimpl_fuzzer.cpp b/test/fuzztest/fuzztest_bundlemanager/bmsinstalldhostimpl_fuzzer/bmsinstalldhostimpl_fuzzer.cpp new file mode 100644 index 0000000000..2abcbb1d26 --- /dev/null +++ b/test/fuzztest/fuzztest_bundlemanager/bmsinstalldhostimpl_fuzzer/bmsinstalldhostimpl_fuzzer.cpp @@ -0,0 +1,313 @@ +/* + * 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 +#include +#include +#define private public +#include "installd_host_impl.h" +#include "bmsinstalldhostimpl_fuzzer.h" +#include "bms_fuzztest_util.h" + +using namespace OHOS::AppExecFwk; +using namespace OHOS::AppExecFwk::BMSFuzzTestUtil; +namespace OHOS { +bool DoSomethingInterestingWithMyAPI(const uint8_t* data, size_t size) +{ + auto installdhostimpl = std::make_shared(); + if (installdhostimpl == nullptr) { + return false; + } + FuzzedDataProvider fdp(data, size); + std::string bundle = ""; + std::string modulePath = ""; + std::string path = ""; + std::string path2 = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH); + std::string bundleDir = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH); + std::string srcModulePath = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH); + std::string targetPath = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH); + std::string targetSoPath = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH); + std::string filePath = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH); + std::string oldSoPath = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH); + std::string diffFilePath = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH); + std::string newSoPath = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH); + std::string srcPath = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH); + std::string realSoFilesPath = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH); + std::string hnpRootPath = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH); + std::string hapPath = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH); + std::string tmpSoPath = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH); + std::string destinationPath = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH); + std::string originPath = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH); + std::string cpuAbi = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH); + ExtractParam param; + param.srcPath = ""; + param.targetPath = ""; + param.cpuAbi = ""; + ExtractParam extractParam; + extractParam.srcPath = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH); + extractParam.targetPath = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH); + extractParam.cpuAbi = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH); + std::string packageInfo = ""; + std::string hnpPackageInfo = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH); + std::string userId = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH); + int32_t userId2 = GenerateRandomUser(fdp); + int userId3 = fdp.ConsumeIntegral(); + std::string packageName = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH); + AOTArgs aotArgs; + std::vector pendSignData; + std::string anFileName = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH); + std::vector signData; + std::vector dirs = GenerateStringArray(fdp); + std::string oldPath = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH); + std::string newPath = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH); + std::string bundleBackupDir = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH); + std::string bundleName = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH); + int32_t uid = fdp.ConsumeIntegral(); + int32_t gid = fdp.ConsumeIntegral(); + CreateDirParam createDirParam; + createDirParam.isPreInstallApp = false; + createDirParam.debug = false; + createDirParam.isDlpSandbox = false; + createDirParam.bundleName = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH); + createDirParam.userId = GenerateRandomUser(fdp);; + createDirParam.uid = fdp.ConsumeIntegral(); + createDirParam.gid = fdp.ConsumeIntegral(); + createDirParam.appIndex = fdp.ConsumeIntegral(); + createDirParam.apl = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH); + createDirParam.uuid = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH); + createDirParam.extensionDirs.push_back("com.acts.example"); + CreateDirParam createDirParam2; + createDirParam2.bundleName = ""; + createDirParam2.userId = -1; + createDirParam2.uid = -1; + createDirParam2.gid = -1; + CodeSignatureParam codeSignatureParam; + codeSignatureParam.modulePath = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH); + codeSignatureParam.targetSoPath = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH); + codeSignatureParam.signatureFileDir = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH); + codeSignatureParam.appIdentifier = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH); + CodeSignatureParam codeSignatureParam2; + codeSignatureParam2.modulePath = ""; + std::vector createDirParams; + std::string parentDir = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH); + std::vector extensionDirs = GenerateStringArray(fdp); + std::vector extensionDirs2; + std::string el = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH); + int32_t mode = fdp.ConsumeIntegral(); + std::string bundleDataDir = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH); + int appIndex = fdp.ConsumeIntegral(); + int32_t appIndex2 = fdp.ConsumeIntegral(); + std::string dir = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH); + std::string dir2 = ""; + std::string srcDir = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH); + std::string desDir = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH); + std::string moduleDir = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH); + std::string extensionBundleDir = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH); + int64_t statSize = fdp.ConsumeIntegral(); + std::string dataDir = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH); + std::vector moduleNameList = GenerateStringArray(fdp); + uint32_t statFlag = fdp.ConsumeIntegral(); + std::vector bundleNames = GenerateStringArray(fdp); + std::unordered_map uidMap = {{"com.example.bundlekit.test", 10000}}; + std::unordered_multimap dirMap = {}; + std::vector bundleStats2; + std::vector bundleStats; + std::vector uids; + bool isRealPath = fdp.ConsumeBool(); + bool isPreInstallApp = fdp.ConsumeBool(); + bool debug = fdp.ConsumeBool(); + bool isDlpSandbox = fdp.ConsumeBool(); + bool isExist = fdp.ConsumeBool(); + bool isDirEmpty = fdp.ConsumeBool(); + bool isEncryption = fdp.ConsumeBool(); + bool async = fdp.ConsumeBool(); + std::string apl = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH); + unsigned int hapFlags = fdp.ConsumeIntegral(); + std::vector cachePath = GenerateStringArray(fdp); + ScanMode scanMode; + ResultMode resultMode; + std::vector paths = GenerateStringArray(fdp); + std::string signatureFilePath = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH); + std::string file = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH); + FileStat fileStat; + std::vector dirVec = GenerateStringArray(fdp); + std::string sourceDir = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH); + std::string destinationDir = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH); + std::vector fileNames = GenerateStringArray(fdp); + CheckEncryptionParam checkEncryptionParam; + checkEncryptionParam.modulePath = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH); + checkEncryptionParam.targetSoPath = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH); + checkEncryptionParam.appIdentifier = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH); + CheckEncryptionParam checkEncryptionParam2; + checkEncryptionParam2.modulePath = ""; + int32_t profileBlockLength = fdp.ConsumeIntegral(); + unsigned char *profileBlock = new unsigned char[0]; + std::string prefix = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH); + EncryptionParam encryptionParam; + encryptionParam.bundleName = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH); + encryptionParam.groupId = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH); + encryptionParam.userId = GenerateRandomUser(fdp); + EncryptionParam encryptionParam2; + encryptionParam2.bundleName = ""; + encryptionParam2.groupId = ""; + std::string keyId = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH); + std::vector extensionBundleDirs = GenerateStringArray(fdp); + std::vector extensionBundleDirs2; + std::vector typeList = GenerateStringArray(fdp); + std::vector sourcePaths = GenerateStringArray(fdp); + std::vector sourcePaths2; + std::vector params; + std::vector uuidList =GenerateStringArray(fdp); + std::vector uuidList2; + nlohmann::json object; + nlohmann::json jsonBuf; + std::string extensionTypeName = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH); + std::string uuid = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH); + + installdhostimpl->CreateBundleDir(bundle); + installdhostimpl->CreateBundleDir(bundleDir); + installdhostimpl->ExtractModuleFiles(modulePath, path, targetSoPath, cpuAbi); + installdhostimpl->ExtractModuleFiles(srcModulePath, targetPath, targetSoPath, cpuAbi); + installdhostimpl->ExtractFiles(param); + installdhostimpl->ExtractFiles(extractParam); + installdhostimpl->ExtractHnpFiles(packageInfo, param); + installdhostimpl->ExtractHnpFiles(hnpPackageInfo, extractParam); + installdhostimpl->ProcessBundleInstallNative(userId, hnpRootPath, hapPath, cpuAbi, packageName); + installdhostimpl->ProcessBundleUnInstallNative(userId, packageName); + installdhostimpl->ExecuteAOT(aotArgs, pendSignData); + installdhostimpl->PendSignAOT(anFileName, signData); + installdhostimpl->DeleteUninstallTmpDirs(dirs); + installdhostimpl->RenameModuleDir(path, modulePath); + installdhostimpl->RenameModuleDir(oldPath, newPath); + installdhostimpl->CreateSharefilesDataDirEl2(createDirParam); + installdhostimpl->CreateBundleDataDirWithVector(createDirParams); + installdhostimpl->AddUserDirDeleteDfx(userId2); + installdhostimpl->AclSetDir(false, dir, false, false); + installdhostimpl->AclSetDir(true, dir, true, false); + installdhostimpl->AclSetDir(true, dir, false, true); + installdhostimpl->AclSetDir(true, dir, false, false); + installdhostimpl->AclSetExtensionDirs(false, parentDir, extensionDirs, false, false); + installdhostimpl->AclSetExtensionDirs(true, parentDir, extensionDirs, false, false); + installdhostimpl->AclSetExtensionDirs(true, parentDir, extensionDirs2, false, false); + installdhostimpl->CreateBundleDataDir(createDirParam); + installdhostimpl->CreateBundleDataDir(createDirParam2); + installdhostimpl->CreateBundleDataDirWithEl(createDirParam); + installdhostimpl->CreateBundleDataDirWithEl(createDirParam2); + installdhostimpl->CreateCommonDataDir(createDirParam, el); + installdhostimpl->CreateEl2DataDir(createDirParam); + installdhostimpl->CreateExtensionDir(createDirParam, parentDir, mode, gid, false); + installdhostimpl->CreateExtensionDir(createDirParam2, parentDir, mode, gid, false); + installdhostimpl->CreateExtensionDir(createDirParam2, parentDir, mode, gid, true); + installdhostimpl->RemoveBundleDataDir("", userId2, true, false); + installdhostimpl->RemoveBundleDataDir(bundleName, userId2, true, false); + installdhostimpl->RemoveBundleDataDir(bundleName, userId2, false, false); + installdhostimpl->RemoveModuleDataDir(moduleDir, userId3); + installdhostimpl->RemoveModuleDataDir(dir2, userId3); + installdhostimpl->RemoveDir(dir); + installdhostimpl->RemoveDir(dir2); + installdhostimpl->GetDiskUsage(dir, statSize, isRealPath); + installdhostimpl->GetDiskUsageFromPath(paths, statSize); + installdhostimpl->CleanBundleDataDir(dir2); + installdhostimpl->CleanBundleDataDir(dataDir); + installdhostimpl->CleanBundleDataDirByName(bundle, userId3, appIndex); + installdhostimpl->CleanBundleDataDirByName(bundleName, userId3, appIndex); + installdhostimpl->GetBundleDataDir(el, userId3); + installdhostimpl->GetAppDataPath(bundleName, el, userId2, appIndex2); + installdhostimpl->GetAppCacheSize(bundleName, userId2, appIndex2, moduleNameList); + installdhostimpl->GetBundleStats(bundle, userId2, bundleStats, uid, appIndex2, statFlag, moduleNameList); + installdhostimpl->GetBundleStats(bundleName, userId2, bundleStats, uid, appIndex2, statFlag, moduleNameList); + installdhostimpl->BatchGetBundleStats(bundleNames, userId3, uidMap, bundleStats2); + installdhostimpl->GetAllBundleStats(userId2, bundleStats, uids); + installdhostimpl->GetHapFlags(isPreInstallApp, debug, isDlpSandbox); + installdhostimpl->SetDirApl(dir, bundleName, apl, isPreInstallApp, debug); + installdhostimpl->SetDirApl(dir, bundleName, apl, hapFlags); + installdhostimpl->SetArkStartupCacheApl(dir); + installdhostimpl->GetBundleCachePath(dir, cachePath); + installdhostimpl->GetBundleCachePath(dir2, cachePath); + installdhostimpl->ScanDir(dir, ScanMode::SUB_FILE_ALL, ResultMode::ABSOLUTE_PATH, paths); + installdhostimpl->ScanDir(dir2, ScanMode::SUB_FILE_ALL, ResultMode::ABSOLUTE_PATH, paths); + installdhostimpl->MoveFile(oldPath, newPath); + installdhostimpl->CopyFile(oldPath, newPath, path); + installdhostimpl->CopyFile(oldPath, newPath, signatureFilePath); + installdhostimpl->Mkdir(dir2, mode, uid, gid); + installdhostimpl->Mkdir(dir, mode, uid, gid); + installdhostimpl->GetFileStat(file, fileStat); + installdhostimpl->ExtractDiffFiles(path, path, cpuAbi); + installdhostimpl->ExtractDiffFiles(filePath, targetPath, cpuAbi); + installdhostimpl->ApplyDiffPatch(path, path, path, uid); + installdhostimpl->ApplyDiffPatch(oldSoPath, diffFilePath, newSoPath, uid); + installdhostimpl->IsExistDir(dir, isExist); + installdhostimpl->IsExistFile(path2, isExist); + installdhostimpl->IsExistApFile(path2, isExist); + installdhostimpl->IsDirEmpty(dir, isDirEmpty); + installdhostimpl->ObtainQuickFixFileDir(dir, dirVec); + installdhostimpl->CopyFiles(sourceDir, destinationDir); + installdhostimpl->GetNativeLibraryFileNames(path, cpuAbi, fileNames); + installdhostimpl->GetNativeLibraryFileNames(filePath, cpuAbi, fileNames); + installdhostimpl->VerifyCodeSignature(codeSignatureParam); + installdhostimpl->VerifyCodeSignature(codeSignatureParam2); + installdhostimpl->CheckEncryption(checkEncryptionParam, isEncryption); + installdhostimpl->CheckEncryption(checkEncryptionParam2, isEncryption); + installdhostimpl->MoveFiles(srcDir, desDir); + installdhostimpl->MoveFiles(dir2, desDir); + installdhostimpl->ExtractDriverSoFiles(srcPath, dirMap); + installdhostimpl->ExtractEncryptedSoFiles(hapPath, realSoFilesPath, cpuAbi, tmpSoPath, uid); + installdhostimpl->VerifyCodeSignatureForHap(codeSignatureParam); + installdhostimpl->DeliverySignProfile(bundleName, profileBlockLength, profileBlock); + installdhostimpl->RemoveSignProfile(bundleName); + installdhostimpl->CheckPathValid(path, prefix); + installdhostimpl->CheckPathValid(path2, prefix); + installdhostimpl->SetEncryptionPolicy(encryptionParam, keyId); + installdhostimpl->SetEncryptionPolicy(encryptionParam2, keyId); + installdhostimpl->DeleteEncryptionKeyId(encryptionParam); + installdhostimpl->DeleteEncryptionKeyId(encryptionParam2); + installdhostimpl->RemoveExtensionDir(userId2, extensionBundleDirs); + installdhostimpl->RemoveExtensionDir(userId2, extensionBundleDirs2); + installdhostimpl->RemoveExtensionDir(userId2, extensionBundleDir); + installdhostimpl->IsExistExtensionDir(userId2, extensionBundleDir, isExist); + installdhostimpl->CreateExtensionDataDir(createDirParam); + installdhostimpl->CreateExtensionDataDir(createDirParam2); + installdhostimpl->GetExtensionSandboxTypeList(typeList); + installdhostimpl->LoadNeedCreateSandbox(object, typeList); + installdhostimpl->LoadExtensionNeedCreateSandbox(object, extensionTypeName); + installdhostimpl->ReadFileIntoJson(filePath, jsonBuf); + installdhostimpl->InnerRemoveAtomicServiceBundleDataDir(bundleName, userId2, async); + installdhostimpl->InnerRemoveBundleDataDir(bundleName, userId2, async); + installdhostimpl->MigrateData(sourcePaths, destinationPath); + installdhostimpl->MigrateData(sourcePaths2, destinationPath); + installdhostimpl->MoveHapToCodeDir(originPath, targetPath); + installdhostimpl->GetGroupDirPath(el, userId2, uuid); + installdhostimpl->CreateDataGroupDirs(params); + installdhostimpl->CreateDataGroupDir(createDirParam); + installdhostimpl->CreateDataGroupDir(createDirParam2); + installdhostimpl->DeleteDataGroupDirs(uuidList, userId2); + installdhostimpl->DeleteDataGroupDirs(uuidList2, userId2); + installdhostimpl->DeleteEl5DataGroupDirs(uuidList, userId2); + installdhostimpl->DeleteEl5DataGroupDirs(uuidList2, userId2); + installdhostimpl->ClearDir(dir); + installdhostimpl->ClearDir(dir2); + installdhostimpl->GetExtensionConfigPath(); + installdhostimpl->StopAOT(); + return true; +} +} + +// Fuzzer entry point. +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + // Run your code on data. + OHOS::DoSomethingInterestingWithMyAPI(data, size); + return 0; +} \ No newline at end of file diff --git a/test/fuzztest/fuzztest_bundlemanager/bmsinstalldhostimpl_fuzzer/bmsinstalldhostimpl_fuzzer.h b/test/fuzztest/fuzztest_bundlemanager/bmsinstalldhostimpl_fuzzer/bmsinstalldhostimpl_fuzzer.h new file mode 100644 index 0000000000..5cf13f0b5b --- /dev/null +++ b/test/fuzztest/fuzztest_bundlemanager/bmsinstalldhostimpl_fuzzer/bmsinstalldhostimpl_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 TEST_FUZZTEST_BMS_INSTALLD_HOST_IMPL_FUZZER_H +#define TEST_FUZZTEST_BMS_INSTALLD_HOST_IMPL_FUZZER_H + +#define FUZZ_PROJECT_NAME "bmsinstalldhostimpl_fuzzer" + +#endif \ No newline at end of file diff --git a/test/fuzztest/fuzztest_bundlemanager/bmsinstalldhostimpl_fuzzer/corpus/init b/test/fuzztest/fuzztest_bundlemanager/bmsinstalldhostimpl_fuzzer/corpus/init new file mode 100644 index 0000000000..6b7212c8a6 --- /dev/null +++ b/test/fuzztest/fuzztest_bundlemanager/bmsinstalldhostimpl_fuzzer/corpus/init @@ -0,0 +1 @@ +FUZZ \ No newline at end of file diff --git a/test/fuzztest/fuzztest_bundlemanager/bmsinstalldhostimpl_fuzzer/project.xml b/test/fuzztest/fuzztest_bundlemanager/bmsinstalldhostimpl_fuzzer/project.xml new file mode 100644 index 0000000000..226522bd2a --- /dev/null +++ b/test/fuzztest/fuzztest_bundlemanager/bmsinstalldhostimpl_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 10000 + + 300 + + 4096 + + diff --git a/test/fuzztest/fuzztest_bundlemanager/bmsinstalldloadcallback_fuzzer/BUILD.gn b/test/fuzztest/fuzztest_bundlemanager/bmsinstalldloadcallback_fuzzer/BUILD.gn new file mode 100644 index 0000000000..8ff566869a --- /dev/null +++ b/test/fuzztest/fuzztest_bundlemanager/bmsinstalldloadcallback_fuzzer/BUILD.gn @@ -0,0 +1,190 @@ +# 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/ohos.gni") +import("//build/test.gni") +import("../../../../appexecfwk.gni") +import("../../../../services/bundlemgr/appexecfwk_bundlemgr.gni") +module_output_path = fuzz_test_path + +##############################fuzztest########################################## +ohos_fuzztest("BMSInstalldLoadCallbackFuzzTest") { + fuzz_config_file = "../../../fuzztest/fuzztest_bundlemanager/bmsinstalldloadcallback_fuzzer" + + use_exceptions = true + module_out_path = module_output_path + include_dirs = [ + "${test_path}/fuzztest", + "${services_path}/bundlemgr/include/installd", + ] + sources = bundle_mgr_source + sources += [ + "${services_path}/bundlemgr/src/aot/aot_executor.cpp", + "${services_path}/bundlemgr/src/installd/installd_host_impl.cpp", + "${services_path}/bundlemgr/src/installd/installd_operator.cpp", + "${services_path}/bundlemgr/src/installd/installd_service.cpp", + "${services_path}/bundlemgr/src/installd/installd_permission_mgr.cpp", + ] + + sources += bundle_install_sources + + sources += [ "bmsinstalldloadcallback_fuzzer.cpp" ] + + configs = [ "${services_path}/bundlemgr/test:bundlemgr_test_config" ] + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + + deps = [ "${core_path}:appexecfwk_core" ] + deps += bundle_install_deps + + external_deps = [ + "ability_base:want", + "ability_runtime:app_manager", + "access_token:el5_filekey_manager_sdk", + "access_token:libprivacy_sdk", + "access_token:libtokenid_sdk", + "appspawn:hnpapi", + "appverify:libhapverify", + "bounds_checking_function:libsec_shared", + "common_event_service:cesfwk_innerkits", + "eventhandler:libeventhandler", + "hilog:libhilog", + "hitrace:hitrace_meter", + "init:libbegetutil", + "jsoncpp:jsoncpp", + "safwk:system_ability_fwk", + "samgr:samgr_proxy", + "selinux_adapter:librestorecon", + ] + external_deps += bundle_install_external_deps + + defines = [] + if (code_signature_enable) { + sources += [ + "${services_path}/bundlemgr/src/aot/aot_sign_data_cache_mgr.cpp", + "${services_path}/bundlemgr/src/code_sign_helper.cpp", + ] + include_dirs += [ "${services_path}/bundlemgr/include" ] + external_deps += [ + "bounds_checking_function:libsec_shared", + "code_signature:libcode_sign_utils", + "ets_runtime:libcompiler_service", + ] + defines += [ "CODE_SIGNATURE_ENABLE" ] + } + + if (configpolicy_enable) { + external_deps += [ "config_policy:configpolicy_util" ] + defines += [ "CONFIG_POLOCY_ENABLE" ] + } + + if (bundle_framework_app_control) { + defines += [ "BUNDLE_FRAMEWORK_APP_CONTROL" ] + sources += [ + "${services_path}/bundlemgr/src/app_control/app_control_manager.cpp", + "${services_path}/bundlemgr/src/app_control/app_control_manager_host_impl.cpp", + "${services_path}/bundlemgr/src/app_control/app_control_manager_rdb.cpp", + "${services_path}/bundlemgr/src/app_control/app_jump_interceptor_event_subscriber.cpp", + "${services_path}/bundlemgr/src/app_control/app_jump_interceptor_manager_rdb.cpp", + ] + include_dirs += [ "${services_path}/bundlemgr/include/app_control" ] + external_deps += [ "c_utils:utils" ] + } + if (current_cpu == "arm64") { + defines += [ "USE_BUNDLE_EXTENSION" ] + } + + if (build_selinux) { + external_deps += [ "selinux_adapter:libhap_restorecon" ] + } + if (account_enable) { + external_deps += [ "os_account:os_account_innerkits" ] + defines += [ "ACCOUNT_ENABLE" ] + } + if (bundle_framework_free_install) { + sources += aging + sources += free_install + sources += distributed_manager + external_deps += [ + "ability_runtime:ability_manager", + "ability_runtime:app_manager", + "battery_manager:batterysrv_client", + "device_usage_statistics:usagestatsinner", + "display_manager:displaymgr", + "power_manager:powermgr_client", + "syscap_codec:syscap_interface_shared", + ] + defines += [ "BUNDLE_FRAMEWORK_FREE_INSTALL" ] + } + if (global_resmgr_enable) { + defines += [ "GLOBAL_RESMGR_ENABLE" ] + external_deps += [ "resource_management:global_resmgr" ] + } + if (hicollie_enable) { + external_deps += [ "hicollie:libhicollie" ] + defines += [ "HICOLLIE_ENABLE" ] + } + + if (hisysevent_enable) { + sources += [ "${services_path}/bundlemgr/src/inner_event_report.cpp" ] + external_deps += [ "hisysevent:libhisysevent" ] + defines += [ "HISYSEVENT_ENABLE" ] + } + + if (bundle_framework_quick_fix) { + include_dirs += [ "${services_path}/bundlemgr/src/include/quick_fix" ] + sources += quick_fix + defines += [ "BUNDLE_FRAMEWORK_QUICK_FIX" ] + } + + if (storage_service_enable) { + external_deps += [ "storage_service:storage_manager_sa_proxy" ] + defines += [ "STORAGE_SERVICE_ENABLE" ] + } + + external_deps += [ "kv_store:distributeddata_inner" ] + configs += [ "${services_path}/bundlemgr:rdb_config" ] + external_deps += [ "relational_store:native_rdb" ] + sources += [ + "${services_path}/bundlemgr/src/bundle_data_storage_rdb.cpp", + "${services_path}/bundlemgr/src/preinstall_data_storage_rdb.cpp", + "${services_path}/bundlemgr/src/rdb/bms_rdb_open_callback.cpp", + "${services_path}/bundlemgr/src/rdb/rdb_data_manager.cpp", + ] + if (udmf_enabled) { + defines += [ "BUNDLE_FRAMEWORK_UDMF_ENABLED" ] + external_deps += [ "udmf:udmf_client" ] + external_deps += [ "udmf:utd_client" ] + } + + if (user_auth_framework_impl_enabled) { + external_deps += [ "user_auth_framework:userauth_client" ] + defines += [ "BMS_USER_AUTH_FRAMEWORK_ENABLED" ] + include_dirs += [ "${services_path}/bundlemgr/include/user_auth" ] + sources += user_auth + } + + if (bms_device_info_manager_part_enabled) { + external_deps += [ + "device_info_manager:distributed_device_profile_common", + "device_info_manager:distributed_device_profile_sdk", + ] + defines += [ "BMS_DEVICE_INFO_MANAGER_ENABLE" ] + } +} \ No newline at end of file diff --git a/test/fuzztest/fuzztest_bundlemanager/bmsinstalldloadcallback_fuzzer/bmsinstalldloadcallback_fuzzer.cpp b/test/fuzztest/fuzztest_bundlemanager/bmsinstalldloadcallback_fuzzer/bmsinstalldloadcallback_fuzzer.cpp new file mode 100644 index 0000000000..5949879113 --- /dev/null +++ b/test/fuzztest/fuzztest_bundlemanager/bmsinstalldloadcallback_fuzzer/bmsinstalldloadcallback_fuzzer.cpp @@ -0,0 +1,51 @@ +/* + * 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 +#include +#include +#define private public +#include "installd_load_callback.h" +#include "bmsinstalldloadcallback_fuzzer.h" +#include "system_ability_definition.h" +#include "bms_fuzztest_util.h" + +using namespace OHOS::AppExecFwk; +using namespace OHOS::AppExecFwk::BMSFuzzTestUtil; +namespace OHOS { +bool DoSomethingInterestingWithMyAPI(const uint8_t* data, size_t size) +{ + auto installdloadcallback = std::make_shared(); + if (installdloadcallback == nullptr) { + return false; + } + FuzzedDataProvider fdp(data, size); + int32_t systemAbilityId = fdp.ConsumeIntegral(); + sptr remoteObject = nullptr; + installdloadcallback->OnLoadSystemAbilitySuccess(systemAbilityId, remoteObject); + installdloadcallback->OnLoadSystemAbilitySuccess(INSTALLD_SERVICE_ID, remoteObject); + installdloadcallback->OnLoadSystemAbilityFail(systemAbilityId); + installdloadcallback->OnLoadSystemAbilityFail(INSTALLD_SERVICE_ID); + return true; +} +} + +// Fuzzer entry point. +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + // Run your code on data. + OHOS::DoSomethingInterestingWithMyAPI(data, size); + return 0; +} \ No newline at end of file diff --git a/test/fuzztest/fuzztest_bundlemanager/bmsinstalldloadcallback_fuzzer/bmsinstalldloadcallback_fuzzer.h b/test/fuzztest/fuzztest_bundlemanager/bmsinstalldloadcallback_fuzzer/bmsinstalldloadcallback_fuzzer.h new file mode 100644 index 0000000000..78bee7274f --- /dev/null +++ b/test/fuzztest/fuzztest_bundlemanager/bmsinstalldloadcallback_fuzzer/bmsinstalldloadcallback_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 TEST_FUZZTEST_BMS_INSTALLD_LOAD_CALLBACK_FUZZER_H +#define TEST_FUZZTEST_BMS_INSTALLD_LOAD_CALLBACK_FUZZER_H + +#define FUZZ_PROJECT_NAME "bmsinstalldloadcallback_fuzzer" + +#endif \ No newline at end of file diff --git a/test/fuzztest/fuzztest_bundlemanager/bmsinstalldloadcallback_fuzzer/corpus/init b/test/fuzztest/fuzztest_bundlemanager/bmsinstalldloadcallback_fuzzer/corpus/init new file mode 100644 index 0000000000..6b7212c8a6 --- /dev/null +++ b/test/fuzztest/fuzztest_bundlemanager/bmsinstalldloadcallback_fuzzer/corpus/init @@ -0,0 +1 @@ +FUZZ \ No newline at end of file diff --git a/test/fuzztest/fuzztest_bundlemanager/bmsinstalldloadcallback_fuzzer/project.xml b/test/fuzztest/fuzztest_bundlemanager/bmsinstalldloadcallback_fuzzer/project.xml new file mode 100644 index 0000000000..226522bd2a --- /dev/null +++ b/test/fuzztest/fuzztest_bundlemanager/bmsinstalldloadcallback_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 10000 + + 300 + + 4096 + + diff --git a/test/fuzztest/fuzztest_bundlemanager/bmsinstalldpermissionmgr_fuzzer/BUILD.gn b/test/fuzztest/fuzztest_bundlemanager/bmsinstalldpermissionmgr_fuzzer/BUILD.gn new file mode 100644 index 0000000000..32b8408071 --- /dev/null +++ b/test/fuzztest/fuzztest_bundlemanager/bmsinstalldpermissionmgr_fuzzer/BUILD.gn @@ -0,0 +1,190 @@ +# 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/ohos.gni") +import("//build/test.gni") +import("../../../../appexecfwk.gni") +import("../../../../services/bundlemgr/appexecfwk_bundlemgr.gni") +module_output_path = fuzz_test_path + +##############################fuzztest########################################## +ohos_fuzztest("BMSInstalldPermissionMgrFuzzTest") { + fuzz_config_file = "../../../fuzztest/fuzztest_bundlemanager/bmsinstalldpermissionmgr_fuzzer" + + use_exceptions = true + module_out_path = module_output_path + include_dirs = [ + "${test_path}/fuzztest", + "${services_path}/bundlemgr/include/installd", + ] + sources = bundle_mgr_source + sources += [ + "${services_path}/bundlemgr/src/aot/aot_executor.cpp", + "${services_path}/bundlemgr/src/installd/installd_host_impl.cpp", + "${services_path}/bundlemgr/src/installd/installd_operator.cpp", + "${services_path}/bundlemgr/src/installd/installd_service.cpp", + "${services_path}/bundlemgr/src/installd/installd_permission_mgr.cpp", + ] + + sources += bundle_install_sources + + sources += [ "bmsinstalldpermissionmgr_fuzzer.cpp" ] + + configs = [ "${services_path}/bundlemgr/test:bundlemgr_test_config" ] + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + + deps = [ "${core_path}:appexecfwk_core" ] + deps += bundle_install_deps + + external_deps = [ + "ability_base:want", + "ability_runtime:app_manager", + "access_token:el5_filekey_manager_sdk", + "access_token:libprivacy_sdk", + "access_token:libtokenid_sdk", + "appspawn:hnpapi", + "appverify:libhapverify", + "bounds_checking_function:libsec_shared", + "common_event_service:cesfwk_innerkits", + "eventhandler:libeventhandler", + "hilog:libhilog", + "hitrace:hitrace_meter", + "init:libbegetutil", + "jsoncpp:jsoncpp", + "safwk:system_ability_fwk", + "samgr:samgr_proxy", + "selinux_adapter:librestorecon", + ] + external_deps += bundle_install_external_deps + + defines = [] + if (code_signature_enable) { + sources += [ + "${services_path}/bundlemgr/src/aot/aot_sign_data_cache_mgr.cpp", + "${services_path}/bundlemgr/src/code_sign_helper.cpp", + ] + include_dirs += [ "${services_path}/bundlemgr/include" ] + external_deps += [ + "bounds_checking_function:libsec_shared", + "code_signature:libcode_sign_utils", + "ets_runtime:libcompiler_service", + ] + defines += [ "CODE_SIGNATURE_ENABLE" ] + } + + if (configpolicy_enable) { + external_deps += [ "config_policy:configpolicy_util" ] + defines += [ "CONFIG_POLOCY_ENABLE" ] + } + + if (bundle_framework_app_control) { + defines += [ "BUNDLE_FRAMEWORK_APP_CONTROL" ] + sources += [ + "${services_path}/bundlemgr/src/app_control/app_control_manager.cpp", + "${services_path}/bundlemgr/src/app_control/app_control_manager_host_impl.cpp", + "${services_path}/bundlemgr/src/app_control/app_control_manager_rdb.cpp", + "${services_path}/bundlemgr/src/app_control/app_jump_interceptor_event_subscriber.cpp", + "${services_path}/bundlemgr/src/app_control/app_jump_interceptor_manager_rdb.cpp", + ] + include_dirs += [ "${services_path}/bundlemgr/include/app_control" ] + external_deps += [ "c_utils:utils" ] + } + if (current_cpu == "arm64") { + defines += [ "USE_BUNDLE_EXTENSION" ] + } + + if (build_selinux) { + external_deps += [ "selinux_adapter:libhap_restorecon" ] + } + if (account_enable) { + external_deps += [ "os_account:os_account_innerkits" ] + defines += [ "ACCOUNT_ENABLE" ] + } + if (bundle_framework_free_install) { + sources += aging + sources += free_install + sources += distributed_manager + external_deps += [ + "ability_runtime:ability_manager", + "ability_runtime:app_manager", + "battery_manager:batterysrv_client", + "device_usage_statistics:usagestatsinner", + "display_manager:displaymgr", + "power_manager:powermgr_client", + "syscap_codec:syscap_interface_shared", + ] + defines += [ "BUNDLE_FRAMEWORK_FREE_INSTALL" ] + } + if (global_resmgr_enable) { + defines += [ "GLOBAL_RESMGR_ENABLE" ] + external_deps += [ "resource_management:global_resmgr" ] + } + if (hicollie_enable) { + external_deps += [ "hicollie:libhicollie" ] + defines += [ "HICOLLIE_ENABLE" ] + } + + if (hisysevent_enable) { + sources += [ "${services_path}/bundlemgr/src/inner_event_report.cpp" ] + external_deps += [ "hisysevent:libhisysevent" ] + defines += [ "HISYSEVENT_ENABLE" ] + } + + if (bundle_framework_quick_fix) { + include_dirs += [ "${services_path}/bundlemgr/src/include/quick_fix" ] + sources += quick_fix + defines += [ "BUNDLE_FRAMEWORK_QUICK_FIX" ] + } + + if (storage_service_enable) { + external_deps += [ "storage_service:storage_manager_sa_proxy" ] + defines += [ "STORAGE_SERVICE_ENABLE" ] + } + + external_deps += [ "kv_store:distributeddata_inner" ] + configs += [ "${services_path}/bundlemgr:rdb_config" ] + external_deps += [ "relational_store:native_rdb" ] + sources += [ + "${services_path}/bundlemgr/src/bundle_data_storage_rdb.cpp", + "${services_path}/bundlemgr/src/preinstall_data_storage_rdb.cpp", + "${services_path}/bundlemgr/src/rdb/bms_rdb_open_callback.cpp", + "${services_path}/bundlemgr/src/rdb/rdb_data_manager.cpp", + ] + if (udmf_enabled) { + defines += [ "BUNDLE_FRAMEWORK_UDMF_ENABLED" ] + external_deps += [ "udmf:udmf_client" ] + external_deps += [ "udmf:utd_client" ] + } + + if (user_auth_framework_impl_enabled) { + external_deps += [ "user_auth_framework:userauth_client" ] + defines += [ "BMS_USER_AUTH_FRAMEWORK_ENABLED" ] + include_dirs += [ "${services_path}/bundlemgr/include/user_auth" ] + sources += user_auth + } + + if (bms_device_info_manager_part_enabled) { + external_deps += [ + "device_info_manager:distributed_device_profile_common", + "device_info_manager:distributed_device_profile_sdk", + ] + defines += [ "BMS_DEVICE_INFO_MANAGER_ENABLE" ] + } +} \ No newline at end of file diff --git a/test/fuzztest/fuzztest_bundlemanager/bmsinstalldpermissionmgr_fuzzer/bmsinstalldpermissionmgr_fuzzer.cpp b/test/fuzztest/fuzztest_bundlemanager/bmsinstalldpermissionmgr_fuzzer/bmsinstalldpermissionmgr_fuzzer.cpp new file mode 100644 index 0000000000..e69de29bb2 diff --git a/test/fuzztest/fuzztest_bundlemanager/bmsinstalldpermissionmgr_fuzzer/bmsinstalldpermissionmgr_fuzzer.h b/test/fuzztest/fuzztest_bundlemanager/bmsinstalldpermissionmgr_fuzzer/bmsinstalldpermissionmgr_fuzzer.h new file mode 100644 index 0000000000..01c8b0ffb8 --- /dev/null +++ b/test/fuzztest/fuzztest_bundlemanager/bmsinstalldpermissionmgr_fuzzer/bmsinstalldpermissionmgr_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 TEST_FUZZTEST_BMS_INSTALLD_PERMISSION_MGR_FUZZER_H +#define TEST_FUZZTEST_BMS_INSTALLD_PERMISSION_MGR_FUZZER_H + +#define FUZZ_PROJECT_NAME "bmsinstalldpermissionmgr_fuzzer" + +#endif \ No newline at end of file diff --git a/test/fuzztest/fuzztest_bundlemanager/bmsinstalldpermissionmgr_fuzzer/corpus/init b/test/fuzztest/fuzztest_bundlemanager/bmsinstalldpermissionmgr_fuzzer/corpus/init new file mode 100644 index 0000000000..6b7212c8a6 --- /dev/null +++ b/test/fuzztest/fuzztest_bundlemanager/bmsinstalldpermissionmgr_fuzzer/corpus/init @@ -0,0 +1 @@ +FUZZ \ No newline at end of file diff --git a/test/fuzztest/fuzztest_bundlemanager/bmsinstalldpermissionmgr_fuzzer/project.xml b/test/fuzztest/fuzztest_bundlemanager/bmsinstalldpermissionmgr_fuzzer/project.xml new file mode 100644 index 0000000000..226522bd2a --- /dev/null +++ b/test/fuzztest/fuzztest_bundlemanager/bmsinstalldpermissionmgr_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 10000 + + 300 + + 4096 + + diff --git a/test/fuzztest/fuzztest_bundlemanager/bmsinstalldservice_fuzzer/BUILD.gn b/test/fuzztest/fuzztest_bundlemanager/bmsinstalldservice_fuzzer/BUILD.gn new file mode 100644 index 0000000000..e35483d8e5 --- /dev/null +++ b/test/fuzztest/fuzztest_bundlemanager/bmsinstalldservice_fuzzer/BUILD.gn @@ -0,0 +1,187 @@ +# 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/ohos.gni") +import("//build/test.gni") +import("../../../../appexecfwk.gni") +import("../../../../services/bundlemgr/appexecfwk_bundlemgr.gni") +module_output_path = fuzz_test_path + +##############################fuzztest########################################## +ohos_fuzztest("BMSInstalldServiceFuzzTest") { + fuzz_config_file = "../../../fuzztest/fuzztest_bundlemanager/bmsinstalldservice_fuzzer" + + use_exceptions = true + module_out_path = module_output_path + include_dirs = [ "${test_path}/fuzztest" ] + sources = bundle_mgr_source + sources += [ + "${services_path}/bundlemgr/src/aot/aot_executor.cpp", + "${services_path}/bundlemgr/src/installd/installd_host_impl.cpp", + "${services_path}/bundlemgr/src/installd/installd_operator.cpp", + "${services_path}/bundlemgr/src/installd/installd_service.cpp", + "${services_path}/bundlemgr/src/installd/installd_permission_mgr.cpp", + ] + + sources += bundle_install_sources + + sources += [ "bmsinstalldservice_fuzzer.cpp" ] + + configs = [ "${services_path}/bundlemgr/test:bundlemgr_test_config" ] + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + + deps = [ "${core_path}:appexecfwk_core" ] + deps += bundle_install_deps + + external_deps = [ + "ability_base:want", + "ability_runtime:app_manager", + "access_token:el5_filekey_manager_sdk", + "access_token:libprivacy_sdk", + "access_token:libtokenid_sdk", + "appspawn:hnpapi", + "appverify:libhapverify", + "bounds_checking_function:libsec_shared", + "common_event_service:cesfwk_innerkits", + "eventhandler:libeventhandler", + "hilog:libhilog", + "hitrace:hitrace_meter", + "init:libbegetutil", + "jsoncpp:jsoncpp", + "safwk:system_ability_fwk", + "samgr:samgr_proxy", + "selinux_adapter:librestorecon", + ] + external_deps += bundle_install_external_deps + + defines = [] + if (code_signature_enable) { + sources += [ + "${services_path}/bundlemgr/src/aot/aot_sign_data_cache_mgr.cpp", + "${services_path}/bundlemgr/src/code_sign_helper.cpp", + ] + include_dirs += [ "${services_path}/bundlemgr/include" ] + external_deps += [ + "bounds_checking_function:libsec_shared", + "code_signature:libcode_sign_utils", + "ets_runtime:libcompiler_service", + ] + defines += [ "CODE_SIGNATURE_ENABLE" ] + } + + if (configpolicy_enable) { + external_deps += [ "config_policy:configpolicy_util" ] + defines += [ "CONFIG_POLOCY_ENABLE" ] + } + + if (bundle_framework_app_control) { + defines += [ "BUNDLE_FRAMEWORK_APP_CONTROL" ] + sources += [ + "${services_path}/bundlemgr/src/app_control/app_control_manager.cpp", + "${services_path}/bundlemgr/src/app_control/app_control_manager_host_impl.cpp", + "${services_path}/bundlemgr/src/app_control/app_control_manager_rdb.cpp", + "${services_path}/bundlemgr/src/app_control/app_jump_interceptor_event_subscriber.cpp", + "${services_path}/bundlemgr/src/app_control/app_jump_interceptor_manager_rdb.cpp", + ] + include_dirs += [ "${services_path}/bundlemgr/include/app_control" ] + external_deps += [ "c_utils:utils" ] + } + if (current_cpu == "arm64") { + defines += [ "USE_BUNDLE_EXTENSION" ] + } + + if (build_selinux) { + external_deps += [ "selinux_adapter:libhap_restorecon" ] + } + if (account_enable) { + external_deps += [ "os_account:os_account_innerkits" ] + defines += [ "ACCOUNT_ENABLE" ] + } + if (bundle_framework_free_install) { + sources += aging + sources += free_install + sources += distributed_manager + external_deps += [ + "ability_runtime:ability_manager", + "ability_runtime:app_manager", + "battery_manager:batterysrv_client", + "device_usage_statistics:usagestatsinner", + "display_manager:displaymgr", + "power_manager:powermgr_client", + "syscap_codec:syscap_interface_shared", + ] + defines += [ "BUNDLE_FRAMEWORK_FREE_INSTALL" ] + } + if (global_resmgr_enable) { + defines += [ "GLOBAL_RESMGR_ENABLE" ] + external_deps += [ "resource_management:global_resmgr" ] + } + if (hicollie_enable) { + external_deps += [ "hicollie:libhicollie" ] + defines += [ "HICOLLIE_ENABLE" ] + } + + if (hisysevent_enable) { + sources += [ "${services_path}/bundlemgr/src/inner_event_report.cpp" ] + external_deps += [ "hisysevent:libhisysevent" ] + defines += [ "HISYSEVENT_ENABLE" ] + } + + if (bundle_framework_quick_fix) { + include_dirs += [ "${services_path}/bundlemgr/src/include/quick_fix" ] + sources += quick_fix + defines += [ "BUNDLE_FRAMEWORK_QUICK_FIX" ] + } + + if (storage_service_enable) { + external_deps += [ "storage_service:storage_manager_sa_proxy" ] + defines += [ "STORAGE_SERVICE_ENABLE" ] + } + + external_deps += [ "kv_store:distributeddata_inner" ] + configs += [ "${services_path}/bundlemgr:rdb_config" ] + external_deps += [ "relational_store:native_rdb" ] + sources += [ + "${services_path}/bundlemgr/src/bundle_data_storage_rdb.cpp", + "${services_path}/bundlemgr/src/preinstall_data_storage_rdb.cpp", + "${services_path}/bundlemgr/src/rdb/bms_rdb_open_callback.cpp", + "${services_path}/bundlemgr/src/rdb/rdb_data_manager.cpp", + ] + if (udmf_enabled) { + defines += [ "BUNDLE_FRAMEWORK_UDMF_ENABLED" ] + external_deps += [ "udmf:udmf_client" ] + external_deps += [ "udmf:utd_client" ] + } + + if (user_auth_framework_impl_enabled) { + external_deps += [ "user_auth_framework:userauth_client" ] + defines += [ "BMS_USER_AUTH_FRAMEWORK_ENABLED" ] + include_dirs += [ "${services_path}/bundlemgr/include/user_auth" ] + sources += user_auth + } + + if (bms_device_info_manager_part_enabled) { + external_deps += [ + "device_info_manager:distributed_device_profile_common", + "device_info_manager:distributed_device_profile_sdk", + ] + defines += [ "BMS_DEVICE_INFO_MANAGER_ENABLE" ] + } +} \ No newline at end of file diff --git a/test/fuzztest/fuzztest_bundlemanager/bmsinstalldservice_fuzzer/bmsinstalldservice_fuzzer.cpp b/test/fuzztest/fuzztest_bundlemanager/bmsinstalldservice_fuzzer/bmsinstalldservice_fuzzer.cpp new file mode 100644 index 0000000000..000c5a3da5 --- /dev/null +++ b/test/fuzztest/fuzztest_bundlemanager/bmsinstalldservice_fuzzer/bmsinstalldservice_fuzzer.cpp @@ -0,0 +1,51 @@ +/* + * 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 +#include +#include +#define private public +#include "installd_service.h" +#include "bmsinstalldservice_fuzzer.h" +#include "bms_fuzztest_util.h" + +using namespace OHOS::AppExecFwk; +using namespace OHOS::AppExecFwk::BMSFuzzTestUtil; +namespace OHOS { +bool DoSomethingInterestingWithMyAPI(const uint8_t* data, size_t size) +{ + auto installdService_ = std::make_shared(); + if (installdService_ == nullptr) { + return false; + } + FuzzedDataProvider fdp(data, size); + std::string path = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH); + installdService_->Init(); + installdService_->InitDir(path); + installdService_->OnStart(); + installdService_->Start(); + installdService_->Stop(); + installdService_->OnStop(); + return true; +} +} + +// Fuzzer entry point. +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + // Run your code on data. + OHOS::DoSomethingInterestingWithMyAPI(data, size); + return 0; +} \ No newline at end of file diff --git a/test/fuzztest/fuzztest_bundlemanager/bmsinstalldservice_fuzzer/bmsinstalldservice_fuzzer.h b/test/fuzztest/fuzztest_bundlemanager/bmsinstalldservice_fuzzer/bmsinstalldservice_fuzzer.h new file mode 100644 index 0000000000..79f4147053 --- /dev/null +++ b/test/fuzztest/fuzztest_bundlemanager/bmsinstalldservice_fuzzer/bmsinstalldservice_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 TEST_FUZZTEST_BMS_INSTALLD_SERVICE_FUZZER_H +#define TEST_FUZZTEST_BMS_INSTALLD_SERVICE_FUZZER_H + +#define FUZZ_PROJECT_NAME "bmsinstalldservice_fuzzer" + +#endif \ No newline at end of file diff --git a/test/fuzztest/fuzztest_bundlemanager/bmsinstalldservice_fuzzer/corpus/init b/test/fuzztest/fuzztest_bundlemanager/bmsinstalldservice_fuzzer/corpus/init new file mode 100644 index 0000000000..6b7212c8a6 --- /dev/null +++ b/test/fuzztest/fuzztest_bundlemanager/bmsinstalldservice_fuzzer/corpus/init @@ -0,0 +1 @@ +FUZZ \ No newline at end of file diff --git a/test/fuzztest/fuzztest_bundlemanager/bmsinstalldservice_fuzzer/project.xml b/test/fuzztest/fuzztest_bundlemanager/bmsinstalldservice_fuzzer/project.xml new file mode 100644 index 0000000000..66e1dcac47 --- /dev/null +++ b/test/fuzztest/fuzztest_bundlemanager/bmsinstalldservice_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + -- Gitee From b8c381cce87cbdad55f4d07ce5358dc8c2bec3c7 Mon Sep 17 00:00:00 2001 From: liuyaoqian Date: Mon, 30 Jun 2025 08:22:38 +0000 Subject: [PATCH 02/14] add Signed-off-by: liuyaoqian --- .../bmscheckabilityenableinstall_fuzzer.cpp | 71 +++++++++++++++++++ 1 file changed, 71 insertions(+) diff --git a/test/fuzztest/fuzztest_bundlemanager/bmscheckabilityenableinstall_fuzzer/bmscheckabilityenableinstall_fuzzer.cpp b/test/fuzztest/fuzztest_bundlemanager/bmscheckabilityenableinstall_fuzzer/bmscheckabilityenableinstall_fuzzer.cpp index e69de29bb2..3330a8fd5b 100644 --- a/test/fuzztest/fuzztest_bundlemanager/bmscheckabilityenableinstall_fuzzer/bmscheckabilityenableinstall_fuzzer.cpp +++ b/test/fuzztest/fuzztest_bundlemanager/bmscheckabilityenableinstall_fuzzer/bmscheckabilityenableinstall_fuzzer.cpp @@ -0,0 +1,71 @@ +/* + * 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 +#include +#include +#include +#define private public +#include "bundle_distributed_manager.h" +#include "bmscheckabilityenableinstall_fuzzer.h" +#include "bms_fuzztest_util.h" + +using Want = OHOS::AAFwk::Want; +using namespace OHOS::AppExecFwk; +using namespace OHOS::AppExecFwk::BMSFuzzTestUtil; +namespace OHOS +{ + std::string DEVICE_ID_NORMAL = "deviceId"; + std::string BUNDLE_NAME_TEST = "com.example.bundlekit.test"; + std::string MODULE_NAME_MY_APPLICATION = "com.example.MyModuleName"; + std::string ABILITY_NAME_MY_APPLICATION = "com.example.MyApplication.MainAbility"; + bool DoSomethingInterestingWithMyAPI(const uint8_t *data, size_t size) + { + std::shared_ptr BundleDistributedManager_ = + std::make_shared(); + if (BundleDistributedManager_ == nullptr) + { + return false; + } + FuzzedDataProvider fdp(data, size); + Want want; + std::string deviceId = DEVICE_ID_NORMAL; + std::string bundleName = BUNDLE_NAME_TEST; + std::string moduleName = MODULE_NAME_MY_APPLICATION; + std::string abilityName = ABILITY_NAME_MY_APPLICATION; + want.SetElementName(deviceId, bundleName, moduleName, abilityName); + int32_t missionId = fdp.ConsumeIntegral(); + int32_t userId = GenerateRandomUser(fdp); + sptr callerToken = nullptr; + BundleDistributedManager_->CheckAbilityEnableInstall(want, missionId, userId, callerToken); +#ifdef BMS_DEVICE_INFO_MANAGER_ENABLE + RpcIdResult rpcIdResult; + rpcIdResult.retCode = fdp.ConsumeIntegral(); + rpcIdResult.version = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH); + rpcIdResult.transactId = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH); + rpcIdResult.resultMsg = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH); + BundleDistributedManager_->ComparePcIdString(want, rpcIdResult); +#endif + return true; + } +} + +// Fuzzer entry point. +extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) +{ + // Run your code on data. + OHOS::DoSomethingInterestingWithMyAPI(data, size); + return 0; +} \ No newline at end of file -- Gitee From 7b77e0cf00b118eb11bbc17b19dcd265fe37d87a Mon Sep 17 00:00:00 2001 From: liuyaoqian Date: Mon, 30 Jun 2025 08:26:09 +0000 Subject: [PATCH 03/14] add Signed-off-by: liuyaoqian --- .../bmscheckabilityenableinstall_fuzzer.cpp | 61 +++++++++---------- 1 file changed, 30 insertions(+), 31 deletions(-) diff --git a/test/fuzztest/fuzztest_bundlemanager/bmscheckabilityenableinstall_fuzzer/bmscheckabilityenableinstall_fuzzer.cpp b/test/fuzztest/fuzztest_bundlemanager/bmscheckabilityenableinstall_fuzzer/bmscheckabilityenableinstall_fuzzer.cpp index 3330a8fd5b..070da2a129 100644 --- a/test/fuzztest/fuzztest_bundlemanager/bmscheckabilityenableinstall_fuzzer/bmscheckabilityenableinstall_fuzzer.cpp +++ b/test/fuzztest/fuzztest_bundlemanager/bmscheckabilityenableinstall_fuzzer/bmscheckabilityenableinstall_fuzzer.cpp @@ -27,39 +27,38 @@ using namespace OHOS::AppExecFwk; using namespace OHOS::AppExecFwk::BMSFuzzTestUtil; namespace OHOS { - std::string DEVICE_ID_NORMAL = "deviceId"; - std::string BUNDLE_NAME_TEST = "com.example.bundlekit.test"; - std::string MODULE_NAME_MY_APPLICATION = "com.example.MyModuleName"; - std::string ABILITY_NAME_MY_APPLICATION = "com.example.MyApplication.MainAbility"; - bool DoSomethingInterestingWithMyAPI(const uint8_t *data, size_t size) - { - std::shared_ptr BundleDistributedManager_ = - std::make_shared(); - if (BundleDistributedManager_ == nullptr) - { - return false; - } - FuzzedDataProvider fdp(data, size); - Want want; - std::string deviceId = DEVICE_ID_NORMAL; - std::string bundleName = BUNDLE_NAME_TEST; - std::string moduleName = MODULE_NAME_MY_APPLICATION; - std::string abilityName = ABILITY_NAME_MY_APPLICATION; - want.SetElementName(deviceId, bundleName, moduleName, abilityName); - int32_t missionId = fdp.ConsumeIntegral(); - int32_t userId = GenerateRandomUser(fdp); - sptr callerToken = nullptr; - BundleDistributedManager_->CheckAbilityEnableInstall(want, missionId, userId, callerToken); +std::string DEVICE_ID_NORMAL = "deviceId"; +std::string BUNDLE_NAME_TEST = "com.example.bundlekit.test"; +std::string MODULE_NAME_MY_APPLICATION = "com.example.MyModuleName"; +std::string ABILITY_NAME_MY_APPLICATION = "com.example.MyApplication.MainAbility"; +bool DoSomethingInterestingWithMyAPI(const uint8_t *data, size_t size) +{ + std::shared_ptr BundleDistributedManager_ = + std::make_shared(); + if (BundleDistributedManager_ == nullptr) { + return false; + } + FuzzedDataProvider fdp(data, size); + Want want; + std::string deviceId = DEVICE_ID_NORMAL; + std::string bundleName = BUNDLE_NAME_TEST; + std::string moduleName = MODULE_NAME_MY_APPLICATION; + std::string abilityName = ABILITY_NAME_MY_APPLICATION; + want.SetElementName(deviceId, bundleName, moduleName, abilityName); + int32_t missionId = fdp.ConsumeIntegral(); + int32_t userId = GenerateRandomUser(fdp); + sptr callerToken = nullptr; + BundleDistributedManager_->CheckAbilityEnableInstall(want, missionId, userId, callerToken); #ifdef BMS_DEVICE_INFO_MANAGER_ENABLE - RpcIdResult rpcIdResult; - rpcIdResult.retCode = fdp.ConsumeIntegral(); - rpcIdResult.version = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH); - rpcIdResult.transactId = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH); - rpcIdResult.resultMsg = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH); - BundleDistributedManager_->ComparePcIdString(want, rpcIdResult); + RpcIdResult rpcIdResult; + rpcIdResult.retCode = fdp.ConsumeIntegral(); + rpcIdResult.version = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH); + rpcIdResult.transactId = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH); + rpcIdResult.resultMsg = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH); + BundleDistributedManager_->ComparePcIdString(want, rpcIdResult); #endif - return true; - } + return true; +} } // Fuzzer entry point. -- Gitee From e073e947c52e2bbeef886cebc67776c9dc98a633 Mon Sep 17 00:00:00 2001 From: liuyaoqian Date: Mon, 30 Jun 2025 08:28:14 +0000 Subject: [PATCH 04/14] add Signed-off-by: liuyaoqian --- .../bmsinstalldpermissionmgr_fuzzer.cpp | 46 +++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/test/fuzztest/fuzztest_bundlemanager/bmsinstalldpermissionmgr_fuzzer/bmsinstalldpermissionmgr_fuzzer.cpp b/test/fuzztest/fuzztest_bundlemanager/bmsinstalldpermissionmgr_fuzzer/bmsinstalldpermissionmgr_fuzzer.cpp index e69de29bb2..c7791a63c9 100644 --- a/test/fuzztest/fuzztest_bundlemanager/bmsinstalldpermissionmgr_fuzzer/bmsinstalldpermissionmgr_fuzzer.cpp +++ b/test/fuzztest/fuzztest_bundlemanager/bmsinstalldpermissionmgr_fuzzer/bmsinstalldpermissionmgr_fuzzer.cpp @@ -0,0 +1,46 @@ +/* + * 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 +#include +#include +#define private public +#include "installd_permission_mgr.h" +#include "bmsinstalldpermissionmgr_fuzzer.h" +#include "bms_fuzztest_util.h" + +using namespace OHOS::AppExecFwk; +using namespace OHOS::AppExecFwk::BMSFuzzTestUtil; +namespace OHOS { +bool DoSomethingInterestingWithMyAPI(const uint8_t *data, size_t size) +{ + auto installdpermissionmgr = std::make_shared(); + if (installdpermissionmgr == nullptr) { + return false; + } + FuzzedDataProvider fdp(data, size); + int32_t uid = fdp.ConsumeIntegral(); + installdpermissionmgr->VerifyCallingPermission(uid); + return true; +} +} + +// Fuzzer entry point. +extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) +{ + // Run your code on data. + OHOS::DoSomethingInterestingWithMyAPI(data, size); + return 0; +} \ No newline at end of file -- Gitee From af839c20e04e1d2119a2d551062e49fcc70f94d8 Mon Sep 17 00:00:00 2001 From: liuyaoqian Date: Mon, 30 Jun 2025 09:13:19 +0000 Subject: [PATCH 05/14] fix Signed-off-by: liuyaoqian --- .../bmscheckabilityenableinstall_fuzzer.cpp | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/test/fuzztest/fuzztest_bundlemanager/bmscheckabilityenableinstall_fuzzer/bmscheckabilityenableinstall_fuzzer.cpp b/test/fuzztest/fuzztest_bundlemanager/bmscheckabilityenableinstall_fuzzer/bmscheckabilityenableinstall_fuzzer.cpp index 070da2a129..f746bb6589 100644 --- a/test/fuzztest/fuzztest_bundlemanager/bmscheckabilityenableinstall_fuzzer/bmscheckabilityenableinstall_fuzzer.cpp +++ b/test/fuzztest/fuzztest_bundlemanager/bmscheckabilityenableinstall_fuzzer/bmscheckabilityenableinstall_fuzzer.cpp @@ -25,16 +25,15 @@ using Want = OHOS::AAFwk::Want; using namespace OHOS::AppExecFwk; using namespace OHOS::AppExecFwk::BMSFuzzTestUtil; -namespace OHOS -{ +namespace OHOS { std::string DEVICE_ID_NORMAL = "deviceId"; std::string BUNDLE_NAME_TEST = "com.example.bundlekit.test"; std::string MODULE_NAME_MY_APPLICATION = "com.example.MyModuleName"; std::string ABILITY_NAME_MY_APPLICATION = "com.example.MyApplication.MainAbility"; -bool DoSomethingInterestingWithMyAPI(const uint8_t *data, size_t size) +bool DoSomethingInterestingWithMyAPI(const uint8_t* data, size_t size) { std::shared_ptr BundleDistributedManager_ = - std::make_shared(); + std::make_shared(); if (BundleDistributedManager_ == nullptr) { return false; } @@ -62,7 +61,7 @@ bool DoSomethingInterestingWithMyAPI(const uint8_t *data, size_t size) } // Fuzzer entry point. -extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { // Run your code on data. OHOS::DoSomethingInterestingWithMyAPI(data, size); -- Gitee From 2eed45ea20cbf6c5865dea2bf809bc520422f232 Mon Sep 17 00:00:00 2001 From: liuyaoqian Date: Mon, 30 Jun 2025 09:14:21 +0000 Subject: [PATCH 06/14] fix Signed-off-by: liuyaoqian --- .../bmsinstalldhostimpl_fuzzer/bmsinstalldhostimpl_fuzzer.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/fuzztest/fuzztest_bundlemanager/bmsinstalldhostimpl_fuzzer/bmsinstalldhostimpl_fuzzer.cpp b/test/fuzztest/fuzztest_bundlemanager/bmsinstalldhostimpl_fuzzer/bmsinstalldhostimpl_fuzzer.cpp index 2abcbb1d26..14d0bc9eca 100644 --- a/test/fuzztest/fuzztest_bundlemanager/bmsinstalldhostimpl_fuzzer/bmsinstalldhostimpl_fuzzer.cpp +++ b/test/fuzztest/fuzztest_bundlemanager/bmsinstalldhostimpl_fuzzer/bmsinstalldhostimpl_fuzzer.cpp @@ -81,7 +81,7 @@ bool DoSomethingInterestingWithMyAPI(const uint8_t* data, size_t size) createDirParam.debug = false; createDirParam.isDlpSandbox = false; createDirParam.bundleName = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH); - createDirParam.userId = GenerateRandomUser(fdp);; + createDirParam.userId = GenerateRandomUser(fdp); createDirParam.uid = fdp.ConsumeIntegral(); createDirParam.gid = fdp.ConsumeIntegral(); createDirParam.appIndex = fdp.ConsumeIntegral(); -- Gitee From 06981001277d537598856701478c5628545261f9 Mon Sep 17 00:00:00 2001 From: liuyaoqian Date: Mon, 30 Jun 2025 14:37:47 +0000 Subject: [PATCH 07/14] =?UTF-8?q?=E5=88=A0=E9=99=A4=E6=96=87=E4=BB=B6=20te?= =?UTF-8?q?st/fuzztest/fuzztest=5Fbundlemanager/bmsinstalldhostimpl=5Ffuzz?= =?UTF-8?q?er/BUILD.gn?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../bmsinstalldhostimpl_fuzzer/BUILD.gn | 190 ------------------ 1 file changed, 190 deletions(-) delete mode 100644 test/fuzztest/fuzztest_bundlemanager/bmsinstalldhostimpl_fuzzer/BUILD.gn diff --git a/test/fuzztest/fuzztest_bundlemanager/bmsinstalldhostimpl_fuzzer/BUILD.gn b/test/fuzztest/fuzztest_bundlemanager/bmsinstalldhostimpl_fuzzer/BUILD.gn deleted file mode 100644 index 681550070c..0000000000 --- a/test/fuzztest/fuzztest_bundlemanager/bmsinstalldhostimpl_fuzzer/BUILD.gn +++ /dev/null @@ -1,190 +0,0 @@ -# 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/ohos.gni") -import("//build/test.gni") -import("../../../../appexecfwk.gni") -import("../../../../services/bundlemgr/appexecfwk_bundlemgr.gni") -module_output_path = fuzz_test_path - -##############################fuzztest########################################## -ohos_fuzztest("BMSInstalldHostImplFuzzTest") { - fuzz_config_file = "../../../fuzztest/fuzztest_bundlemanager/bmsinstalldhostimpl_fuzzer" - - use_exceptions = true - module_out_path = module_output_path - include_dirs = [ - "${test_path}/fuzztest", - "${services_path}/bundlemgr/include/installd", - ] - sources = bundle_mgr_source - sources += [ - "${services_path}/bundlemgr/src/aot/aot_executor.cpp", - "${services_path}/bundlemgr/src/installd/installd_host_impl.cpp", - "${services_path}/bundlemgr/src/installd/installd_operator.cpp", - "${services_path}/bundlemgr/src/installd/installd_service.cpp", - "${services_path}/bundlemgr/src/installd/installd_permission_mgr.cpp", - ] - - sources += bundle_install_sources - - sources += [ "bmsinstalldhostimpl_fuzzer.cpp" ] - - configs = [ "${services_path}/bundlemgr/test:bundlemgr_test_config" ] - cflags = [ - "-g", - "-O0", - "-Wno-unused-variable", - "-fno-omit-frame-pointer", - ] - - deps = [ "${core_path}:appexecfwk_core" ] - deps += bundle_install_deps - - external_deps = [ - "ability_base:want", - "ability_runtime:app_manager", - "access_token:el5_filekey_manager_sdk", - "access_token:libprivacy_sdk", - "access_token:libtokenid_sdk", - "appspawn:hnpapi", - "appverify:libhapverify", - "bounds_checking_function:libsec_shared", - "common_event_service:cesfwk_innerkits", - "eventhandler:libeventhandler", - "hilog:libhilog", - "hitrace:hitrace_meter", - "init:libbegetutil", - "jsoncpp:jsoncpp", - "safwk:system_ability_fwk", - "samgr:samgr_proxy", - "selinux_adapter:librestorecon", - ] - external_deps += bundle_install_external_deps - - defines = [] - if (code_signature_enable) { - sources += [ - "${services_path}/bundlemgr/src/aot/aot_sign_data_cache_mgr.cpp", - "${services_path}/bundlemgr/src/code_sign_helper.cpp", - ] - include_dirs += [ "${services_path}/bundlemgr/include" ] - external_deps += [ - "bounds_checking_function:libsec_shared", - "code_signature:libcode_sign_utils", - "ets_runtime:libcompiler_service", - ] - defines += [ "CODE_SIGNATURE_ENABLE" ] - } - - if (configpolicy_enable) { - external_deps += [ "config_policy:configpolicy_util" ] - defines += [ "CONFIG_POLOCY_ENABLE" ] - } - - if (bundle_framework_app_control) { - defines += [ "BUNDLE_FRAMEWORK_APP_CONTROL" ] - sources += [ - "${services_path}/bundlemgr/src/app_control/app_control_manager.cpp", - "${services_path}/bundlemgr/src/app_control/app_control_manager_host_impl.cpp", - "${services_path}/bundlemgr/src/app_control/app_control_manager_rdb.cpp", - "${services_path}/bundlemgr/src/app_control/app_jump_interceptor_event_subscriber.cpp", - "${services_path}/bundlemgr/src/app_control/app_jump_interceptor_manager_rdb.cpp", - ] - include_dirs += [ "${services_path}/bundlemgr/include/app_control" ] - external_deps += [ "c_utils:utils" ] - } - if (current_cpu == "arm64") { - defines += [ "USE_BUNDLE_EXTENSION" ] - } - - if (build_selinux) { - external_deps += [ "selinux_adapter:libhap_restorecon" ] - } - if (account_enable) { - external_deps += [ "os_account:os_account_innerkits" ] - defines += [ "ACCOUNT_ENABLE" ] - } - if (bundle_framework_free_install) { - sources += aging - sources += free_install - sources += distributed_manager - external_deps += [ - "ability_runtime:ability_manager", - "ability_runtime:app_manager", - "battery_manager:batterysrv_client", - "device_usage_statistics:usagestatsinner", - "display_manager:displaymgr", - "power_manager:powermgr_client", - "syscap_codec:syscap_interface_shared", - ] - defines += [ "BUNDLE_FRAMEWORK_FREE_INSTALL" ] - } - if (global_resmgr_enable) { - defines += [ "GLOBAL_RESMGR_ENABLE" ] - external_deps += [ "resource_management:global_resmgr" ] - } - if (hicollie_enable) { - external_deps += [ "hicollie:libhicollie" ] - defines += [ "HICOLLIE_ENABLE" ] - } - - if (hisysevent_enable) { - sources += [ "${services_path}/bundlemgr/src/inner_event_report.cpp" ] - external_deps += [ "hisysevent:libhisysevent" ] - defines += [ "HISYSEVENT_ENABLE" ] - } - - if (bundle_framework_quick_fix) { - include_dirs += [ "${services_path}/bundlemgr/src/include/quick_fix" ] - sources += quick_fix - defines += [ "BUNDLE_FRAMEWORK_QUICK_FIX" ] - } - - if (storage_service_enable) { - external_deps += [ "storage_service:storage_manager_sa_proxy" ] - defines += [ "STORAGE_SERVICE_ENABLE" ] - } - - external_deps += [ "kv_store:distributeddata_inner" ] - configs += [ "${services_path}/bundlemgr:rdb_config" ] - external_deps += [ "relational_store:native_rdb" ] - sources += [ - "${services_path}/bundlemgr/src/bundle_data_storage_rdb.cpp", - "${services_path}/bundlemgr/src/preinstall_data_storage_rdb.cpp", - "${services_path}/bundlemgr/src/rdb/bms_rdb_open_callback.cpp", - "${services_path}/bundlemgr/src/rdb/rdb_data_manager.cpp", - ] - if (udmf_enabled) { - defines += [ "BUNDLE_FRAMEWORK_UDMF_ENABLED" ] - external_deps += [ "udmf:udmf_client" ] - external_deps += [ "udmf:utd_client" ] - } - - if (user_auth_framework_impl_enabled) { - external_deps += [ "user_auth_framework:userauth_client" ] - defines += [ "BMS_USER_AUTH_FRAMEWORK_ENABLED" ] - include_dirs += [ "${services_path}/bundlemgr/include/user_auth" ] - sources += user_auth - } - - if (bms_device_info_manager_part_enabled) { - external_deps += [ - "device_info_manager:distributed_device_profile_common", - "device_info_manager:distributed_device_profile_sdk", - ] - defines += [ "BMS_DEVICE_INFO_MANAGER_ENABLE" ] - } -} \ No newline at end of file -- Gitee From 91964a4d7659a919ac7f64c89fb9d5e63cc432e4 Mon Sep 17 00:00:00 2001 From: liuyaoqian Date: Mon, 30 Jun 2025 14:38:01 +0000 Subject: [PATCH 08/14] =?UTF-8?q?=E5=88=A0=E9=99=A4=E6=96=87=E4=BB=B6=20te?= =?UTF-8?q?st/fuzztest/fuzztest=5Fbundlemanager/bmsinstalldhostimpl=5Ffuzz?= =?UTF-8?q?er/bmsinstalldhostimpl=5Ffuzzer.cpp?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../bmsinstalldhostimpl_fuzzer.cpp | 313 ------------------ 1 file changed, 313 deletions(-) delete mode 100644 test/fuzztest/fuzztest_bundlemanager/bmsinstalldhostimpl_fuzzer/bmsinstalldhostimpl_fuzzer.cpp diff --git a/test/fuzztest/fuzztest_bundlemanager/bmsinstalldhostimpl_fuzzer/bmsinstalldhostimpl_fuzzer.cpp b/test/fuzztest/fuzztest_bundlemanager/bmsinstalldhostimpl_fuzzer/bmsinstalldhostimpl_fuzzer.cpp deleted file mode 100644 index 14d0bc9eca..0000000000 --- a/test/fuzztest/fuzztest_bundlemanager/bmsinstalldhostimpl_fuzzer/bmsinstalldhostimpl_fuzzer.cpp +++ /dev/null @@ -1,313 +0,0 @@ -/* - * 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 -#include -#include -#define private public -#include "installd_host_impl.h" -#include "bmsinstalldhostimpl_fuzzer.h" -#include "bms_fuzztest_util.h" - -using namespace OHOS::AppExecFwk; -using namespace OHOS::AppExecFwk::BMSFuzzTestUtil; -namespace OHOS { -bool DoSomethingInterestingWithMyAPI(const uint8_t* data, size_t size) -{ - auto installdhostimpl = std::make_shared(); - if (installdhostimpl == nullptr) { - return false; - } - FuzzedDataProvider fdp(data, size); - std::string bundle = ""; - std::string modulePath = ""; - std::string path = ""; - std::string path2 = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH); - std::string bundleDir = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH); - std::string srcModulePath = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH); - std::string targetPath = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH); - std::string targetSoPath = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH); - std::string filePath = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH); - std::string oldSoPath = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH); - std::string diffFilePath = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH); - std::string newSoPath = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH); - std::string srcPath = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH); - std::string realSoFilesPath = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH); - std::string hnpRootPath = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH); - std::string hapPath = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH); - std::string tmpSoPath = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH); - std::string destinationPath = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH); - std::string originPath = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH); - std::string cpuAbi = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH); - ExtractParam param; - param.srcPath = ""; - param.targetPath = ""; - param.cpuAbi = ""; - ExtractParam extractParam; - extractParam.srcPath = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH); - extractParam.targetPath = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH); - extractParam.cpuAbi = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH); - std::string packageInfo = ""; - std::string hnpPackageInfo = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH); - std::string userId = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH); - int32_t userId2 = GenerateRandomUser(fdp); - int userId3 = fdp.ConsumeIntegral(); - std::string packageName = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH); - AOTArgs aotArgs; - std::vector pendSignData; - std::string anFileName = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH); - std::vector signData; - std::vector dirs = GenerateStringArray(fdp); - std::string oldPath = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH); - std::string newPath = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH); - std::string bundleBackupDir = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH); - std::string bundleName = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH); - int32_t uid = fdp.ConsumeIntegral(); - int32_t gid = fdp.ConsumeIntegral(); - CreateDirParam createDirParam; - createDirParam.isPreInstallApp = false; - createDirParam.debug = false; - createDirParam.isDlpSandbox = false; - createDirParam.bundleName = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH); - createDirParam.userId = GenerateRandomUser(fdp); - createDirParam.uid = fdp.ConsumeIntegral(); - createDirParam.gid = fdp.ConsumeIntegral(); - createDirParam.appIndex = fdp.ConsumeIntegral(); - createDirParam.apl = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH); - createDirParam.uuid = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH); - createDirParam.extensionDirs.push_back("com.acts.example"); - CreateDirParam createDirParam2; - createDirParam2.bundleName = ""; - createDirParam2.userId = -1; - createDirParam2.uid = -1; - createDirParam2.gid = -1; - CodeSignatureParam codeSignatureParam; - codeSignatureParam.modulePath = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH); - codeSignatureParam.targetSoPath = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH); - codeSignatureParam.signatureFileDir = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH); - codeSignatureParam.appIdentifier = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH); - CodeSignatureParam codeSignatureParam2; - codeSignatureParam2.modulePath = ""; - std::vector createDirParams; - std::string parentDir = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH); - std::vector extensionDirs = GenerateStringArray(fdp); - std::vector extensionDirs2; - std::string el = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH); - int32_t mode = fdp.ConsumeIntegral(); - std::string bundleDataDir = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH); - int appIndex = fdp.ConsumeIntegral(); - int32_t appIndex2 = fdp.ConsumeIntegral(); - std::string dir = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH); - std::string dir2 = ""; - std::string srcDir = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH); - std::string desDir = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH); - std::string moduleDir = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH); - std::string extensionBundleDir = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH); - int64_t statSize = fdp.ConsumeIntegral(); - std::string dataDir = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH); - std::vector moduleNameList = GenerateStringArray(fdp); - uint32_t statFlag = fdp.ConsumeIntegral(); - std::vector bundleNames = GenerateStringArray(fdp); - std::unordered_map uidMap = {{"com.example.bundlekit.test", 10000}}; - std::unordered_multimap dirMap = {}; - std::vector bundleStats2; - std::vector bundleStats; - std::vector uids; - bool isRealPath = fdp.ConsumeBool(); - bool isPreInstallApp = fdp.ConsumeBool(); - bool debug = fdp.ConsumeBool(); - bool isDlpSandbox = fdp.ConsumeBool(); - bool isExist = fdp.ConsumeBool(); - bool isDirEmpty = fdp.ConsumeBool(); - bool isEncryption = fdp.ConsumeBool(); - bool async = fdp.ConsumeBool(); - std::string apl = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH); - unsigned int hapFlags = fdp.ConsumeIntegral(); - std::vector cachePath = GenerateStringArray(fdp); - ScanMode scanMode; - ResultMode resultMode; - std::vector paths = GenerateStringArray(fdp); - std::string signatureFilePath = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH); - std::string file = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH); - FileStat fileStat; - std::vector dirVec = GenerateStringArray(fdp); - std::string sourceDir = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH); - std::string destinationDir = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH); - std::vector fileNames = GenerateStringArray(fdp); - CheckEncryptionParam checkEncryptionParam; - checkEncryptionParam.modulePath = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH); - checkEncryptionParam.targetSoPath = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH); - checkEncryptionParam.appIdentifier = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH); - CheckEncryptionParam checkEncryptionParam2; - checkEncryptionParam2.modulePath = ""; - int32_t profileBlockLength = fdp.ConsumeIntegral(); - unsigned char *profileBlock = new unsigned char[0]; - std::string prefix = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH); - EncryptionParam encryptionParam; - encryptionParam.bundleName = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH); - encryptionParam.groupId = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH); - encryptionParam.userId = GenerateRandomUser(fdp); - EncryptionParam encryptionParam2; - encryptionParam2.bundleName = ""; - encryptionParam2.groupId = ""; - std::string keyId = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH); - std::vector extensionBundleDirs = GenerateStringArray(fdp); - std::vector extensionBundleDirs2; - std::vector typeList = GenerateStringArray(fdp); - std::vector sourcePaths = GenerateStringArray(fdp); - std::vector sourcePaths2; - std::vector params; - std::vector uuidList =GenerateStringArray(fdp); - std::vector uuidList2; - nlohmann::json object; - nlohmann::json jsonBuf; - std::string extensionTypeName = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH); - std::string uuid = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH); - - installdhostimpl->CreateBundleDir(bundle); - installdhostimpl->CreateBundleDir(bundleDir); - installdhostimpl->ExtractModuleFiles(modulePath, path, targetSoPath, cpuAbi); - installdhostimpl->ExtractModuleFiles(srcModulePath, targetPath, targetSoPath, cpuAbi); - installdhostimpl->ExtractFiles(param); - installdhostimpl->ExtractFiles(extractParam); - installdhostimpl->ExtractHnpFiles(packageInfo, param); - installdhostimpl->ExtractHnpFiles(hnpPackageInfo, extractParam); - installdhostimpl->ProcessBundleInstallNative(userId, hnpRootPath, hapPath, cpuAbi, packageName); - installdhostimpl->ProcessBundleUnInstallNative(userId, packageName); - installdhostimpl->ExecuteAOT(aotArgs, pendSignData); - installdhostimpl->PendSignAOT(anFileName, signData); - installdhostimpl->DeleteUninstallTmpDirs(dirs); - installdhostimpl->RenameModuleDir(path, modulePath); - installdhostimpl->RenameModuleDir(oldPath, newPath); - installdhostimpl->CreateSharefilesDataDirEl2(createDirParam); - installdhostimpl->CreateBundleDataDirWithVector(createDirParams); - installdhostimpl->AddUserDirDeleteDfx(userId2); - installdhostimpl->AclSetDir(false, dir, false, false); - installdhostimpl->AclSetDir(true, dir, true, false); - installdhostimpl->AclSetDir(true, dir, false, true); - installdhostimpl->AclSetDir(true, dir, false, false); - installdhostimpl->AclSetExtensionDirs(false, parentDir, extensionDirs, false, false); - installdhostimpl->AclSetExtensionDirs(true, parentDir, extensionDirs, false, false); - installdhostimpl->AclSetExtensionDirs(true, parentDir, extensionDirs2, false, false); - installdhostimpl->CreateBundleDataDir(createDirParam); - installdhostimpl->CreateBundleDataDir(createDirParam2); - installdhostimpl->CreateBundleDataDirWithEl(createDirParam); - installdhostimpl->CreateBundleDataDirWithEl(createDirParam2); - installdhostimpl->CreateCommonDataDir(createDirParam, el); - installdhostimpl->CreateEl2DataDir(createDirParam); - installdhostimpl->CreateExtensionDir(createDirParam, parentDir, mode, gid, false); - installdhostimpl->CreateExtensionDir(createDirParam2, parentDir, mode, gid, false); - installdhostimpl->CreateExtensionDir(createDirParam2, parentDir, mode, gid, true); - installdhostimpl->RemoveBundleDataDir("", userId2, true, false); - installdhostimpl->RemoveBundleDataDir(bundleName, userId2, true, false); - installdhostimpl->RemoveBundleDataDir(bundleName, userId2, false, false); - installdhostimpl->RemoveModuleDataDir(moduleDir, userId3); - installdhostimpl->RemoveModuleDataDir(dir2, userId3); - installdhostimpl->RemoveDir(dir); - installdhostimpl->RemoveDir(dir2); - installdhostimpl->GetDiskUsage(dir, statSize, isRealPath); - installdhostimpl->GetDiskUsageFromPath(paths, statSize); - installdhostimpl->CleanBundleDataDir(dir2); - installdhostimpl->CleanBundleDataDir(dataDir); - installdhostimpl->CleanBundleDataDirByName(bundle, userId3, appIndex); - installdhostimpl->CleanBundleDataDirByName(bundleName, userId3, appIndex); - installdhostimpl->GetBundleDataDir(el, userId3); - installdhostimpl->GetAppDataPath(bundleName, el, userId2, appIndex2); - installdhostimpl->GetAppCacheSize(bundleName, userId2, appIndex2, moduleNameList); - installdhostimpl->GetBundleStats(bundle, userId2, bundleStats, uid, appIndex2, statFlag, moduleNameList); - installdhostimpl->GetBundleStats(bundleName, userId2, bundleStats, uid, appIndex2, statFlag, moduleNameList); - installdhostimpl->BatchGetBundleStats(bundleNames, userId3, uidMap, bundleStats2); - installdhostimpl->GetAllBundleStats(userId2, bundleStats, uids); - installdhostimpl->GetHapFlags(isPreInstallApp, debug, isDlpSandbox); - installdhostimpl->SetDirApl(dir, bundleName, apl, isPreInstallApp, debug); - installdhostimpl->SetDirApl(dir, bundleName, apl, hapFlags); - installdhostimpl->SetArkStartupCacheApl(dir); - installdhostimpl->GetBundleCachePath(dir, cachePath); - installdhostimpl->GetBundleCachePath(dir2, cachePath); - installdhostimpl->ScanDir(dir, ScanMode::SUB_FILE_ALL, ResultMode::ABSOLUTE_PATH, paths); - installdhostimpl->ScanDir(dir2, ScanMode::SUB_FILE_ALL, ResultMode::ABSOLUTE_PATH, paths); - installdhostimpl->MoveFile(oldPath, newPath); - installdhostimpl->CopyFile(oldPath, newPath, path); - installdhostimpl->CopyFile(oldPath, newPath, signatureFilePath); - installdhostimpl->Mkdir(dir2, mode, uid, gid); - installdhostimpl->Mkdir(dir, mode, uid, gid); - installdhostimpl->GetFileStat(file, fileStat); - installdhostimpl->ExtractDiffFiles(path, path, cpuAbi); - installdhostimpl->ExtractDiffFiles(filePath, targetPath, cpuAbi); - installdhostimpl->ApplyDiffPatch(path, path, path, uid); - installdhostimpl->ApplyDiffPatch(oldSoPath, diffFilePath, newSoPath, uid); - installdhostimpl->IsExistDir(dir, isExist); - installdhostimpl->IsExistFile(path2, isExist); - installdhostimpl->IsExistApFile(path2, isExist); - installdhostimpl->IsDirEmpty(dir, isDirEmpty); - installdhostimpl->ObtainQuickFixFileDir(dir, dirVec); - installdhostimpl->CopyFiles(sourceDir, destinationDir); - installdhostimpl->GetNativeLibraryFileNames(path, cpuAbi, fileNames); - installdhostimpl->GetNativeLibraryFileNames(filePath, cpuAbi, fileNames); - installdhostimpl->VerifyCodeSignature(codeSignatureParam); - installdhostimpl->VerifyCodeSignature(codeSignatureParam2); - installdhostimpl->CheckEncryption(checkEncryptionParam, isEncryption); - installdhostimpl->CheckEncryption(checkEncryptionParam2, isEncryption); - installdhostimpl->MoveFiles(srcDir, desDir); - installdhostimpl->MoveFiles(dir2, desDir); - installdhostimpl->ExtractDriverSoFiles(srcPath, dirMap); - installdhostimpl->ExtractEncryptedSoFiles(hapPath, realSoFilesPath, cpuAbi, tmpSoPath, uid); - installdhostimpl->VerifyCodeSignatureForHap(codeSignatureParam); - installdhostimpl->DeliverySignProfile(bundleName, profileBlockLength, profileBlock); - installdhostimpl->RemoveSignProfile(bundleName); - installdhostimpl->CheckPathValid(path, prefix); - installdhostimpl->CheckPathValid(path2, prefix); - installdhostimpl->SetEncryptionPolicy(encryptionParam, keyId); - installdhostimpl->SetEncryptionPolicy(encryptionParam2, keyId); - installdhostimpl->DeleteEncryptionKeyId(encryptionParam); - installdhostimpl->DeleteEncryptionKeyId(encryptionParam2); - installdhostimpl->RemoveExtensionDir(userId2, extensionBundleDirs); - installdhostimpl->RemoveExtensionDir(userId2, extensionBundleDirs2); - installdhostimpl->RemoveExtensionDir(userId2, extensionBundleDir); - installdhostimpl->IsExistExtensionDir(userId2, extensionBundleDir, isExist); - installdhostimpl->CreateExtensionDataDir(createDirParam); - installdhostimpl->CreateExtensionDataDir(createDirParam2); - installdhostimpl->GetExtensionSandboxTypeList(typeList); - installdhostimpl->LoadNeedCreateSandbox(object, typeList); - installdhostimpl->LoadExtensionNeedCreateSandbox(object, extensionTypeName); - installdhostimpl->ReadFileIntoJson(filePath, jsonBuf); - installdhostimpl->InnerRemoveAtomicServiceBundleDataDir(bundleName, userId2, async); - installdhostimpl->InnerRemoveBundleDataDir(bundleName, userId2, async); - installdhostimpl->MigrateData(sourcePaths, destinationPath); - installdhostimpl->MigrateData(sourcePaths2, destinationPath); - installdhostimpl->MoveHapToCodeDir(originPath, targetPath); - installdhostimpl->GetGroupDirPath(el, userId2, uuid); - installdhostimpl->CreateDataGroupDirs(params); - installdhostimpl->CreateDataGroupDir(createDirParam); - installdhostimpl->CreateDataGroupDir(createDirParam2); - installdhostimpl->DeleteDataGroupDirs(uuidList, userId2); - installdhostimpl->DeleteDataGroupDirs(uuidList2, userId2); - installdhostimpl->DeleteEl5DataGroupDirs(uuidList, userId2); - installdhostimpl->DeleteEl5DataGroupDirs(uuidList2, userId2); - installdhostimpl->ClearDir(dir); - installdhostimpl->ClearDir(dir2); - installdhostimpl->GetExtensionConfigPath(); - installdhostimpl->StopAOT(); - return true; -} -} - -// Fuzzer entry point. -extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) -{ - // Run your code on data. - OHOS::DoSomethingInterestingWithMyAPI(data, size); - return 0; -} \ No newline at end of file -- Gitee From 15910880e8b7e1378f1aa55919f7632e29d0706e Mon Sep 17 00:00:00 2001 From: liuyaoqian Date: Mon, 30 Jun 2025 14:38:14 +0000 Subject: [PATCH 09/14] =?UTF-8?q?=E5=88=A0=E9=99=A4=E6=96=87=E4=BB=B6=20te?= =?UTF-8?q?st/fuzztest/fuzztest=5Fbundlemanager/bmsinstalldhostimpl=5Ffuzz?= =?UTF-8?q?er/bmsinstalldhostimpl=5Ffuzzer.h?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../bmsinstalldhostimpl_fuzzer.h | 21 ------------------- 1 file changed, 21 deletions(-) delete mode 100644 test/fuzztest/fuzztest_bundlemanager/bmsinstalldhostimpl_fuzzer/bmsinstalldhostimpl_fuzzer.h diff --git a/test/fuzztest/fuzztest_bundlemanager/bmsinstalldhostimpl_fuzzer/bmsinstalldhostimpl_fuzzer.h b/test/fuzztest/fuzztest_bundlemanager/bmsinstalldhostimpl_fuzzer/bmsinstalldhostimpl_fuzzer.h deleted file mode 100644 index 5cf13f0b5b..0000000000 --- a/test/fuzztest/fuzztest_bundlemanager/bmsinstalldhostimpl_fuzzer/bmsinstalldhostimpl_fuzzer.h +++ /dev/null @@ -1,21 +0,0 @@ -/* - * 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 TEST_FUZZTEST_BMS_INSTALLD_HOST_IMPL_FUZZER_H -#define TEST_FUZZTEST_BMS_INSTALLD_HOST_IMPL_FUZZER_H - -#define FUZZ_PROJECT_NAME "bmsinstalldhostimpl_fuzzer" - -#endif \ No newline at end of file -- Gitee From 37c35cdb81e79541c9af9de53f0a3dfd88c87b97 Mon Sep 17 00:00:00 2001 From: liuyaoqian Date: Mon, 30 Jun 2025 14:38:35 +0000 Subject: [PATCH 10/14] =?UTF-8?q?=E5=88=A0=E9=99=A4=E6=96=87=E4=BB=B6=20te?= =?UTF-8?q?st/fuzztest/fuzztest=5Fbundlemanager/bmsinstalldhostimpl=5Ffuzz?= =?UTF-8?q?er/project.xml?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../bmsinstalldhostimpl_fuzzer/project.xml | 25 ------------------- 1 file changed, 25 deletions(-) delete mode 100644 test/fuzztest/fuzztest_bundlemanager/bmsinstalldhostimpl_fuzzer/project.xml diff --git a/test/fuzztest/fuzztest_bundlemanager/bmsinstalldhostimpl_fuzzer/project.xml b/test/fuzztest/fuzztest_bundlemanager/bmsinstalldhostimpl_fuzzer/project.xml deleted file mode 100644 index 226522bd2a..0000000000 --- a/test/fuzztest/fuzztest_bundlemanager/bmsinstalldhostimpl_fuzzer/project.xml +++ /dev/null @@ -1,25 +0,0 @@ - - - - - - 10000 - - 300 - - 4096 - - -- Gitee From e7b0d33c4c21f2000d0b83d761264fee9888d47c Mon Sep 17 00:00:00 2001 From: liuyaoqian Date: Mon, 30 Jun 2025 14:38:54 +0000 Subject: [PATCH 11/14] =?UTF-8?q?=E5=88=A0=E9=99=A4=E6=96=87=E4=BB=B6=20te?= =?UTF-8?q?st/fuzztest/fuzztest=5Fbundlemanager/bmsinstalldloadcallback=5F?= =?UTF-8?q?fuzzer/BUILD.gn?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../bmsinstalldloadcallback_fuzzer/BUILD.gn | 190 ------------------ 1 file changed, 190 deletions(-) delete mode 100644 test/fuzztest/fuzztest_bundlemanager/bmsinstalldloadcallback_fuzzer/BUILD.gn diff --git a/test/fuzztest/fuzztest_bundlemanager/bmsinstalldloadcallback_fuzzer/BUILD.gn b/test/fuzztest/fuzztest_bundlemanager/bmsinstalldloadcallback_fuzzer/BUILD.gn deleted file mode 100644 index 8ff566869a..0000000000 --- a/test/fuzztest/fuzztest_bundlemanager/bmsinstalldloadcallback_fuzzer/BUILD.gn +++ /dev/null @@ -1,190 +0,0 @@ -# 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/ohos.gni") -import("//build/test.gni") -import("../../../../appexecfwk.gni") -import("../../../../services/bundlemgr/appexecfwk_bundlemgr.gni") -module_output_path = fuzz_test_path - -##############################fuzztest########################################## -ohos_fuzztest("BMSInstalldLoadCallbackFuzzTest") { - fuzz_config_file = "../../../fuzztest/fuzztest_bundlemanager/bmsinstalldloadcallback_fuzzer" - - use_exceptions = true - module_out_path = module_output_path - include_dirs = [ - "${test_path}/fuzztest", - "${services_path}/bundlemgr/include/installd", - ] - sources = bundle_mgr_source - sources += [ - "${services_path}/bundlemgr/src/aot/aot_executor.cpp", - "${services_path}/bundlemgr/src/installd/installd_host_impl.cpp", - "${services_path}/bundlemgr/src/installd/installd_operator.cpp", - "${services_path}/bundlemgr/src/installd/installd_service.cpp", - "${services_path}/bundlemgr/src/installd/installd_permission_mgr.cpp", - ] - - sources += bundle_install_sources - - sources += [ "bmsinstalldloadcallback_fuzzer.cpp" ] - - configs = [ "${services_path}/bundlemgr/test:bundlemgr_test_config" ] - cflags = [ - "-g", - "-O0", - "-Wno-unused-variable", - "-fno-omit-frame-pointer", - ] - - deps = [ "${core_path}:appexecfwk_core" ] - deps += bundle_install_deps - - external_deps = [ - "ability_base:want", - "ability_runtime:app_manager", - "access_token:el5_filekey_manager_sdk", - "access_token:libprivacy_sdk", - "access_token:libtokenid_sdk", - "appspawn:hnpapi", - "appverify:libhapverify", - "bounds_checking_function:libsec_shared", - "common_event_service:cesfwk_innerkits", - "eventhandler:libeventhandler", - "hilog:libhilog", - "hitrace:hitrace_meter", - "init:libbegetutil", - "jsoncpp:jsoncpp", - "safwk:system_ability_fwk", - "samgr:samgr_proxy", - "selinux_adapter:librestorecon", - ] - external_deps += bundle_install_external_deps - - defines = [] - if (code_signature_enable) { - sources += [ - "${services_path}/bundlemgr/src/aot/aot_sign_data_cache_mgr.cpp", - "${services_path}/bundlemgr/src/code_sign_helper.cpp", - ] - include_dirs += [ "${services_path}/bundlemgr/include" ] - external_deps += [ - "bounds_checking_function:libsec_shared", - "code_signature:libcode_sign_utils", - "ets_runtime:libcompiler_service", - ] - defines += [ "CODE_SIGNATURE_ENABLE" ] - } - - if (configpolicy_enable) { - external_deps += [ "config_policy:configpolicy_util" ] - defines += [ "CONFIG_POLOCY_ENABLE" ] - } - - if (bundle_framework_app_control) { - defines += [ "BUNDLE_FRAMEWORK_APP_CONTROL" ] - sources += [ - "${services_path}/bundlemgr/src/app_control/app_control_manager.cpp", - "${services_path}/bundlemgr/src/app_control/app_control_manager_host_impl.cpp", - "${services_path}/bundlemgr/src/app_control/app_control_manager_rdb.cpp", - "${services_path}/bundlemgr/src/app_control/app_jump_interceptor_event_subscriber.cpp", - "${services_path}/bundlemgr/src/app_control/app_jump_interceptor_manager_rdb.cpp", - ] - include_dirs += [ "${services_path}/bundlemgr/include/app_control" ] - external_deps += [ "c_utils:utils" ] - } - if (current_cpu == "arm64") { - defines += [ "USE_BUNDLE_EXTENSION" ] - } - - if (build_selinux) { - external_deps += [ "selinux_adapter:libhap_restorecon" ] - } - if (account_enable) { - external_deps += [ "os_account:os_account_innerkits" ] - defines += [ "ACCOUNT_ENABLE" ] - } - if (bundle_framework_free_install) { - sources += aging - sources += free_install - sources += distributed_manager - external_deps += [ - "ability_runtime:ability_manager", - "ability_runtime:app_manager", - "battery_manager:batterysrv_client", - "device_usage_statistics:usagestatsinner", - "display_manager:displaymgr", - "power_manager:powermgr_client", - "syscap_codec:syscap_interface_shared", - ] - defines += [ "BUNDLE_FRAMEWORK_FREE_INSTALL" ] - } - if (global_resmgr_enable) { - defines += [ "GLOBAL_RESMGR_ENABLE" ] - external_deps += [ "resource_management:global_resmgr" ] - } - if (hicollie_enable) { - external_deps += [ "hicollie:libhicollie" ] - defines += [ "HICOLLIE_ENABLE" ] - } - - if (hisysevent_enable) { - sources += [ "${services_path}/bundlemgr/src/inner_event_report.cpp" ] - external_deps += [ "hisysevent:libhisysevent" ] - defines += [ "HISYSEVENT_ENABLE" ] - } - - if (bundle_framework_quick_fix) { - include_dirs += [ "${services_path}/bundlemgr/src/include/quick_fix" ] - sources += quick_fix - defines += [ "BUNDLE_FRAMEWORK_QUICK_FIX" ] - } - - if (storage_service_enable) { - external_deps += [ "storage_service:storage_manager_sa_proxy" ] - defines += [ "STORAGE_SERVICE_ENABLE" ] - } - - external_deps += [ "kv_store:distributeddata_inner" ] - configs += [ "${services_path}/bundlemgr:rdb_config" ] - external_deps += [ "relational_store:native_rdb" ] - sources += [ - "${services_path}/bundlemgr/src/bundle_data_storage_rdb.cpp", - "${services_path}/bundlemgr/src/preinstall_data_storage_rdb.cpp", - "${services_path}/bundlemgr/src/rdb/bms_rdb_open_callback.cpp", - "${services_path}/bundlemgr/src/rdb/rdb_data_manager.cpp", - ] - if (udmf_enabled) { - defines += [ "BUNDLE_FRAMEWORK_UDMF_ENABLED" ] - external_deps += [ "udmf:udmf_client" ] - external_deps += [ "udmf:utd_client" ] - } - - if (user_auth_framework_impl_enabled) { - external_deps += [ "user_auth_framework:userauth_client" ] - defines += [ "BMS_USER_AUTH_FRAMEWORK_ENABLED" ] - include_dirs += [ "${services_path}/bundlemgr/include/user_auth" ] - sources += user_auth - } - - if (bms_device_info_manager_part_enabled) { - external_deps += [ - "device_info_manager:distributed_device_profile_common", - "device_info_manager:distributed_device_profile_sdk", - ] - defines += [ "BMS_DEVICE_INFO_MANAGER_ENABLE" ] - } -} \ No newline at end of file -- Gitee From 5d69e3a1392769fffabf999128a4aef8d699c1fd Mon Sep 17 00:00:00 2001 From: liuyaoqian Date: Mon, 30 Jun 2025 14:42:11 +0000 Subject: [PATCH 12/14] reset Signed-off-by: liuyaoqian --- .../bmsinstalldloadcallback_fuzzer/BUILD.gn | 190 ++++++++++++++++++ 1 file changed, 190 insertions(+) create mode 100644 test/fuzztest/fuzztest_bundlemanager/bmsinstalldloadcallback_fuzzer/BUILD.gn diff --git a/test/fuzztest/fuzztest_bundlemanager/bmsinstalldloadcallback_fuzzer/BUILD.gn b/test/fuzztest/fuzztest_bundlemanager/bmsinstalldloadcallback_fuzzer/BUILD.gn new file mode 100644 index 0000000000..53a6d87cc7 --- /dev/null +++ b/test/fuzztest/fuzztest_bundlemanager/bmsinstalldloadcallback_fuzzer/BUILD.gn @@ -0,0 +1,190 @@ +# 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/ohos.gni") +import("//build/test.gni") +import("../../../../appexecfwk.gni") +import("../../../../services/bundlemgr/appexecfwk_bundlemgr.gni") +module_output_path = fuzz_test_path + +##############################fuzztest########################################## +ohos_fuzztest("BMSInstalldLoadCallbackFuzzTest") { + fuzz_config_file = "../../../fuzztest/fuzztest_bundlemanager/bmsinstalldloadcallback_fuzzer" + + use_exceptions = true + module_out_path = module_output_path + include_dirs = [ + "${test_path}/fuzztest", + "${services_path}/bundlemgr/include/installd", + ] + sources = bundle_mgr_source + sources += [ + "${services_path}/bundlemgr/src/aot/aot_executor.cpp", + "${services_path}/bundlemgr/src/installd/installd_host_impl.cpp", + "${services_path}/bundlemgr/src/installd/installd_operator.cpp", + "${services_path}/bundlemgr/src/installd/installd_service.cpp", + "${services_path}/bundlemgr/src/installd/installd_permission_mgr.cpp", + ] + + sources += bundle_install_sources + + sources += [ "bmsinstalldloadcallback_fuzzer.cpp" ] + + configs = [ "${services_path}/bundlemgr/test:bundlemgr_test_config" ] + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + + deps = [ "${core_path}:appexecfwk_core" ] + deps += bundle_install_deps + + external_deps = [ + "ability_base:want", + "ability_runtime:app_manager", + "access_token:el5_filekey_manager_sdk", + "access_token:libprivacy_sdk", + "access_token:libtokenid_sdk", + "appspawn:hnpapi", + "appverify:libhapverify", + "bounds_checking_function:libsec_shared", + "common_event_service:cesfwk_innerkits", + "eventhandler:libeventhandler", + "hilog:libhilog", + "hitrace:hitrace_meter", + "init:libbegetutil", + "jsoncpp:jsoncpp", + "safwk:system_ability_fwk", + "samgr:samgr_proxy", + "selinux_adapter:librestorecon", + ] + external_deps += bundle_install_external_deps + + defines = [] + if (code_signature_enable) { + sources += [ + "${services_path}/bundlemgr/src/aot/aot_sign_data_cache_mgr.cpp", + "${services_path}/bundlemgr/src/code_sign_helper.cpp", + ] + include_dirs += [ "${services_path}/bundlemgr/include" ] + external_deps += [ + "bounds_checking_function:libsec_shared", + "code_signature:libcode_sign_utils", + "ets_runtime:libcompiler_service", + ] + defines += [ "CODE_SIGNATURE_ENABLE" ] + } + + if (configpolicy_enable) { + external_deps += [ "config_policy:configpolicy_util" ] + defines += [ "CONFIG_POLOCY_ENABLE" ] + } + + if (bundle_framework_app_control) { + defines += [ "BUNDLE_FRAMEWORK_APP_CONTROL" ] + sources += [ + "${services_path}/bundlemgr/src/app_control/app_control_manager.cpp", + "${services_path}/bundlemgr/src/app_control/app_control_manager_host_impl.cpp", + "${services_path}/bundlemgr/src/app_control/app_control_manager_rdb.cpp", + "${services_path}/bundlemgr/src/app_control/app_jump_interceptor_event_subscriber.cpp", + "${services_path}/bundlemgr/src/app_control/app_jump_interceptor_manager_rdb.cpp", + ] + include_dirs += [ "${services_path}/bundlemgr/include/app_control" ] + external_deps += [ "c_utils:utils" ] + } + if (current_cpu == "arm64") { + defines += [ "USE_BUNDLE_EXTENSION" ] + } + + if (build_selinux) { + external_deps += [ "selinux_adapter:libhap_restorecon" ] + } + if (account_enable) { + external_deps += [ "os_account:os_account_innerkits" ] + defines += [ "ACCOUNT_ENABLE" ] + } + if (bundle_framework_free_install) { + sources += aging + sources += free_install + sources += distributed_manager + external_deps += [ + "ability_runtime:ability_manager", + "ability_runtime:app_manager", + "battery_manager:batterysrv_client", + "device_usage_statistics:usagestatsinner", + "display_manager:displaymgr", + "power_manager:powermgr_client", + "syscap_codec:syscap_interface_shared", + ] + defines += [ "BUNDLE_FRAMEWORK_FREE_INSTALL" ] + } + if (global_resmgr_enable) { + defines += [ "GLOBAL_RESMGR_ENABLE" ] + external_deps += [ "resource_management:global_resmgr" ] + } + if (hicollie_enable) { + external_deps += [ "hicollie:libhicollie" ] + defines += [ "HICOLLIE_ENABLE" ] + } + + if (hisysevent_enable) { + sources += [ "${services_path}/bundlemgr/src/inner_event_report.cpp" ] + external_deps += [ "hisysevent:libhisysevent" ] + defines += [ "HISYSEVENT_ENABLE" ] + } + + if (bundle_framework_quick_fix) { + include_dirs += [ "${services_path}/bundlemgr/src/include/quick_fix" ] + sources += quick_fix + defines += [ "BUNDLE_FRAMEWORK_QUICK_FIX" ] + } + + if (storage_service_enable) { + external_deps += [ "storage_service:storage_manager_sa_proxy" ] + defines += [ "STORAGE_SERVICE_ENABLE" ] + } + + external_deps += [ "kv_store:distributeddata_inner" ] + configs += [ "${services_path}/bundlemgr:rdb_config" ] + external_deps += [ "relational_store:native_rdb" ] + sources += [ + "${services_path}/bundlemgr/src/bundle_data_storage_rdb.cpp", + "${services_path}/bundlemgr/src/preinstall_data_storage_rdb.cpp", + "${services_path}/bundlemgr/src/rdb/bms_rdb_open_callback.cpp", + "${services_path}/bundlemgr/src/rdb/rdb_data_manager.cpp", + ] + if (udmf_enabled) { + defines += [ "BUNDLE_FRAMEWORK_UDMF_ENABLED" ] + external_deps += [ "udmf:udmf_client" ] + external_deps += [ "udmf:utd_client" ] + } + + if (user_auth_framework_impl_enabled) { + external_deps += [ "user_auth_framework:userauth_client" ] + defines += [ "BMS_USER_AUTH_FRAMEWORK_ENABLED" ] + include_dirs += [ "${services_path}/bundlemgr/include/user_auth" ] + sources += user_auth + } + + if (bms_device_info_manager_part_enabled) { + external_deps += [ + "device_info_manager:distributed_device_profile_common", + "device_info_manager:distributed_device_profile_sdk", + ] + defines += [ "BMS_DEVICE_INFO_MANAGER_ENABLE" ] + } +} \ No newline at end of file -- Gitee From 5eee9f02157eb5d44a496bf961f614b72df5af90 Mon Sep 17 00:00:00 2001 From: liuyaoqian Date: Mon, 30 Jun 2025 14:42:49 +0000 Subject: [PATCH 13/14] =?UTF-8?q?=E5=88=A0=E9=99=A4=E6=96=87=E4=BB=B6=20te?= =?UTF-8?q?st/fuzztest/fuzztest=5Fbundlemanager/bmsinstalldhostimpl=5Ffuzz?= =?UTF-8?q?er/corpus/init?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../bmsinstalldhostimpl_fuzzer/corpus/init | 1 - 1 file changed, 1 deletion(-) delete mode 100644 test/fuzztest/fuzztest_bundlemanager/bmsinstalldhostimpl_fuzzer/corpus/init diff --git a/test/fuzztest/fuzztest_bundlemanager/bmsinstalldhostimpl_fuzzer/corpus/init b/test/fuzztest/fuzztest_bundlemanager/bmsinstalldhostimpl_fuzzer/corpus/init deleted file mode 100644 index 6b7212c8a6..0000000000 --- a/test/fuzztest/fuzztest_bundlemanager/bmsinstalldhostimpl_fuzzer/corpus/init +++ /dev/null @@ -1 +0,0 @@ -FUZZ \ No newline at end of file -- Gitee From b51419f32aec5e92616a60ac75d2c3172a32cbb4 Mon Sep 17 00:00:00 2001 From: liuyaoqian Date: Mon, 30 Jun 2025 14:43:16 +0000 Subject: [PATCH 14/14] update test/fuzztest/fuzztest_bundlemanager/BUILD.gn. Signed-off-by: liuyaoqian --- test/fuzztest/fuzztest_bundlemanager/BUILD.gn | 1 - 1 file changed, 1 deletion(-) diff --git a/test/fuzztest/fuzztest_bundlemanager/BUILD.gn b/test/fuzztest/fuzztest_bundlemanager/BUILD.gn index a9241dbc74..fb4e3da90b 100644 --- a/test/fuzztest/fuzztest_bundlemanager/BUILD.gn +++ b/test/fuzztest/fuzztest_bundlemanager/BUILD.gn @@ -90,7 +90,6 @@ group("bundlemanagerfuzztest") { "bmsgetnameforuid_fuzzer:BMSGetNameForUidFuzzTest", "bmsgetpermissiondef_fuzzer:BMSGetPermissionDefFuzzTest", "bmshapmoduleinfo_fuzzer:BMSHapModuleInfoFuzzTest", - "bmsinstalldhostimpl_fuzzer:BMSInstalldHostImplFuzzTest", "bmsinstalldloadcallback_fuzzer:BMSInstalldLoadCallbackFuzzTest", "bmsinstalldpermissionmgr_fuzzer:BMSInstalldPermissionMgrFuzzTest", "bmsinstalldservice_fuzzer:BMSInstalldServiceFuzzTest", -- Gitee