From e422dcadfe1acf1d632a2624baff75d486a1fcf0 Mon Sep 17 00:00:00 2001 From: zhaogan Date: Sun, 6 Jul 2025 09:31:03 +0800 Subject: [PATCH 1/2] add fuzz Signed-off-by: zhaogan --- test/fuzztest/bms_fuzztest_util.h | 15 ++ test/fuzztest/fuzztest_bundlemanager/BUILD.gn | 4 + .../BUILD.gn | 6 +- .../bmsbundleconnectabilitymgr_fuzzer.cpp | 200 ++++++++++++++++++ .../bmsbundleconnectabilitymgr_fuzzer.h} | 42 ++-- .../corpus/init | 0 .../project.xml | 0 .../bmscodesignatureparam_fuzzer/BUILD.gn | 188 ++++++++++++++++ .../bmscodesignatureparam_fuzzer.cpp} | 93 ++++---- .../bmscodesignatureparam_fuzzer.h | 21 ++ .../bmscodesignatureparam_fuzzer/corpus/init | 1 + .../bmscodesignatureparam_fuzzer/project.xml | 25 +++ .../bmscreatedirparam_fuzzer/BUILD.gn | 188 ++++++++++++++++ .../bmscreatedirparam_fuzzer.cpp | 47 ++++ .../bmscreatedirparam_fuzzer.h | 21 ++ .../bmscreatedirparam_fuzzer/corpus/init | 1 + .../bmscreatedirparam_fuzzer/project.xml | 25 +++ .../bmsencryptionparam_fuzzer/BUILD.gn | 188 ++++++++++++++++ .../bmsencryptionparam_fuzzer.cpp | 51 +++++ .../bmsencryptionparam_fuzzer.h | 21 ++ .../bmsencryptionparam_fuzzer/corpus/init | 1 + .../bmsencryptionparam_fuzzer/project.xml | 25 +++ 22 files changed, 1091 insertions(+), 72 deletions(-) rename test/fuzztest/fuzztest_bundlemanager/{bmsappservicefwkinstallerbeforeinstall_fuzzer copy => bmsbundleconnectabilitymgr_fuzzer}/BUILD.gn (97%) create mode 100644 test/fuzztest/fuzztest_bundlemanager/bmsbundleconnectabilitymgr_fuzzer/bmsbundleconnectabilitymgr_fuzzer.cpp rename test/fuzztest/fuzztest_bundlemanager/{bmsappservicefwkinstallerbeforeinstall_fuzzer copy/bmsappservicefwkinstallerbeforeinstall_fuzzer.h => bmsbundleconnectabilitymgr_fuzzer/bmsbundleconnectabilitymgr_fuzzer.h} (71%) rename test/fuzztest/fuzztest_bundlemanager/{bmsappservicefwkinstallerbeforeinstall_fuzzer copy => bmsbundleconnectabilitymgr_fuzzer}/corpus/init (100%) rename test/fuzztest/fuzztest_bundlemanager/{bmsappservicefwkinstallerbeforeinstall_fuzzer copy => bmsbundleconnectabilitymgr_fuzzer}/project.xml (100%) create mode 100644 test/fuzztest/fuzztest_bundlemanager/bmscodesignatureparam_fuzzer/BUILD.gn rename test/fuzztest/fuzztest_bundlemanager/{bmsappservicefwkinstallerbeforeinstall_fuzzer copy/bmsappservicefwkinstallerbeforeinstall_fuzzer.cpp => bmscodesignatureparam_fuzzer/bmscodesignatureparam_fuzzer.cpp} (70%) create mode 100644 test/fuzztest/fuzztest_bundlemanager/bmscodesignatureparam_fuzzer/bmscodesignatureparam_fuzzer.h create mode 100644 test/fuzztest/fuzztest_bundlemanager/bmscodesignatureparam_fuzzer/corpus/init create mode 100644 test/fuzztest/fuzztest_bundlemanager/bmscodesignatureparam_fuzzer/project.xml create mode 100644 test/fuzztest/fuzztest_bundlemanager/bmscreatedirparam_fuzzer/BUILD.gn create mode 100644 test/fuzztest/fuzztest_bundlemanager/bmscreatedirparam_fuzzer/bmscreatedirparam_fuzzer.cpp create mode 100644 test/fuzztest/fuzztest_bundlemanager/bmscreatedirparam_fuzzer/bmscreatedirparam_fuzzer.h create mode 100644 test/fuzztest/fuzztest_bundlemanager/bmscreatedirparam_fuzzer/corpus/init create mode 100644 test/fuzztest/fuzztest_bundlemanager/bmscreatedirparam_fuzzer/project.xml create mode 100644 test/fuzztest/fuzztest_bundlemanager/bmsencryptionparam_fuzzer/BUILD.gn create mode 100644 test/fuzztest/fuzztest_bundlemanager/bmsencryptionparam_fuzzer/bmsencryptionparam_fuzzer.cpp create mode 100644 test/fuzztest/fuzztest_bundlemanager/bmsencryptionparam_fuzzer/bmsencryptionparam_fuzzer.h create mode 100644 test/fuzztest/fuzztest_bundlemanager/bmsencryptionparam_fuzzer/corpus/init create mode 100644 test/fuzztest/fuzztest_bundlemanager/bmsencryptionparam_fuzzer/project.xml diff --git a/test/fuzztest/bms_fuzztest_util.h b/test/fuzztest/bms_fuzztest_util.h index 88b81dc862..a9401c67f4 100644 --- a/test/fuzztest/bms_fuzztest_util.h +++ b/test/fuzztest/bms_fuzztest_util.h @@ -26,6 +26,7 @@ #include "form_info.h" #include "install_param.h" #include "install_plugin_param.h" +#include "ipc/code_signature_param.h" #include "shortcut_info.h" namespace OHOS { @@ -631,6 +632,20 @@ int32_t GenerateRandomUser(FuzzedDataProvider& fdp) return USERS[index]; } +void GenerateCodeSignatureParam(FuzzedDataProvider& fdp, CodeSignatureParam &codeSignatureParam) +{ + codeSignatureParam.isEnterpriseBundle = fdp.ConsumeBool(); + codeSignatureParam.isPreInstalledBundle = fdp.ConsumeBool(); + codeSignatureParam.isCompileSdkOpenHarmony = fdp.ConsumeBool(); + codeSignatureParam.isInternaltestingBundle = fdp.ConsumeBool(); + codeSignatureParam.isCompressNativeLibrary = fdp.ConsumeBool(); + codeSignatureParam.modulePath = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH); + codeSignatureParam.cpuAbi = 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); +} + void GenerateHapModuleInfo(FuzzedDataProvider& fdp, HapModuleInfo &hapModuleInfo) { hapModuleInfo.compressNativeLibs = fdp.ConsumeBool(); diff --git a/test/fuzztest/fuzztest_bundlemanager/BUILD.gn b/test/fuzztest/fuzztest_bundlemanager/BUILD.gn index 57be731faf..ccce28c6ba 100644 --- a/test/fuzztest/fuzztest_bundlemanager/BUILD.gn +++ b/test/fuzztest/fuzztest_bundlemanager/BUILD.gn @@ -40,6 +40,7 @@ group("bundlemanagerfuzztest") { "bmsappservicefwkinstallerprocessnativelibrary_fuzzer:BMSAppServiceFwkInstallerProcessNativeLibraryFuzzTest", "bmsbundlecloneinstaller_fuzzer:BmsBundleCloneInstallerFuzzTest", "bmsapplicationinfofromjson_fuzzer:BMSApplicationInfoFromJsonFuzzTest", + "bmsbundleconnectabilitymgr_fuzzer:BMSBundleConnectAbilityMgrFuzzTest", "bmsbundlefileutil_fuzzer:BMSBundleFileUtilFuzzTest", "bmsbundleinfo_fuzzer:BMSBundleInfoFuzzTest", "bmsbundleinstallerhost_fuzzer:BMSBundleInstallerHostFuzzTest", @@ -71,10 +72,13 @@ group("bundlemanagerfuzztest") { "bmscleancachecallbackproxy_fuzzer:BMSCleanCacheCallbackProxyFuzzTest", "bmscheckabilityenableinstall_fuzzer:BMSCheckAbilityEnableInstallFuzzTest", "bmscompatibleabilityinfo_fuzzer:BMSCompatibleAbilityInfoFuzzTest", + "bmscodesignatureparam_fuzzer:BMSCodeSignatureParamFuzzTest", "bmscompatibleapplicationinfo_fuzzer:BMSCompatibleApplicationInfoFuzzTest", "bmsconverttargetabilityinfo_fuzzer:BMSConvertTargetAbilityInfoFuzzTest", + "bmscreatedirparam_fuzzer:BMSCreateDirParamFuzzTest", "bmsdeletefirstinstallbundleinfo_fuzzer:BMSDeleteFirstInstallBundleInfoFuzzTest", "bmsdriverinstaller_fuzzer:BMSDriverInstallerFuzzTest", + "bmsencryptionparam_fuzzer:BMSEncryptionParamFuzzTest", "bmsextendresourcemanager_fuzzer:BMSExtendResourceManagerFuzzTest", "bmsextensionabilityinfo_fuzzer:BMSExtensionAbilityInfoFuzzTest", "bmsfirstinstallbundleinfo_fuzzer:BMSFirstInstallBundleInfoFuzzTest", diff --git a/test/fuzztest/fuzztest_bundlemanager/bmsappservicefwkinstallerbeforeinstall_fuzzer copy/BUILD.gn b/test/fuzztest/fuzztest_bundlemanager/bmsbundleconnectabilitymgr_fuzzer/BUILD.gn similarity index 97% rename from test/fuzztest/fuzztest_bundlemanager/bmsappservicefwkinstallerbeforeinstall_fuzzer copy/BUILD.gn rename to test/fuzztest/fuzztest_bundlemanager/bmsbundleconnectabilitymgr_fuzzer/BUILD.gn index d842ad93a6..428b6c6e7d 100644 --- a/test/fuzztest/fuzztest_bundlemanager/bmsappservicefwkinstallerbeforeinstall_fuzzer copy/BUILD.gn +++ b/test/fuzztest/fuzztest_bundlemanager/bmsbundleconnectabilitymgr_fuzzer/BUILD.gn @@ -17,8 +17,8 @@ import("../../../../services/bundlemgr/appexecfwk_bundlemgr.gni") module_output_path = fuzz_test_path -ohos_fuzztest("BMSAppServiceFwkInstallerBeforeInstallFuzzTest") { - fuzz_config_file = "../../../fuzztest/fuzztest_bundlemanager/bmsappservicefwkinstallerbeforeinstall_fuzzer" +ohos_fuzztest("BMSBundleConnectAbilityMgrFuzzTest") { + fuzz_config_file = "../../../fuzztest/fuzztest_bundlemanager/bmsbundleconnectabilitymgr_fuzzer" use_exceptions = true module_out_path = module_output_path @@ -36,7 +36,7 @@ ohos_fuzztest("BMSAppServiceFwkInstallerBeforeInstallFuzzTest") { sources += bundle_install_sources - sources += [ "bmsappservicefwkinstallerbeforeinstall_fuzzer.cpp" ] + sources += [ "bmsbundleconnectabilitymgr_fuzzer.cpp" ] configs = [ "${services_path}/bundlemgr/test:bundlemgr_test_config" ] cflags = [ diff --git a/test/fuzztest/fuzztest_bundlemanager/bmsbundleconnectabilitymgr_fuzzer/bmsbundleconnectabilitymgr_fuzzer.cpp b/test/fuzztest/fuzztest_bundlemanager/bmsbundleconnectabilitymgr_fuzzer/bmsbundleconnectabilitymgr_fuzzer.cpp new file mode 100644 index 0000000000..6f5de9f3b9 --- /dev/null +++ b/test/fuzztest/fuzztest_bundlemanager/bmsbundleconnectabilitymgr_fuzzer/bmsbundleconnectabilitymgr_fuzzer.cpp @@ -0,0 +1,200 @@ +/* + * 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. + */ + +#define private public +#include +#include +#include + +#include "free_install/bundle_connect_ability_mgr.h" + +#include "bmsbundleconnectabilitymgr_fuzzer.h" +#include "bms_fuzztest_util.h" +#include "bundle_mgr_service.h" +#include "securec.h" + +using namespace OHOS::AppExecFwk; +using namespace OHOS::AppExecFwk::BMSFuzzTestUtil; +namespace OHOS { +constexpr int32_t USER_ID = 100; +constexpr int32_t WAIT_TIME = 5; +namespace AppExecFwk { +bool ExistBundleNameInCallingBundles( + const std::string &bundleName, const std::vector &callingBundleNames); +int32_t GetTargetInfoFlag(const Want &want, const std::string &deviceId, const std::string &bundleName, + const std::vector &callingBundleNames); +} +const std::string INSTALL_RESULT = R"( + { + "version":"123", + "result":{ + "retCode":123, + "transactId":"1", + "resultMsg":"2" + }, + "progress":{ + "downloadSize":1, + "totalSize":1 + } +})"; +const std::shared_ptr GetConnectAbilityMgrFromService() +{ + return DelayedSingleton::GetInstance()->GetConnectAbility(Constants::START_USERID); +} + +bool DoSomethingInterestingWithMyAPI(const uint8_t* data, size_t size) +{ + FuzzedDataProvider fdp(data, size); + auto bundleMgrService = DelayedSingleton::GetInstance(); + if (bundleMgrService == nullptr) { + return false; + } + if (!bundleMgrService->IsServiceReady()) { + bundleMgrService->OnStart(); + bundleMgrService->GetDataMgr()->AddUserId(USER_ID); + std::this_thread::sleep_for(std::chrono::seconds(WAIT_TIME)); + } + auto bundleConnectAbilityMgr = GetConnectAbilityMgrFromService(); + if (bundleConnectAbilityMgr == nullptr) { + return false; + } + + TargetAbilityInfo emptyTargetAbilityInfo; + bundleConnectAbilityMgr->ProcessPreloadCheck(emptyTargetAbilityInfo); + int32_t flag = fdp.ConsumeIntegral(); + bundleConnectAbilityMgr->ProcessPreloadRequestToServiceCenter(flag, emptyTargetAbilityInfo); + bundleConnectAbilityMgr->PreloadRequest(flag, emptyTargetAbilityInfo); + bundleConnectAbilityMgr->GetPreloadFlag(); + std::string bundleName = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH); + std::string moduleName = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH); + int32_t userId = GenerateRandomUser(fdp); + sptr targetAbilityInfoPtr = new TargetAbilityInfo(); + bundleConnectAbilityMgr->GetPreloadList(bundleName, moduleName, userId, targetAbilityInfoPtr); + std::string sysBundleName = "ohos.global.systemres"; + bundleConnectAbilityMgr->GetPreloadList(sysBundleName, moduleName, userId, targetAbilityInfoPtr); + std::string emptyModuleName; + bundleConnectAbilityMgr->GetPreloadList(sysBundleName, emptyModuleName, userId, targetAbilityInfoPtr); + + Want want; + FreeInstallParams freeInstallParams; + bundleConnectAbilityMgr->SilentInstall(emptyTargetAbilityInfo, want, freeInstallParams, userId); + bundleConnectAbilityMgr->UpgradeInstall(emptyTargetAbilityInfo, want, freeInstallParams, userId); + + bundleConnectAbilityMgr->CheckIsOnDemandLoad(emptyTargetAbilityInfo); + TargetAbilityInfo targetAbilityInfo1; + targetAbilityInfo1.targetInfo.callingBundleNames.emplace_back(bundleName); + targetAbilityInfo1.targetInfo.bundleName = bundleName; + bundleConnectAbilityMgr->CheckIsOnDemandLoad(targetAbilityInfo1); + bundleConnectAbilityMgr->SilentInstall(targetAbilityInfo1, want, freeInstallParams, userId); + + TargetAbilityInfo targetAbilityInfo2; + targetAbilityInfo2.targetInfo.callingBundleNames.emplace_back(bundleName); + targetAbilityInfo2.targetInfo.bundleName = "test"; + bundleConnectAbilityMgr->CheckIsOnDemandLoad(targetAbilityInfo2); + bundleConnectAbilityMgr->SilentInstall(targetAbilityInfo2, want, freeInstallParams, userId); + bundleConnectAbilityMgr->SendRequestToServiceCenter(flag, targetAbilityInfo2, want, userId, freeInstallParams); + + int32_t saId = fdp.ConsumeIntegral(); + bundleConnectAbilityMgr->LoadService(saId); + + std::mutex mutex; + std::unique_lock lock(mutex); + bundleConnectAbilityMgr->WaitFromConnecting(std::ref(lock)); + bundleConnectAbilityMgr->WaitFromConnected(std::ref(lock)); + lock.unlock(); + + bundleConnectAbilityMgr->connectState_ = ServiceCenterConnectState::CONNECTING; + sptr callerToken = nullptr; + bundleConnectAbilityMgr->ConnectAbility(want, callerToken); + bundleConnectAbilityMgr->DisconnectDelay(); + int32_t resultCode = fdp.ConsumeIntegral(); + std::string transactId = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH); + bundleConnectAbilityMgr->SendCallBack(resultCode, want, userId, transactId); + + sptr systemAbilityManager = + SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); + if (!systemAbilityManager) { + return false; + } + + sptr remoteObject = systemAbilityManager->GetSystemAbility(BUNDLE_MGR_SERVICE_SYS_ABILITY_ID); + freeInstallParams.callback = remoteObject; + bundleConnectAbilityMgr->SendCallBack(transactId, freeInstallParams); + bundleConnectAbilityMgr->freeInstallParamsMap_[bundleName] = freeInstallParams; + bundleConnectAbilityMgr->DeathRecipientSendCallback(); + + std::string installResultStr1 = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH); + bundleConnectAbilityMgr->OnServiceCenterReceived(installResultStr1); + bundleConnectAbilityMgr->OnServiceCenterReceived(INSTALL_RESULT); + bundleConnectAbilityMgr->freeInstallParamsMap_["1"] = freeInstallParams; + bundleConnectAbilityMgr->OnServiceCenterReceived(INSTALL_RESULT); + + bundleConnectAbilityMgr->OutTimeMonitor(transactId); + bundleConnectAbilityMgr->OutTimeMonitor("1"); + bundleConnectAbilityMgr->GetAbilityManagerServiceCallBack("1"); + int32_t callingUid = fdp.ConsumeIntegral(); + std::vector bundleNames = GenerateStringArray(fdp); + std::vector callingAppIds; + bundleConnectAbilityMgr->GetCallingInfo(userId, callingUid, bundleNames, callingAppIds); + std::vector callingBundleNames; + ExistBundleNameInCallingBundles(bundleName, callingBundleNames); + callingBundleNames.push_back(bundleName); + ExistBundleNameInCallingBundles(bundleName, callingBundleNames); + std::string deviceId = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH); + GetTargetInfoFlag(want, deviceId, bundleName, callingBundleNames); + + InnerBundleInfo innerBundleInfo; + bundleConnectAbilityMgr->GetTargetAbilityInfo(want, userId, innerBundleInfo, targetAbilityInfoPtr); + bundleConnectAbilityMgr->CheckSubPackageName(innerBundleInfo, want); + std::string testValue = "test"; + want.SetParam("ohos.param.atomicservice.subpackageName", testValue); + bundleConnectAbilityMgr->CheckSubPackageName(innerBundleInfo, want); + + bundleConnectAbilityMgr->CallAbilityManager(resultCode, want, userId, remoteObject); + bundleConnectAbilityMgr->CheckIsModuleNeedUpdate(innerBundleInfo, want, userId, remoteObject); + want.SetModuleName("entry"); + InnerModuleInfo innerModuleInfo; + innerModuleInfo.moduleName = "entry"; + innerModuleInfo.upgradeFlag = CODE_MAX_TWO; + innerBundleInfo.innerModuleInfos_["entry"] = innerModuleInfo; + bundleConnectAbilityMgr->CheckIsModuleNeedUpdate(innerBundleInfo, want, userId, remoteObject); + + AbilityInfo abilityInfo; + bundleConnectAbilityMgr->IsObtainAbilityInfo(want, flag, userId, abilityInfo, remoteObject, innerBundleInfo); + ElementName elementName("", "test", "", "entry"); + want.SetElement(elementName); + bundleConnectAbilityMgr->IsObtainAbilityInfo(want, flag, userId, abilityInfo, remoteObject, innerBundleInfo); + bundleConnectAbilityMgr->CheckIsModuleNeedUpdateWrap(innerBundleInfo, want, userId, remoteObject); + bundleConnectAbilityMgr->QueryAbilityInfo(want, flag, userId, abilityInfo, remoteObject); + bundleConnectAbilityMgr->SilentInstall(want, userId, remoteObject); + bundleConnectAbilityMgr->UpgradeAtomicService(want, userId); + ErmsCallerInfo callerInfo; + BmsExperienceRule rule; + bundleConnectAbilityMgr->CheckEcologicalRule(want, callerInfo, rule); + bundleConnectAbilityMgr->GetEcologicalCallerInfo(want, callerInfo, userId); + moduleName = "entry"; + bundleConnectAbilityMgr->GetModuleName(innerBundleInfo, want, moduleName); + + 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; +} diff --git a/test/fuzztest/fuzztest_bundlemanager/bmsappservicefwkinstallerbeforeinstall_fuzzer copy/bmsappservicefwkinstallerbeforeinstall_fuzzer.h b/test/fuzztest/fuzztest_bundlemanager/bmsbundleconnectabilitymgr_fuzzer/bmsbundleconnectabilitymgr_fuzzer.h similarity index 71% rename from test/fuzztest/fuzztest_bundlemanager/bmsappservicefwkinstallerbeforeinstall_fuzzer copy/bmsappservicefwkinstallerbeforeinstall_fuzzer.h rename to test/fuzztest/fuzztest_bundlemanager/bmsbundleconnectabilitymgr_fuzzer/bmsbundleconnectabilitymgr_fuzzer.h index e7b154fcf2..22f8febb09 100644 --- a/test/fuzztest/fuzztest_bundlemanager/bmsappservicefwkinstallerbeforeinstall_fuzzer copy/bmsappservicefwkinstallerbeforeinstall_fuzzer.h +++ b/test/fuzztest/fuzztest_bundlemanager/bmsbundleconnectabilitymgr_fuzzer/bmsbundleconnectabilitymgr_fuzzer.h @@ -1,21 +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_APPSERVICEFWKINSTALLERBEFOREINSTALL_FUZZER_H -#define TEST_FUZZTEST_BMS_APPSERVICEFWKINSTALLERBEFOREINSTALL_FUZZER_H - -#define FUZZ_PROJECT_NAME "bmsappservicefwkinstallerbeforeinstall_fuzzer" - -#endif \ No newline at end of file +/* + * 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_BUNDLE_CONNECT_ABILITY_MGR_FUZZER_H +#define TEST_FUZZTEST_BMS_BUNDLE_CONNECT_ABILITY_MGR_FUZZER_H + +#define FUZZ_PROJECT_NAME "bmsbundleconnectabilitymgr_fuzzer" + +#endif diff --git a/test/fuzztest/fuzztest_bundlemanager/bmsappservicefwkinstallerbeforeinstall_fuzzer copy/corpus/init b/test/fuzztest/fuzztest_bundlemanager/bmsbundleconnectabilitymgr_fuzzer/corpus/init similarity index 100% rename from test/fuzztest/fuzztest_bundlemanager/bmsappservicefwkinstallerbeforeinstall_fuzzer copy/corpus/init rename to test/fuzztest/fuzztest_bundlemanager/bmsbundleconnectabilitymgr_fuzzer/corpus/init diff --git a/test/fuzztest/fuzztest_bundlemanager/bmsappservicefwkinstallerbeforeinstall_fuzzer copy/project.xml b/test/fuzztest/fuzztest_bundlemanager/bmsbundleconnectabilitymgr_fuzzer/project.xml similarity index 100% rename from test/fuzztest/fuzztest_bundlemanager/bmsappservicefwkinstallerbeforeinstall_fuzzer copy/project.xml rename to test/fuzztest/fuzztest_bundlemanager/bmsbundleconnectabilitymgr_fuzzer/project.xml diff --git a/test/fuzztest/fuzztest_bundlemanager/bmscodesignatureparam_fuzzer/BUILD.gn b/test/fuzztest/fuzztest_bundlemanager/bmscodesignatureparam_fuzzer/BUILD.gn new file mode 100644 index 0000000000..3497399741 --- /dev/null +++ b/test/fuzztest/fuzztest_bundlemanager/bmscodesignatureparam_fuzzer/BUILD.gn @@ -0,0 +1,188 @@ +# 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. + +import("//build/test.gni") +import("../../../../appexecfwk.gni") +import("../../../../services/bundlemgr/appexecfwk_bundlemgr.gni") + +module_output_path = fuzz_test_path + +ohos_fuzztest("BMSCodeSignatureParamFuzzTest") { + fuzz_config_file = "../../../fuzztest/fuzztest_bundlemanager/bmscodesignatureparam_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", + ] + + sources += + [ "${services_path}/bundlemgr/src/installd/installd_permission_mgr.cpp" ] + + sources += bundle_install_sources + + sources += [ "bmscodesignatureparam_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" ] + } +} diff --git a/test/fuzztest/fuzztest_bundlemanager/bmsappservicefwkinstallerbeforeinstall_fuzzer copy/bmsappservicefwkinstallerbeforeinstall_fuzzer.cpp b/test/fuzztest/fuzztest_bundlemanager/bmscodesignatureparam_fuzzer/bmscodesignatureparam_fuzzer.cpp similarity index 70% rename from test/fuzztest/fuzztest_bundlemanager/bmsappservicefwkinstallerbeforeinstall_fuzzer copy/bmsappservicefwkinstallerbeforeinstall_fuzzer.cpp rename to test/fuzztest/fuzztest_bundlemanager/bmscodesignatureparam_fuzzer/bmscodesignatureparam_fuzzer.cpp index 668c4e642c..779f5f8625 100644 --- a/test/fuzztest/fuzztest_bundlemanager/bmsappservicefwkinstallerbeforeinstall_fuzzer copy/bmsappservicefwkinstallerbeforeinstall_fuzzer.cpp +++ b/test/fuzztest/fuzztest_bundlemanager/bmscodesignatureparam_fuzzer/bmscodesignatureparam_fuzzer.cpp @@ -1,48 +1,45 @@ -/* - * 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. - */ - -#define private public -#include -#include -#include - -#include "app_service_fwk/app_service_fwk_installer.h" - -#include "bmsappservicefwkinstallerbeforeinstall_fuzzer.h" -#include "bms_fuzztest_util.h" -#include "securec.h" - -using namespace OHOS::AppExecFwk; -using namespace OHOS::AppExecFwk::BMSFuzzTestUtil; -namespace OHOS { -bool DoSomethingInterestingWithMyAPI(const uint8_t* data, size_t size) -{ - InstallParam installParam; - FuzzedDataProvider fdp(data, size); - GenerateInstallParam(fdp, installParam); - AppServiceFwkInstaller appServicefwk; - std::vector hspPaths = GenerateStringArray(fdp); - appServicefwk.BeforeInstall(hspPaths, installParam); - 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 +/* + * 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 "ipc/code_signature_param.h" +#include "parcel.h" + +#include "bmscodesignatureparam_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) +{ + FuzzedDataProvider fdp(data, size); + CodeSignatureParam codeSignatureParam; + GenerateCodeSignatureParam(fdp, codeSignatureParam); + codeSignatureParam.ToString(); + 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; +} diff --git a/test/fuzztest/fuzztest_bundlemanager/bmscodesignatureparam_fuzzer/bmscodesignatureparam_fuzzer.h b/test/fuzztest/fuzztest_bundlemanager/bmscodesignatureparam_fuzzer/bmscodesignatureparam_fuzzer.h new file mode 100644 index 0000000000..3863648485 --- /dev/null +++ b/test/fuzztest/fuzztest_bundlemanager/bmscodesignatureparam_fuzzer/bmscodesignatureparam_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_CODE_SIGNATURE_PARAM_FUZZER_H +#define TEST_FUZZTEST_BMS_CODE_SIGNATURE_PARAM_FUZZER_H + +#define FUZZ_PROJECT_NAME "bmscodesignatureparam_fuzzer" + +#endif // TEST_FUZZTEST_BMS_CODE_SIGNATURE_PARAM_FUZZER_H diff --git a/test/fuzztest/fuzztest_bundlemanager/bmscodesignatureparam_fuzzer/corpus/init b/test/fuzztest/fuzztest_bundlemanager/bmscodesignatureparam_fuzzer/corpus/init new file mode 100644 index 0000000000..6b7212c8a6 --- /dev/null +++ b/test/fuzztest/fuzztest_bundlemanager/bmscodesignatureparam_fuzzer/corpus/init @@ -0,0 +1 @@ +FUZZ \ No newline at end of file diff --git a/test/fuzztest/fuzztest_bundlemanager/bmscodesignatureparam_fuzzer/project.xml b/test/fuzztest/fuzztest_bundlemanager/bmscodesignatureparam_fuzzer/project.xml new file mode 100644 index 0000000000..b04cd8961f --- /dev/null +++ b/test/fuzztest/fuzztest_bundlemanager/bmscodesignatureparam_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 5000 + + 300 + + 4096 + + diff --git a/test/fuzztest/fuzztest_bundlemanager/bmscreatedirparam_fuzzer/BUILD.gn b/test/fuzztest/fuzztest_bundlemanager/bmscreatedirparam_fuzzer/BUILD.gn new file mode 100644 index 0000000000..e20c6fbb72 --- /dev/null +++ b/test/fuzztest/fuzztest_bundlemanager/bmscreatedirparam_fuzzer/BUILD.gn @@ -0,0 +1,188 @@ +# 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. + +import("//build/test.gni") +import("../../../../appexecfwk.gni") +import("../../../../services/bundlemgr/appexecfwk_bundlemgr.gni") + +module_output_path = fuzz_test_path + +ohos_fuzztest("BMSCreateDirParamFuzzTest") { + fuzz_config_file = "../../../fuzztest/fuzztest_bundlemanager/bmscreatedirparam_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", + ] + + sources += + [ "${services_path}/bundlemgr/src/installd/installd_permission_mgr.cpp" ] + + sources += bundle_install_sources + + sources += [ "bmscreatedirparam_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" ] + } +} diff --git a/test/fuzztest/fuzztest_bundlemanager/bmscreatedirparam_fuzzer/bmscreatedirparam_fuzzer.cpp b/test/fuzztest/fuzztest_bundlemanager/bmscreatedirparam_fuzzer/bmscreatedirparam_fuzzer.cpp new file mode 100644 index 0000000000..2c57a5c50c --- /dev/null +++ b/test/fuzztest/fuzztest_bundlemanager/bmscreatedirparam_fuzzer/bmscreatedirparam_fuzzer.cpp @@ -0,0 +1,47 @@ +/* + * 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 "ipc/create_dir_param.h" +#include "parcel.h" + +#include "bmscreatedirparam_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) +{ + FuzzedDataProvider fdp(data, size); + CreateDirParam createDirParam; + createDirParam.extensionDirs = GenerateStringArray(fdp); + createDirParam.extensionDirs.emplace_back("test"); + Parcel dataMessageParcel; + createDirParam.Marshalling(dataMessageParcel); + 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; +} diff --git a/test/fuzztest/fuzztest_bundlemanager/bmscreatedirparam_fuzzer/bmscreatedirparam_fuzzer.h b/test/fuzztest/fuzztest_bundlemanager/bmscreatedirparam_fuzzer/bmscreatedirparam_fuzzer.h new file mode 100644 index 0000000000..2d0e1ba9e2 --- /dev/null +++ b/test/fuzztest/fuzztest_bundlemanager/bmscreatedirparam_fuzzer/bmscreatedirparam_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_CREATE_DIR_PARAM_FUZZER_H +#define TEST_FUZZTEST_BMS_CREATE_DIR_PARAM_FUZZER_H + +#define FUZZ_PROJECT_NAME "bmscreatedirparam_fuzzer" + +#endif // TEST_FUZZTEST_BMS_CREATE_DIR_PARAM_FUZZER_H diff --git a/test/fuzztest/fuzztest_bundlemanager/bmscreatedirparam_fuzzer/corpus/init b/test/fuzztest/fuzztest_bundlemanager/bmscreatedirparam_fuzzer/corpus/init new file mode 100644 index 0000000000..6b7212c8a6 --- /dev/null +++ b/test/fuzztest/fuzztest_bundlemanager/bmscreatedirparam_fuzzer/corpus/init @@ -0,0 +1 @@ +FUZZ \ No newline at end of file diff --git a/test/fuzztest/fuzztest_bundlemanager/bmscreatedirparam_fuzzer/project.xml b/test/fuzztest/fuzztest_bundlemanager/bmscreatedirparam_fuzzer/project.xml new file mode 100644 index 0000000000..b04cd8961f --- /dev/null +++ b/test/fuzztest/fuzztest_bundlemanager/bmscreatedirparam_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 5000 + + 300 + + 4096 + + diff --git a/test/fuzztest/fuzztest_bundlemanager/bmsencryptionparam_fuzzer/BUILD.gn b/test/fuzztest/fuzztest_bundlemanager/bmsencryptionparam_fuzzer/BUILD.gn new file mode 100644 index 0000000000..a41112359b --- /dev/null +++ b/test/fuzztest/fuzztest_bundlemanager/bmsencryptionparam_fuzzer/BUILD.gn @@ -0,0 +1,188 @@ +# 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. + +import("//build/test.gni") +import("../../../../appexecfwk.gni") +import("../../../../services/bundlemgr/appexecfwk_bundlemgr.gni") + +module_output_path = fuzz_test_path + +ohos_fuzztest("BMSEncryptionParamFuzzTest") { + fuzz_config_file = "../../../fuzztest/fuzztest_bundlemanager/bmsencryptionparam_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", + ] + + sources += + [ "${services_path}/bundlemgr/src/installd/installd_permission_mgr.cpp" ] + + sources += bundle_install_sources + + sources += [ "bmsencryptionparam_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" ] + } +} diff --git a/test/fuzztest/fuzztest_bundlemanager/bmsencryptionparam_fuzzer/bmsencryptionparam_fuzzer.cpp b/test/fuzztest/fuzztest_bundlemanager/bmsencryptionparam_fuzzer/bmsencryptionparam_fuzzer.cpp new file mode 100644 index 0000000000..a8677b9bd5 --- /dev/null +++ b/test/fuzztest/fuzztest_bundlemanager/bmsencryptionparam_fuzzer/bmsencryptionparam_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 + +#include "ipc/encryption_param.h" +#include "parcel.h" + +#include "bmsencryptionparam_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) +{ + FuzzedDataProvider fdp(data, size); + std::string name = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH); + std::string id = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH); + int32_t uidParam = fdp.ConsumeIntegral(); + int32_t userIdParam = fdp.ConsumeIntegral(); + EncryptionDirType dirType = fdp.ConsumeBool() ? EncryptionDirType::APP : EncryptionDirType::GROUP; + + EncryptionParam encryptionParam(name, id, uidParam, userIdParam, dirType); + Parcel dataMessageParcel; + encryptionParam.Marshalling(dataMessageParcel); + 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; +} diff --git a/test/fuzztest/fuzztest_bundlemanager/bmsencryptionparam_fuzzer/bmsencryptionparam_fuzzer.h b/test/fuzztest/fuzztest_bundlemanager/bmsencryptionparam_fuzzer/bmsencryptionparam_fuzzer.h new file mode 100644 index 0000000000..381f4307a5 --- /dev/null +++ b/test/fuzztest/fuzztest_bundlemanager/bmsencryptionparam_fuzzer/bmsencryptionparam_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_ENCRYPTION_PARAM_FUZZER_H +#define TEST_FUZZTEST_BMS_ENCRYPTION_PARAM_FUZZER_H + +#define FUZZ_PROJECT_NAME "bmsencryptionparam_fuzzer" + +#endif // TEST_FUZZTEST_BMS_ENCRYPTION_PARAM_FUZZER_H diff --git a/test/fuzztest/fuzztest_bundlemanager/bmsencryptionparam_fuzzer/corpus/init b/test/fuzztest/fuzztest_bundlemanager/bmsencryptionparam_fuzzer/corpus/init new file mode 100644 index 0000000000..6b7212c8a6 --- /dev/null +++ b/test/fuzztest/fuzztest_bundlemanager/bmsencryptionparam_fuzzer/corpus/init @@ -0,0 +1 @@ +FUZZ \ No newline at end of file diff --git a/test/fuzztest/fuzztest_bundlemanager/bmsencryptionparam_fuzzer/project.xml b/test/fuzztest/fuzztest_bundlemanager/bmsencryptionparam_fuzzer/project.xml new file mode 100644 index 0000000000..b04cd8961f --- /dev/null +++ b/test/fuzztest/fuzztest_bundlemanager/bmsencryptionparam_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 5000 + + 300 + + 4096 + + -- Gitee From dd838de9254e4429aa77aff5bd86796105b8d830 Mon Sep 17 00:00:00 2001 From: zhaogan Date: Mon, 7 Jul 2025 14:25:35 +0800 Subject: [PATCH 2/2] remove bundle_connect_ability Signed-off-by: zhaogan --- test/fuzztest/fuzztest_bundlemanager/BUILD.gn | 1 - .../BUILD.gn | 193 ----------------- .../bmsbundleconnectabilitymgr_fuzzer.cpp | 200 ------------------ .../bmsbundleconnectabilitymgr_fuzzer.h | 21 -- .../corpus/init | 1 - .../project.xml | 25 --- .../bmscodesignatureparam_fuzzer.cpp | 6 +- 7 files changed, 5 insertions(+), 442 deletions(-) delete mode 100644 test/fuzztest/fuzztest_bundlemanager/bmsbundleconnectabilitymgr_fuzzer/BUILD.gn delete mode 100644 test/fuzztest/fuzztest_bundlemanager/bmsbundleconnectabilitymgr_fuzzer/bmsbundleconnectabilitymgr_fuzzer.cpp delete mode 100644 test/fuzztest/fuzztest_bundlemanager/bmsbundleconnectabilitymgr_fuzzer/bmsbundleconnectabilitymgr_fuzzer.h delete mode 100644 test/fuzztest/fuzztest_bundlemanager/bmsbundleconnectabilitymgr_fuzzer/corpus/init delete mode 100644 test/fuzztest/fuzztest_bundlemanager/bmsbundleconnectabilitymgr_fuzzer/project.xml diff --git a/test/fuzztest/fuzztest_bundlemanager/BUILD.gn b/test/fuzztest/fuzztest_bundlemanager/BUILD.gn index ccce28c6ba..2df9823120 100644 --- a/test/fuzztest/fuzztest_bundlemanager/BUILD.gn +++ b/test/fuzztest/fuzztest_bundlemanager/BUILD.gn @@ -40,7 +40,6 @@ group("bundlemanagerfuzztest") { "bmsappservicefwkinstallerprocessnativelibrary_fuzzer:BMSAppServiceFwkInstallerProcessNativeLibraryFuzzTest", "bmsbundlecloneinstaller_fuzzer:BmsBundleCloneInstallerFuzzTest", "bmsapplicationinfofromjson_fuzzer:BMSApplicationInfoFromJsonFuzzTest", - "bmsbundleconnectabilitymgr_fuzzer:BMSBundleConnectAbilityMgrFuzzTest", "bmsbundlefileutil_fuzzer:BMSBundleFileUtilFuzzTest", "bmsbundleinfo_fuzzer:BMSBundleInfoFuzzTest", "bmsbundleinstallerhost_fuzzer:BMSBundleInstallerHostFuzzTest", diff --git a/test/fuzztest/fuzztest_bundlemanager/bmsbundleconnectabilitymgr_fuzzer/BUILD.gn b/test/fuzztest/fuzztest_bundlemanager/bmsbundleconnectabilitymgr_fuzzer/BUILD.gn deleted file mode 100644 index 428b6c6e7d..0000000000 --- a/test/fuzztest/fuzztest_bundlemanager/bmsbundleconnectabilitymgr_fuzzer/BUILD.gn +++ /dev/null @@ -1,193 +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. - -import("//build/test.gni") -import("../../../../appexecfwk.gni") -import("../../../../services/bundlemgr/appexecfwk_bundlemgr.gni") - -module_output_path = fuzz_test_path - -ohos_fuzztest("BMSBundleConnectAbilityMgrFuzzTest") { - fuzz_config_file = "../../../fuzztest/fuzztest_bundlemanager/bmsbundleconnectabilitymgr_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", - ] - - sources += - [ "${services_path}/bundlemgr/src/installd/installd_permission_mgr.cpp" ] - - sources += bundle_install_sources - - sources += [ "bmsbundleconnectabilitymgr_fuzzer.cpp" ] - - configs = [ "${services_path}/bundlemgr/test:bundlemgr_test_config" ] - cflags = [ - "-g", - "-O0", - "-Wno-unused-variable", - "-fno-omit-frame-pointer", - ] - - deps = [ - "${bundle_framework_path}/test/sceneProject/unittest/bundle_app_service/app_service_version1_library1:appService_v1_library1", - "${bundle_framework_path}/test/sceneProject/unittest/bundle_app_service/app_service_version1_library2:appService_v1_library2", - "${bundle_framework_path}/test/sceneProject/unittest/bundle_app_service/app_service_version2_library1:appService_v2_library1", - "${bundle_framework_path}/test/sceneProject/unittest/bundle_app_service/app_service_version2_library2:appService_v2_library2", - "${bundle_framework_path}/test/sceneProject/unittest/test_bundle/rightTest:rightTest", - "${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" ] - } -} diff --git a/test/fuzztest/fuzztest_bundlemanager/bmsbundleconnectabilitymgr_fuzzer/bmsbundleconnectabilitymgr_fuzzer.cpp b/test/fuzztest/fuzztest_bundlemanager/bmsbundleconnectabilitymgr_fuzzer/bmsbundleconnectabilitymgr_fuzzer.cpp deleted file mode 100644 index 6f5de9f3b9..0000000000 --- a/test/fuzztest/fuzztest_bundlemanager/bmsbundleconnectabilitymgr_fuzzer/bmsbundleconnectabilitymgr_fuzzer.cpp +++ /dev/null @@ -1,200 +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. - */ - -#define private public -#include -#include -#include - -#include "free_install/bundle_connect_ability_mgr.h" - -#include "bmsbundleconnectabilitymgr_fuzzer.h" -#include "bms_fuzztest_util.h" -#include "bundle_mgr_service.h" -#include "securec.h" - -using namespace OHOS::AppExecFwk; -using namespace OHOS::AppExecFwk::BMSFuzzTestUtil; -namespace OHOS { -constexpr int32_t USER_ID = 100; -constexpr int32_t WAIT_TIME = 5; -namespace AppExecFwk { -bool ExistBundleNameInCallingBundles( - const std::string &bundleName, const std::vector &callingBundleNames); -int32_t GetTargetInfoFlag(const Want &want, const std::string &deviceId, const std::string &bundleName, - const std::vector &callingBundleNames); -} -const std::string INSTALL_RESULT = R"( - { - "version":"123", - "result":{ - "retCode":123, - "transactId":"1", - "resultMsg":"2" - }, - "progress":{ - "downloadSize":1, - "totalSize":1 - } -})"; -const std::shared_ptr GetConnectAbilityMgrFromService() -{ - return DelayedSingleton::GetInstance()->GetConnectAbility(Constants::START_USERID); -} - -bool DoSomethingInterestingWithMyAPI(const uint8_t* data, size_t size) -{ - FuzzedDataProvider fdp(data, size); - auto bundleMgrService = DelayedSingleton::GetInstance(); - if (bundleMgrService == nullptr) { - return false; - } - if (!bundleMgrService->IsServiceReady()) { - bundleMgrService->OnStart(); - bundleMgrService->GetDataMgr()->AddUserId(USER_ID); - std::this_thread::sleep_for(std::chrono::seconds(WAIT_TIME)); - } - auto bundleConnectAbilityMgr = GetConnectAbilityMgrFromService(); - if (bundleConnectAbilityMgr == nullptr) { - return false; - } - - TargetAbilityInfo emptyTargetAbilityInfo; - bundleConnectAbilityMgr->ProcessPreloadCheck(emptyTargetAbilityInfo); - int32_t flag = fdp.ConsumeIntegral(); - bundleConnectAbilityMgr->ProcessPreloadRequestToServiceCenter(flag, emptyTargetAbilityInfo); - bundleConnectAbilityMgr->PreloadRequest(flag, emptyTargetAbilityInfo); - bundleConnectAbilityMgr->GetPreloadFlag(); - std::string bundleName = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH); - std::string moduleName = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH); - int32_t userId = GenerateRandomUser(fdp); - sptr targetAbilityInfoPtr = new TargetAbilityInfo(); - bundleConnectAbilityMgr->GetPreloadList(bundleName, moduleName, userId, targetAbilityInfoPtr); - std::string sysBundleName = "ohos.global.systemres"; - bundleConnectAbilityMgr->GetPreloadList(sysBundleName, moduleName, userId, targetAbilityInfoPtr); - std::string emptyModuleName; - bundleConnectAbilityMgr->GetPreloadList(sysBundleName, emptyModuleName, userId, targetAbilityInfoPtr); - - Want want; - FreeInstallParams freeInstallParams; - bundleConnectAbilityMgr->SilentInstall(emptyTargetAbilityInfo, want, freeInstallParams, userId); - bundleConnectAbilityMgr->UpgradeInstall(emptyTargetAbilityInfo, want, freeInstallParams, userId); - - bundleConnectAbilityMgr->CheckIsOnDemandLoad(emptyTargetAbilityInfo); - TargetAbilityInfo targetAbilityInfo1; - targetAbilityInfo1.targetInfo.callingBundleNames.emplace_back(bundleName); - targetAbilityInfo1.targetInfo.bundleName = bundleName; - bundleConnectAbilityMgr->CheckIsOnDemandLoad(targetAbilityInfo1); - bundleConnectAbilityMgr->SilentInstall(targetAbilityInfo1, want, freeInstallParams, userId); - - TargetAbilityInfo targetAbilityInfo2; - targetAbilityInfo2.targetInfo.callingBundleNames.emplace_back(bundleName); - targetAbilityInfo2.targetInfo.bundleName = "test"; - bundleConnectAbilityMgr->CheckIsOnDemandLoad(targetAbilityInfo2); - bundleConnectAbilityMgr->SilentInstall(targetAbilityInfo2, want, freeInstallParams, userId); - bundleConnectAbilityMgr->SendRequestToServiceCenter(flag, targetAbilityInfo2, want, userId, freeInstallParams); - - int32_t saId = fdp.ConsumeIntegral(); - bundleConnectAbilityMgr->LoadService(saId); - - std::mutex mutex; - std::unique_lock lock(mutex); - bundleConnectAbilityMgr->WaitFromConnecting(std::ref(lock)); - bundleConnectAbilityMgr->WaitFromConnected(std::ref(lock)); - lock.unlock(); - - bundleConnectAbilityMgr->connectState_ = ServiceCenterConnectState::CONNECTING; - sptr callerToken = nullptr; - bundleConnectAbilityMgr->ConnectAbility(want, callerToken); - bundleConnectAbilityMgr->DisconnectDelay(); - int32_t resultCode = fdp.ConsumeIntegral(); - std::string transactId = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH); - bundleConnectAbilityMgr->SendCallBack(resultCode, want, userId, transactId); - - sptr systemAbilityManager = - SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); - if (!systemAbilityManager) { - return false; - } - - sptr remoteObject = systemAbilityManager->GetSystemAbility(BUNDLE_MGR_SERVICE_SYS_ABILITY_ID); - freeInstallParams.callback = remoteObject; - bundleConnectAbilityMgr->SendCallBack(transactId, freeInstallParams); - bundleConnectAbilityMgr->freeInstallParamsMap_[bundleName] = freeInstallParams; - bundleConnectAbilityMgr->DeathRecipientSendCallback(); - - std::string installResultStr1 = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH); - bundleConnectAbilityMgr->OnServiceCenterReceived(installResultStr1); - bundleConnectAbilityMgr->OnServiceCenterReceived(INSTALL_RESULT); - bundleConnectAbilityMgr->freeInstallParamsMap_["1"] = freeInstallParams; - bundleConnectAbilityMgr->OnServiceCenterReceived(INSTALL_RESULT); - - bundleConnectAbilityMgr->OutTimeMonitor(transactId); - bundleConnectAbilityMgr->OutTimeMonitor("1"); - bundleConnectAbilityMgr->GetAbilityManagerServiceCallBack("1"); - int32_t callingUid = fdp.ConsumeIntegral(); - std::vector bundleNames = GenerateStringArray(fdp); - std::vector callingAppIds; - bundleConnectAbilityMgr->GetCallingInfo(userId, callingUid, bundleNames, callingAppIds); - std::vector callingBundleNames; - ExistBundleNameInCallingBundles(bundleName, callingBundleNames); - callingBundleNames.push_back(bundleName); - ExistBundleNameInCallingBundles(bundleName, callingBundleNames); - std::string deviceId = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH); - GetTargetInfoFlag(want, deviceId, bundleName, callingBundleNames); - - InnerBundleInfo innerBundleInfo; - bundleConnectAbilityMgr->GetTargetAbilityInfo(want, userId, innerBundleInfo, targetAbilityInfoPtr); - bundleConnectAbilityMgr->CheckSubPackageName(innerBundleInfo, want); - std::string testValue = "test"; - want.SetParam("ohos.param.atomicservice.subpackageName", testValue); - bundleConnectAbilityMgr->CheckSubPackageName(innerBundleInfo, want); - - bundleConnectAbilityMgr->CallAbilityManager(resultCode, want, userId, remoteObject); - bundleConnectAbilityMgr->CheckIsModuleNeedUpdate(innerBundleInfo, want, userId, remoteObject); - want.SetModuleName("entry"); - InnerModuleInfo innerModuleInfo; - innerModuleInfo.moduleName = "entry"; - innerModuleInfo.upgradeFlag = CODE_MAX_TWO; - innerBundleInfo.innerModuleInfos_["entry"] = innerModuleInfo; - bundleConnectAbilityMgr->CheckIsModuleNeedUpdate(innerBundleInfo, want, userId, remoteObject); - - AbilityInfo abilityInfo; - bundleConnectAbilityMgr->IsObtainAbilityInfo(want, flag, userId, abilityInfo, remoteObject, innerBundleInfo); - ElementName elementName("", "test", "", "entry"); - want.SetElement(elementName); - bundleConnectAbilityMgr->IsObtainAbilityInfo(want, flag, userId, abilityInfo, remoteObject, innerBundleInfo); - bundleConnectAbilityMgr->CheckIsModuleNeedUpdateWrap(innerBundleInfo, want, userId, remoteObject); - bundleConnectAbilityMgr->QueryAbilityInfo(want, flag, userId, abilityInfo, remoteObject); - bundleConnectAbilityMgr->SilentInstall(want, userId, remoteObject); - bundleConnectAbilityMgr->UpgradeAtomicService(want, userId); - ErmsCallerInfo callerInfo; - BmsExperienceRule rule; - bundleConnectAbilityMgr->CheckEcologicalRule(want, callerInfo, rule); - bundleConnectAbilityMgr->GetEcologicalCallerInfo(want, callerInfo, userId); - moduleName = "entry"; - bundleConnectAbilityMgr->GetModuleName(innerBundleInfo, want, moduleName); - - 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; -} diff --git a/test/fuzztest/fuzztest_bundlemanager/bmsbundleconnectabilitymgr_fuzzer/bmsbundleconnectabilitymgr_fuzzer.h b/test/fuzztest/fuzztest_bundlemanager/bmsbundleconnectabilitymgr_fuzzer/bmsbundleconnectabilitymgr_fuzzer.h deleted file mode 100644 index 22f8febb09..0000000000 --- a/test/fuzztest/fuzztest_bundlemanager/bmsbundleconnectabilitymgr_fuzzer/bmsbundleconnectabilitymgr_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_BUNDLE_CONNECT_ABILITY_MGR_FUZZER_H -#define TEST_FUZZTEST_BMS_BUNDLE_CONNECT_ABILITY_MGR_FUZZER_H - -#define FUZZ_PROJECT_NAME "bmsbundleconnectabilitymgr_fuzzer" - -#endif diff --git a/test/fuzztest/fuzztest_bundlemanager/bmsbundleconnectabilitymgr_fuzzer/corpus/init b/test/fuzztest/fuzztest_bundlemanager/bmsbundleconnectabilitymgr_fuzzer/corpus/init deleted file mode 100644 index 62d0290f27..0000000000 --- a/test/fuzztest/fuzztest_bundlemanager/bmsbundleconnectabilitymgr_fuzzer/corpus/init +++ /dev/null @@ -1 +0,0 @@ -FUZZ \ No newline at end of file diff --git a/test/fuzztest/fuzztest_bundlemanager/bmsbundleconnectabilitymgr_fuzzer/project.xml b/test/fuzztest/fuzztest_bundlemanager/bmsbundleconnectabilitymgr_fuzzer/project.xml deleted file mode 100644 index 66e1dcac47..0000000000 --- a/test/fuzztest/fuzztest_bundlemanager/bmsbundleconnectabilitymgr_fuzzer/project.xml +++ /dev/null @@ -1,25 +0,0 @@ - - - - - - 1000 - - 300 - - 4096 - - diff --git a/test/fuzztest/fuzztest_bundlemanager/bmscodesignatureparam_fuzzer/bmscodesignatureparam_fuzzer.cpp b/test/fuzztest/fuzztest_bundlemanager/bmscodesignatureparam_fuzzer/bmscodesignatureparam_fuzzer.cpp index 779f5f8625..4a83ba3baf 100644 --- a/test/fuzztest/fuzztest_bundlemanager/bmscodesignatureparam_fuzzer/bmscodesignatureparam_fuzzer.cpp +++ b/test/fuzztest/fuzztest_bundlemanager/bmscodesignatureparam_fuzzer/bmscodesignatureparam_fuzzer.cpp @@ -30,7 +30,11 @@ bool DoSomethingInterestingWithMyAPI(const uint8_t* data, size_t size) { FuzzedDataProvider fdp(data, size); CodeSignatureParam codeSignatureParam; - GenerateCodeSignatureParam(fdp, codeSignatureParam); + codeSignatureParam.isEnterpriseBundle = fdp.ConsumeBool(); + codeSignatureParam.isPreInstalledBundle = fdp.ConsumeBool(); + codeSignatureParam.isCompileSdkOpenHarmony = fdp.ConsumeBool(); + codeSignatureParam.isInternaltestingBundle = fdp.ConsumeBool(); + codeSignatureParam.isCompressNativeLibrary = fdp.ConsumeBool(); codeSignatureParam.ToString(); return true; } -- Gitee