diff --git a/test/fuzztest/BUILD.gn b/test/fuzztest/BUILD.gn index 201e76e1328531ca837461ce50107c7ab349d323..2d516cb649380598fb1ee283c8167e843a85d8d6 100644 --- a/test/fuzztest/BUILD.gn +++ b/test/fuzztest/BUILD.gn @@ -15,7 +15,7 @@ import("../../services/bundlemgr/appexecfwk_bundlemgr.gni") group("fuzztest") { testonly = true - deps = [] + deps = [ "fuzztest_bundlemanager:bundlemanagerfuzztest" ] deps += [ # deps file @@ -44,11 +44,6 @@ group("fuzztest") { "fuzztest_application/cleancachecallbackproxy_fuzzer:CleanCacheCallbackProxyFuzzTest", "fuzztest_application/defaultapphost_fuzzer:DefaultAppHostFuzzTest", "fuzztest_application/verifymanagerhost_fuzzer:VerifyManagerHostFuzzTest", - "fuzztest_bundlemanager/bmsappcontrolhost_fuzzer:BMSAppControlHostFuzzTest", - "fuzztest_bundlemanager/bmsapplicationinfo_fuzzer:BMSApplicationInfoFuzzTest", - "fuzztest_bundlemanager/bmsapplicationinfofromjson_fuzzer:BMSApplicationInfoFromJsonFuzzTest", - "fuzztest_bundlemanager/bmsbundlefileutil_fuzzer:BMSBundleFileUtilFuzzTest", - "fuzztest_bundlemanager/bmsbundleinfo_fuzzer:BMSBundleInfoFuzzTest", "fuzztest_information/abilityinfofromjson_fuzzer:AbilityInfoFromJsonFuzzTest", "fuzztest_information/abilityinfomarshalling_fuzzer:AbilityInfoMarshallingFuzzTest", "fuzztest_information/abilityinfounmarshalling_fuzzer:AbilityInfoUnmarshallingFuzzTest", @@ -271,11 +266,6 @@ group("fuzztest") { "fuzztest_application/apprunningcontrolruleresult_fuzzer:AppRunningControlRuleResultFuzzTest", "fuzztest_application/deleteappinstallcontrolrule_fuzzer:DeleteAppInstallControlRuleFuzzTest", "fuzztest_application/deleteapprunningcontrolrule_fuzzer:DeleteAppRunningControlRuleFuzzTest", - "fuzztest_bundlemanager/bmsaddappInstallcontrolrule_fuzzer:BMSAddAppInstallControlRuleFuzzTest", - "fuzztest_bundlemanager/bmsaddappjumpcontrolrule_fuzzer:BMSAddAppJumpControlRuleFuzzTest", - "fuzztest_bundlemanager/bmsaddapprunningcontrolrule_fuzzer:BMSAddAppRunningControlRuleFuzzTest", - "fuzztest_bundlemanager/bmsapprunningcontrolrule_fuzzer:BMSAppRunningControlRuleFuzzTest", - "fuzztest_bundlemanager/bmsapprunningcontrolruleresult_fuzzer:BMSAppRunningControlRuleResultFuzzTest", "fuzztest_information/getappinstallcontrolrule_fuzzer:GetAppInstallControlRuleFuzzTest", "fuzztest_information/getapprunningcontrolrule_fuzzer:GetAppRunningControlRuleFuzzTest", "fuzztest_information/getdisposedstatus_fuzzer:GetDisposedStatusFuzzTest", diff --git a/test/fuzztest/bms_fuzztest_util.h b/test/fuzztest/bms_fuzztest_util.h index 8332ef4c33106e1195a12af3061cadecbe50d69a..2ff0c16ec61f5e08204b76116485de6ce38454a6 100644 --- a/test/fuzztest/bms_fuzztest_util.h +++ b/test/fuzztest/bms_fuzztest_util.h @@ -21,7 +21,9 @@ #include #include -#include "application_info.h" +#include "bundle_info.h" +#include "bundle_user_info.h" +#include "install_param.h" namespace OHOS { namespace AppExecFwk { @@ -152,6 +154,241 @@ void GenerateApplicationInfo(FuzzedDataProvider& fdp, ApplicationInfo &applicati // Installation-free applicationInfo.targetBundleList = GenerateStringArray(fdp); } + +void GenerateSignatureInfo(FuzzedDataProvider& fdp, SignatureInfo &signatureInfo) +{ + signatureInfo.appId = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH); + signatureInfo.fingerprint = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH); + signatureInfo.appIdentifier = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH); + signatureInfo.certificate = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH); +} + +void GenerateAbilityInfo(FuzzedDataProvider& fdp, AbilityInfo &abilityInfo) +{ + abilityInfo.visible = fdp.ConsumeBool(); + abilityInfo.isLauncherAbility = fdp.ConsumeBool(); + abilityInfo.isNativeAbility = fdp.ConsumeBool(); + abilityInfo.enabled = fdp.ConsumeBool(); + abilityInfo.supportPipMode = fdp.ConsumeBool(); + abilityInfo.formEnabled = fdp.ConsumeBool(); + abilityInfo.removeMissionAfterTerminate = fdp.ConsumeBool(); + abilityInfo.isModuleJson = fdp.ConsumeBool(); + abilityInfo.isStageBasedModel = fdp.ConsumeBool(); + abilityInfo.continuable = fdp.ConsumeBool(); + // whether to display in the missions list + abilityInfo.excludeFromMissions = fdp.ConsumeBool(); + abilityInfo.unclearableMission = fdp.ConsumeBool(); + abilityInfo.excludeFromDock = fdp.ConsumeBool(); + // whether to support recover UI interface + abilityInfo.recoverable = fdp.ConsumeBool(); + abilityInfo.isolationProcess = fdp.ConsumeBool(); + abilityInfo.multiUserShared = fdp.ConsumeBool(); + abilityInfo.grantPermission = fdp.ConsumeBool(); + abilityInfo.directLaunch = fdp.ConsumeBool(); + + abilityInfo.linkType = static_cast(fdp.ConsumeIntegralInRange(0, 2)); + abilityInfo.labelId = fdp.ConsumeIntegral(); + abilityInfo.descriptionId = fdp.ConsumeIntegral(); + abilityInfo.iconId = fdp.ConsumeIntegral(); + abilityInfo.orientationId = fdp.ConsumeIntegral(); + abilityInfo.formEntity = fdp.ConsumeIntegral(); + abilityInfo.backgroundModes = fdp.ConsumeIntegral(); + abilityInfo.startWindowId = fdp.ConsumeIntegral(); + abilityInfo.startWindowIconId = fdp.ConsumeIntegral(); + abilityInfo.startWindowBackgroundId = fdp.ConsumeIntegral(); + abilityInfo.maxWindowWidth = fdp.ConsumeIntegral(); + abilityInfo.minWindowWidth = fdp.ConsumeIntegral(); + abilityInfo.maxWindowHeight = fdp.ConsumeIntegral(); + abilityInfo.minWindowHeight = fdp.ConsumeIntegral(); + abilityInfo.packageSize = fdp.ConsumeIntegral(); + abilityInfo.minFormHeight = fdp.ConsumeIntegral(); + abilityInfo.defaultFormHeight = fdp.ConsumeIntegral(); + abilityInfo.minFormWidth = fdp.ConsumeIntegral(); + abilityInfo.defaultFormWidth = fdp.ConsumeIntegral(); + abilityInfo.priority = fdp.ConsumeIntegral(); + abilityInfo.appIndex = fdp.ConsumeIntegral(); + abilityInfo.uid = fdp.ConsumeIntegral(); + abilityInfo.type = static_cast(fdp.ConsumeIntegralInRange(0, 5)); + abilityInfo.extensionAbilityType = static_cast(fdp.ConsumeIntegralInRange(0, 25)); + abilityInfo.orientation = static_cast(fdp.ConsumeIntegralInRange(0, 14)); + abilityInfo.launchMode = static_cast(fdp.ConsumeIntegralInRange(0, 2)); + abilityInfo.compileMode = static_cast(fdp.ConsumeIntegralInRange(0, 1)); + abilityInfo.subType = static_cast(fdp.ConsumeIntegralInRange(0, 1)); + + abilityInfo.name = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH); // ability name, only the main class name + abilityInfo.label = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH); + abilityInfo.description = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH); + abilityInfo.iconPath = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH); + abilityInfo.theme = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH); + abilityInfo.kind = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH); // ability category + abilityInfo.extensionTypeName = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH); + abilityInfo.srcPath = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH); + abilityInfo.srcLanguage = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH); + + abilityInfo.process = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH); + abilityInfo.uri = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH); + abilityInfo.targetAbility = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH); + abilityInfo.readPermission = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH); + abilityInfo.writePermission = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH); + + // set when install + abilityInfo.package = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH); // the "module.package" in config.json + abilityInfo.bundleName = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH); + abilityInfo.moduleName = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH); // the "module.name" in config.json + abilityInfo.applicationName = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH); // the "bundlename" in config.json + + abilityInfo.codePath = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH); // ability main code path with name + abilityInfo.resourcePath = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH); // resource path for resource init + abilityInfo.hapPath = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH); + + abilityInfo.srcEntrance = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH); + + // configuration fields on startup page + abilityInfo.startWindow = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH); + abilityInfo.startWindowIcon = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH); + abilityInfo.startWindowBackground = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH); + abilityInfo.preferMultiWindowOrientation = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH); + + abilityInfo.originalBundleName = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH); + abilityInfo.appName = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH); + abilityInfo.privacyUrl = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH); + abilityInfo.privacyName = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH); + abilityInfo.downloadUrl = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH); + abilityInfo.versionName = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH); + abilityInfo.className = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH); + abilityInfo.originalClassName = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH); + abilityInfo.uriPermissionMode = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH); + abilityInfo.uriPermissionPath = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH); + abilityInfo.libPath = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH); + abilityInfo.deviceId = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH); +} + +void GenerateBundleInfo(FuzzedDataProvider& fdp, BundleInfo &bundleInfo) +{ + bundleInfo.isNewVersion = fdp.ConsumeBool(); + bundleInfo.isKeepAlive = fdp.ConsumeBool(); + bundleInfo.singleton = fdp.ConsumeBool(); + bundleInfo.isPreInstallApp = fdp.ConsumeBool(); + bundleInfo.isNativeApp = fdp.ConsumeBool(); + bundleInfo.entryInstallationFree = fdp.ConsumeBool(); + bundleInfo.isDifferentName = fdp.ConsumeBool(); + bundleInfo.versionCode = fdp.ConsumeIntegral(); + bundleInfo.minCompatibleVersionCode = fdp.ConsumeIntegral(); + bundleInfo.compatibleVersion = fdp.ConsumeIntegral(); + bundleInfo.targetVersion = fdp.ConsumeIntegral(); + bundleInfo.appIndex = fdp.ConsumeIntegral(); + bundleInfo.minSdkVersion = fdp.ConsumeIntegral(); + bundleInfo.maxSdkVersion = fdp.ConsumeIntegral(); + bundleInfo.overlayType = fdp.ConsumeIntegralInRange(1, 3); + bundleInfo.uid = fdp.ConsumeIntegral(); + bundleInfo.gid = fdp.ConsumeIntegral(); + bundleInfo.installTime = fdp.ConsumeIntegral(); + bundleInfo.updateTime = fdp.ConsumeIntegral(); + bundleInfo.firstInstallTime = fdp.ConsumeIntegral(); + bundleInfo.name = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH); + bundleInfo.versionName = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH); + bundleInfo.vendor = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH); + bundleInfo.releaseType = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH); + bundleInfo.mainEntry = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH); + bundleInfo.entryModuleName = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH); + bundleInfo.appId = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH); + bundleInfo.cpuAbi = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH); + bundleInfo.seInfo = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH); + bundleInfo.label = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH); + bundleInfo.description = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH); + bundleInfo.jointUserId = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH); + + GenerateSignatureInfo(fdp, bundleInfo.signatureInfo); + + bundleInfo.oldAppIds = GenerateStringArray(fdp); + bundleInfo.hapModuleNames = GenerateStringArray(fdp); // the "module.package" in each config.json + bundleInfo.moduleNames = GenerateStringArray(fdp); // the "module.name" in each config.json + bundleInfo.modulePublicDirs = GenerateStringArray(fdp); // the public paths of all modules of the application. + bundleInfo.moduleDirs = GenerateStringArray(fdp); // the paths of all modules of the application. + bundleInfo.moduleResPaths = GenerateStringArray(fdp); // the paths of all resources paths. + + bundleInfo.reqPermissions = GenerateStringArray(fdp); + bundleInfo.defPermissions = GenerateStringArray(fdp); +} + +void GenerateMap(FuzzedDataProvider& fdp, std::map &data) +{ + // Generate number of key-value pairs (0 to 128) + const size_t num_pairs = fdp.ConsumeIntegralInRange(0, ARRAY_MAX_LENGTH); + + for (size_t i = 0; i < num_pairs; ++i) { + // Generate key with maximum length 128 + const std::string key = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH); + + // Generate value with maximum length 128 + const std::string value = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH); + + // Insert into map (allow overwriting existing keys) + data[key] = value; + } +} + +void GenerateInstallParam(FuzzedDataProvider& fdp, InstallParam &installParam) +{ + installParam.isKeepData = fdp.ConsumeBool(); + installParam.needSavePreInstallInfo = fdp.ConsumeBool(); + installParam.isPreInstallApp = fdp.ConsumeBool(); + installParam.removable = fdp.ConsumeBool(); + // whether need copy hap to install path + installParam.copyHapToInstallPath = fdp.ConsumeBool(); + // is aging Cause uninstall. + installParam.isAgingUninstall = fdp.ConsumeBool(); + installParam.needSendEvent = fdp.ConsumeBool(); + installParam.withCopyHaps = fdp.ConsumeBool(); + // for MDM self update + installParam.isSelfUpdate = fdp.ConsumeBool(); + // is shell token + installParam.isCallByShell = fdp.ConsumeBool(); + // for AOT + installParam.isOTA = fdp.ConsumeBool(); + installParam.concentrateSendEvent = fdp.ConsumeBool(); + installParam.isRemoveUser = fdp.ConsumeBool(); + installParam.allUser = fdp.ConsumeBool(); + installParam.isPatch = fdp.ConsumeBool(); + installParam.isDataPreloadHap = fdp.ConsumeBool(); + installParam.userId = fdp.ConsumeIntegral(); + installParam.installFlag = static_cast(fdp.ConsumeIntegralInRange(0, 1)); + installParam.installLocation = static_cast(fdp.ConsumeIntegralInRange(1, 2)); + installParam.installBundlePermissionStatus = + static_cast(fdp.ConsumeIntegralInRange(0, 2)); + installParam.installEnterpriseBundlePermissionStatus = + static_cast(fdp.ConsumeIntegralInRange(0, 2)); + installParam.installEtpNormalBundlePermissionStatus = + static_cast(fdp.ConsumeIntegralInRange(0, 2)); + installParam.installEtpMdmBundlePermissionStatus = + static_cast(fdp.ConsumeIntegralInRange(0, 2)); + installParam.installInternaltestingBundlePermissionStatus = + static_cast(fdp.ConsumeIntegralInRange(0, 2)); + installParam.installUpdateSelfBundlePermissionStatus = + static_cast(fdp.ConsumeIntegralInRange(0, 2)); + installParam.preinstallSourceFlag = static_cast(fdp.ConsumeIntegral()); + installParam.crowdtestDeadline = fdp.ConsumeIntegral(); // for crowdtesting type hap + // Indicates the distribution type + installParam.specifiedDistributionType = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH); + // Indicates the additional Info + installParam.additionalInfo = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH); + installParam.appIdentifier = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH); + // shared bundle directory paths + installParam.sharedBundleDirPaths = GenerateStringArray(fdp); + GenerateMap(fdp, installParam.parameters); + GenerateMap(fdp, installParam.pgoParams); + GenerateMap(fdp, installParam.hashParams); + GenerateMap(fdp, installParam.verifyCodeParams); +} + +void GenerateBundleUserInfo(FuzzedDataProvider& fdp, BundleUserInfo &bundleUserInfo) +{ + bundleUserInfo.enabled = fdp.ConsumeBool(); + bundleUserInfo.userId = fdp.ConsumeIntegral(); + bundleUserInfo.setEnabledCaller = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH); + bundleUserInfo.disabledAbilities = GenerateStringArray(fdp); + bundleUserInfo.overlayModulesState = GenerateStringArray(fdp); +} } // namespace BMSFuzzTestUtil } // namespace AppExecFwk } // namespace OHOS diff --git a/test/fuzztest/fuzztest_bundlemanager/BUILD.gn b/test/fuzztest/fuzztest_bundlemanager/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..3a4ab47b734a7a5792aee550a1bb7cae6e297079 --- /dev/null +++ b/test/fuzztest/fuzztest_bundlemanager/BUILD.gn @@ -0,0 +1,66 @@ +# 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("../../../services/bundlemgr/appexecfwk_bundlemgr.gni") + +group("bundlemanagerfuzztest") { + testonly = true + deps = [] + + deps += [ + # deps file + "bmsappcontrolhost_fuzzer:BMSAppControlHostFuzzTest", + "bmsapplicationinfo_fuzzer:BMSApplicationInfoFuzzTest", + "bmsapplicationinfofromjson_fuzzer:BMSApplicationInfoFromJsonFuzzTest", + "bmsbundlefileutil_fuzzer:BMSBundleFileUtilFuzzTest", + "bmsbundleinfo_fuzzer:BMSBundleInfoFuzzTest", + "bmsbundleinstallerhost_fuzzer:BMSBundleInstallerHostFuzzTest", + "bmsbundleinstallerproxy_fuzzer:BMSBundleInstallerProxyFuzzTest", + "bmsbundlemgrhost_fuzzer:BMSBundleMgrHostFuzzTest", + "bmsbundlemgrproxypartfour_fuzzer:BMSBundleMgrProxyFuzzPartFourTest", + "bmsbundlemgrproxypartone_fuzzer:BMSBundleMgrProxyFuzzPartOneTest", + "bmsbundlemgrproxypartthree_fuzzer:BMSBundleMgrProxyFuzzPartThreeTest", + "bmsbundlemgrproxyparttwo_fuzzer:BMSBundleMgrProxyFuzzPartTwoTest", + "bmsbundleresourcehost_fuzzer:BMSBundleResourceHostFuzzTest", + "bmsbundlestatuscallbackproxy_fuzzer:BMSBundleStatusCallbackProxyFuzzTest", + "bmsbundlestreaminstallerhost_fuzzer:BMSBundleStreamInstallerHostFuzzTest", + "bmsbundlestreaminstallerproxy_fuzzer:BMSBundleStreamInstallerProxyFuzzTest", + "bmsbundlesyscap_fuzzer:BMSBundleSysCapFuzzTest", + "bmsbundleuserinfo_fuzzer:BMSBundleUserInfoFuzzTest", + "bmsbundleusermgrhost_fuzzer:BMSBundleUserMgrHostFuzzTest", + "bmsbundleusermgrproxy_fuzzer:BMSBundleUserMgrProxyFuzzTest", + "bmscheckissystemappbyuid_fuzzer:BMSCheckIsSystemAppByUidFuzzTest", + "bmscleanbundlecachefiles_fuzzer:BMSCleanBundleCacheFilesFuzzTest", + "bmscleanbundledatafiles_fuzzer:BMSCleanBundleDataFilesFuzzTest", + "bmscleancachecallbackproxy_fuzzer:BMSCleanCacheCallbackProxyFuzzTest", + "bmsverifymanagerhost_fuzzer:BMSVerifyManagerHostFuzzTest" + ] + + if (bundle_framework_default_app) { + deps += [ + "bmsdefaultapphost_fuzzer:BMSDefaultAppHostFuzzTest" + ] + } + + if (bundle_framework_app_control) { + deps += [ + "bmsaddappInstallcontrolrule_fuzzer:BMSAddAppInstallControlRuleFuzzTest", + "bmsaddappjumpcontrolrule_fuzzer:BMSAddAppJumpControlRuleFuzzTest", + "bmsaddapprunningcontrolrule_fuzzer:BMSAddAppRunningControlRuleFuzzTest", + "bmsapprunningcontrolrule_fuzzer:BMSAppRunningControlRuleFuzzTest", + "bmsapprunningcontrolruleresult_fuzzer:BMSAppRunningControlRuleResultFuzzTest", + "bmsdeleteappinstallcontrolrule_fuzzer:BMSDeleteAppInstallControlRuleFuzzTest", + "bmsdeleteapprunningcontrolrule_fuzzer:BMSDeleteAppRunningControlRuleFuzzTest" + ] + } +} \ No newline at end of file diff --git a/test/fuzztest/fuzztest_bundlemanager/bmsbundleinfo_fuzzer/bmsbundleinfo_fuzzer.cpp b/test/fuzztest/fuzztest_bundlemanager/bmsbundleinfo_fuzzer/bmsbundleinfo_fuzzer.cpp index 19aca6f4083129156e81a38f76fa4a1491bdd770..89d792146f45d10978cccf6c3b9db0ceebda5774 100644 --- a/test/fuzztest/fuzztest_bundlemanager/bmsbundleinfo_fuzzer/bmsbundleinfo_fuzzer.cpp +++ b/test/fuzztest/fuzztest_bundlemanager/bmsbundleinfo_fuzzer/bmsbundleinfo_fuzzer.cpp @@ -28,7 +28,8 @@ namespace OHOS { { Parcel dataMessageParcel; BundleInfo oldBundleInfo; - oldBundleInfo.name = std::string(reinterpret_cast(data), size); + FuzzedDataProvider fdp(data, size); + AppExecFwk::BMSFuzzTestUtil::GenerateBundleInfo(fdp, oldBundleInfo); if (!oldBundleInfo.Marshalling(dataMessageParcel)) { return false; } diff --git a/test/fuzztest/fuzztest_bundlemanager/bmsbundleinfo_fuzzer/project.xml b/test/fuzztest/fuzztest_bundlemanager/bmsbundleinfo_fuzzer/project.xml index 85e7ef2c1cc6471e288306f6e3dcea5287a78b0e..f2626d206fb41dddaab90cd95758517d7bb93519 100644 --- a/test/fuzztest/fuzztest_bundlemanager/bmsbundleinfo_fuzzer/project.xml +++ b/test/fuzztest/fuzztest_bundlemanager/bmsbundleinfo_fuzzer/project.xml @@ -16,9 +16,9 @@ - 1000 + 10000 - 300 + 600 4096 diff --git a/test/fuzztest/fuzztest_bundlemanager/bmsbundleinfofromjson_fuzzer/BUILD.gn b/test/fuzztest/fuzztest_bundlemanager/bmsbundleinfofromjson_fuzzer/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..636e463eb100ba7f372e6c6ea4fc2a13be540b57 --- /dev/null +++ b/test/fuzztest/fuzztest_bundlemanager/bmsbundleinfofromjson_fuzzer/BUILD.gn @@ -0,0 +1,44 @@ +# 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") +module_output_path = fuzz_test_path + +##############################fuzztest########################################## +ohos_fuzztest("BMSBundleInfoFromJsonFuzzTest") { + module_out_path = module_output_path + fuzz_config_file = + "../../../fuzztest/fuzztest_bundlemanager/bmsbundleinfofromjson_fuzzer" + + configs = [ "${bundle_framework_path}/services/bundlemgr/test/unittest/bms_bundle_data_storage_test:private_config" ] + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + sources = [ "bmsbundleinfofromjson_fuzzer.cpp" ] + + deps = [ + "${base_path}:appexecfwk_base", + "${common_path}:libappexecfwk_common", + ] + external_deps = [ + "c_utils:utils", + "ipc:ipc_core", + ] +} diff --git a/test/fuzztest/fuzztest_bundlemanager/bmsbundleinfofromjson_fuzzer/bmsbundleinfofromjson_fuzzer.cpp b/test/fuzztest/fuzztest_bundlemanager/bmsbundleinfofromjson_fuzzer/bmsbundleinfofromjson_fuzzer.cpp new file mode 100644 index 0000000000000000000000000000000000000000..293bb0308e2cfdbcaadadb36d51f2da6b4eeac4b --- /dev/null +++ b/test/fuzztest/fuzztest_bundlemanager/bmsbundleinfofromjson_fuzzer/bmsbundleinfofromjson_fuzzer.cpp @@ -0,0 +1,49 @@ +/* + * 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 "bundle_info.h" +#include "json_serializer.h" +#include "nlohmann/json.hpp" +#include "../../bms_fuzztest_util.h" + +#include "bmsbundleinfofromjson_fuzzer.h" + +using namespace OHOS::AppExecFwk; +namespace OHOS { +namespace { +const char NAME[] = "name"; +} + bool DoSomethingInterestingWithMyAPI(const uint8_t* data, size_t size) + { + nlohmann::json infoJson; + FuzzedDataProvider fdp(data, size); + std::string name = fdp.ConsumeRandomLengthString(BMSFuzzTestUtil::STRING_MAX_LENGTH);; + infoJson[NAME] = name; + BundleInfo bundleInfo = infoJson; + 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/bmsbundleinfofromjson_fuzzer/bmsbundleinfofromjson_fuzzer.h b/test/fuzztest/fuzztest_bundlemanager/bmsbundleinfofromjson_fuzzer/bmsbundleinfofromjson_fuzzer.h new file mode 100644 index 0000000000000000000000000000000000000000..12d112190dd8b1baf13b1079aba5da0b9294f76b --- /dev/null +++ b/test/fuzztest/fuzztest_bundlemanager/bmsbundleinfofromjson_fuzzer/bmsbundleinfofromjson_fuzzer.h @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2022 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_BUNDLEINFO_FROM_JSON_FUZZER_H +#define TEST_FUZZTEST_BMS_BUNDLEINFO_FROM_JSON_FUZZER_H + +#define FUZZ_PROJECT_NAME "bmsbundleInfoFromJson_fuzzer" + +#endif \ No newline at end of file diff --git a/test/fuzztest/fuzztest_bundlemanager/bmsbundleinfofromjson_fuzzer/corpus/init b/test/fuzztest/fuzztest_bundlemanager/bmsbundleinfofromjson_fuzzer/corpus/init new file mode 100644 index 0000000000000000000000000000000000000000..bc977bd9738ee9a70b362067f57a9c63d3adb801 --- /dev/null +++ b/test/fuzztest/fuzztest_bundlemanager/bmsbundleinfofromjson_fuzzer/corpus/init @@ -0,0 +1,14 @@ +# Copyright (c) 2022 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +FUZZ \ No newline at end of file diff --git a/test/fuzztest/fuzztest_bundlemanager/bmsbundleinfofromjson_fuzzer/project.xml b/test/fuzztest/fuzztest_bundlemanager/bmsbundleinfofromjson_fuzzer/project.xml new file mode 100644 index 0000000000000000000000000000000000000000..85e7ef2c1cc6471e288306f6e3dcea5287a78b0e --- /dev/null +++ b/test/fuzztest/fuzztest_bundlemanager/bmsbundleinfofromjson_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/test/fuzztest/fuzztest_bundlemanager/bmsbundleinstalldhost_fuzzer/BUILD.gn b/test/fuzztest/fuzztest_bundlemanager/bmsbundleinstalldhost_fuzzer/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..a292ea2d0b7cbf88cd1db8fef949271b66845782 --- /dev/null +++ b/test/fuzztest/fuzztest_bundlemanager/bmsbundleinstalldhost_fuzzer/BUILD.gn @@ -0,0 +1,155 @@ +# Copyright (c) 2023 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("BundleInstalldHostFuzzTest") { + module_out_path = module_output_path + fuzz_config_file = + "../../../fuzztest/fuzztest_bundlemanager/bmsbundleinstalldhost_fuzzer" + + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + + use_exceptions = true + + sources = bundle_mgr_source + sources -= [ "${services_path}/bundlemgr/src/system_ability_helper.cpp" ] + 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/test/mock/src/installd_service.cpp", + ] + + sources += [ + "${services_path}/bundlemgr/test/mock/src/installd_permission_mgr.cpp", + "${services_path}/bundlemgr/test/mock/src/mock_bundle_status.cpp", + "${services_path}/bundlemgr/test/mock/src/system_ability_helper.cpp", + ] + + sources += bundle_install_sources + + configs = [ "${services_path}/bundlemgr/test:bundlemgr_test_config" ] + + deps = bundle_install_deps + deps += [ + "${base_path}:appexecfwk_base", + "${core_path}:appexecfwk_core", + ] + + external_deps = [ + "ability_runtime:ability_manager", + "access_token:el5_filekey_manager_sdk", + "access_token:libprivacy_sdk", + "access_token:libtokenid_sdk", + "appspawn:hnpapi", + "appverify:libhapverify", + "bounds_checking_function:libsec_shared", + "c_utils:utils", + "common_event_service:cesfwk_core", + "common_event_service:cesfwk_innerkits", + "eventhandler:libeventhandler", + "hilog:libhilog", + "hitrace:hitrace_meter", + "init:libbegetutil", + "ipc:ipc_core", + "safwk:system_ability_fwk", + "samgr:samgr_proxy", + "selinux_adapter:librestorecon", + ] + + external_deps += [ + "ability_runtime:ability_manager", + "ability_runtime:app_manager", + "battery_manager:batterysrv_client", + "display_manager:displaymgr", + "ffrt:libffrt", + "power_manager:powermgr_client", + "syscap_codec:syscap_interface_shared", + ] + + external_deps += bundle_install_external_deps + + if (bundle_framework_power_mgr_enable) { + external_deps += aot_external_deps + } + + configs += [ "../../../../services/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", + ] + + defines = [] + include_dirs = [] + if (device_usage_statistics_enabled) { + external_deps += [ "device_usage_statistics:usagestatsinner" ] + defines += [ "DEVICE_USAGE_STATISTICS_ENABLED" ] + } + 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 (current_cpu == "arm64") { + defines += [ "ON_64BIT_SYSTEM" ] + } + 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 (udmf_enabled) { + defines += [ "BUNDLE_FRAMEWORK_UDMF_ENABLED" ] + 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 + } + + sources += [ "bmsbundleinstalldhost_fuzzer.cpp" ] +} diff --git a/test/fuzztest/fuzztest_bundlemanager/bmsbundleinstalldhost_fuzzer/bmsbundleinstalldhost_fuzzer.cpp b/test/fuzztest/fuzztest_bundlemanager/bmsbundleinstalldhost_fuzzer/bmsbundleinstalldhost_fuzzer.cpp new file mode 100644 index 0000000000000000000000000000000000000000..0a21005e27e264837a16d0bf733e681a925b40ef --- /dev/null +++ b/test/fuzztest/fuzztest_bundlemanager/bmsbundleinstalldhost_fuzzer/bmsbundleinstalldhost_fuzzer.cpp @@ -0,0 +1,77 @@ +/* + * Copyright (c) 2023 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 "bundleinstalldhost_fuzzer.h" + +#include +#include +#include "ipc/installd_host.h" +#include "bundle_mgr_service.h" +#include "message_parcel.h" +#include "securec.h" + +using namespace OHOS::AppExecFwk; +namespace OHOS { +constexpr size_t U32_AT_SIZE = 4; +constexpr uint32_t CODE_MAX = 56; +static InstalldHost installdHost; + +bool DoSomethingInterestingWithMyAPI(const char* data, size_t size) +{ + for (uint32_t code = 0; code <= CODE_MAX; code++) { + MessageParcel datas; + std::u16string descriptor = InstalldHost::GetDescriptor(); + datas.WriteInterfaceToken(descriptor); + datas.WriteBuffer(data, size); + datas.RewindRead(0); + MessageParcel reply; + MessageOption option; + DelayedSingleton::GetInstance()->OnStop(); + installdHost.OnRemoteRequest(code, datas, reply, option); + } + return true; +} +} + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data */ + if (data == nullptr) { + return 0; + } + + if (size < OHOS::U32_AT_SIZE) { + return 0; + } + + char* ch = static_cast(malloc(size + 1)); + if (ch == nullptr) { + return 0; + } + + (void)memset_s(ch, size + 1, 0x00, size + 1); + if (memcpy_s(ch, size, data, size) != EOK) { + free(ch); + ch = nullptr; + return 0; + } + + OHOS::DoSomethingInterestingWithMyAPI(ch, size); + free(ch); + ch = nullptr; + return 0; +} \ No newline at end of file diff --git a/test/fuzztest/fuzztest_bundlemanager/bmsbundleinstalldhost_fuzzer/bmsbundleinstalldhost_fuzzer.h b/test/fuzztest/fuzztest_bundlemanager/bmsbundleinstalldhost_fuzzer/bmsbundleinstalldhost_fuzzer.h new file mode 100644 index 0000000000000000000000000000000000000000..ea6dcc62bd22940d55242f78a09ea34d3a5483a4 --- /dev/null +++ b/test/fuzztest/fuzztest_bundlemanager/bmsbundleinstalldhost_fuzzer/bmsbundleinstalldhost_fuzzer.h @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2023 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_BUNDLEINSTALLDHOST_FUZZER_H +#define TEST_FUZZTEST_BUNDLEINSTALLDHOST_FUZZER_H + +#define FUZZ_PROJECT_NAME "bmsbundleinstalldhost_fuzzer" + +#endif \ No newline at end of file diff --git a/test/fuzztest/fuzztest_bundlemanager/bmsbundleinstalldhost_fuzzer/corpus/init b/test/fuzztest/fuzztest_bundlemanager/bmsbundleinstalldhost_fuzzer/corpus/init new file mode 100644 index 0000000000000000000000000000000000000000..e4ceac1bcd4e3b3427eb63cea0c28304064333cc --- /dev/null +++ b/test/fuzztest/fuzztest_bundlemanager/bmsbundleinstalldhost_fuzzer/corpus/init @@ -0,0 +1,14 @@ +# Copyright (c) 2023 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +FUZZ \ No newline at end of file diff --git a/test/fuzztest/fuzztest_bundlemanager/bmsbundleinstalldhost_fuzzer/project.xml b/test/fuzztest/fuzztest_bundlemanager/bmsbundleinstalldhost_fuzzer/project.xml new file mode 100644 index 0000000000000000000000000000000000000000..4fdbc407f205680885fa42663163b5c987f123a6 --- /dev/null +++ b/test/fuzztest/fuzztest_bundlemanager/bmsbundleinstalldhost_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/test/fuzztest/fuzztest_bundlemanager/bmsbundleinstallerhost_fuzzer/BUILD.gn b/test/fuzztest/fuzztest_bundlemanager/bmsbundleinstallerhost_fuzzer/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..de99d4cbcd798de1ff70b002b51e7a3441921266 --- /dev/null +++ b/test/fuzztest/fuzztest_bundlemanager/bmsbundleinstallerhost_fuzzer/BUILD.gn @@ -0,0 +1,155 @@ +# Copyright (c) 2023 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("BMSBundleInstallerHostFuzzTest") { + module_out_path = module_output_path + fuzz_config_file = + "../../../fuzztest/fuzztest_bundlemanager/bmsbundleinstallerhost_fuzzer" + + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + + use_exceptions = true + + sources = bundle_mgr_source + sources -= [ "${services_path}/bundlemgr/src/system_ability_helper.cpp" ] + 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/test/mock/src/installd_service.cpp", + ] + + sources += [ + "${services_path}/bundlemgr/test/mock/src/installd_permission_mgr.cpp", + "${services_path}/bundlemgr/test/mock/src/mock_bundle_status.cpp", + "${services_path}/bundlemgr/test/mock/src/system_ability_helper.cpp", + ] + + sources += bundle_install_sources + + configs = [ "${services_path}/bundlemgr/test:bundlemgr_test_config" ] + + deps = bundle_install_deps + deps += [ + "${base_path}:appexecfwk_base", + "${core_path}:appexecfwk_core", + ] + + external_deps = [ + "ability_runtime:ability_manager", + "access_token:el5_filekey_manager_sdk", + "access_token:libprivacy_sdk", + "access_token:libtokenid_sdk", + "appspawn:hnpapi", + "appverify:libhapverify", + "bounds_checking_function:libsec_shared", + "c_utils:utils", + "common_event_service:cesfwk_innerkits", + "eventhandler:libeventhandler", + "hilog:libhilog", + "hitrace:hitrace_meter", + "init:libbegetutil", + "ipc:ipc_core", + "safwk:system_ability_fwk", + "samgr:samgr_proxy", + "selinux_adapter:librestorecon", + ] + + external_deps += [ + "ability_runtime:ability_manager", + "ability_runtime:app_manager", + "battery_manager:batterysrv_client", + "display_manager:displaymgr", + "ffrt:libffrt", + "power_manager:powermgr_client", + "syscap_codec:syscap_interface_shared", + ] + + external_deps += bundle_install_external_deps + + if (bundle_framework_power_mgr_enable) { + external_deps += aot_external_deps + } + + configs += [ "../../../../services/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", + ] + + defines = [] + include_dirs = [] + + if (device_usage_statistics_enabled) { + external_deps += [ "device_usage_statistics:usagestatsinner" ] + defines += [ "DEVICE_USAGE_STATISTICS_ENABLED" ] + } + 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 (current_cpu == "arm64") { + defines += [ "ON_64BIT_SYSTEM" ] + } + 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 (udmf_enabled) { + defines += [ "BUNDLE_FRAMEWORK_UDMF_ENABLED" ] + 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 + } + + sources += [ "bmsbundleinstallerhost_fuzzer.cpp" ] +} diff --git a/test/fuzztest/fuzztest_bundlemanager/bmsbundleinstallerhost_fuzzer/bmsbundleinstallerhost_fuzzer.cpp b/test/fuzztest/fuzztest_bundlemanager/bmsbundleinstallerhost_fuzzer/bmsbundleinstallerhost_fuzzer.cpp new file mode 100644 index 0000000000000000000000000000000000000000..0253069ed0cd85c2d579e39d897bbc022a31240f --- /dev/null +++ b/test/fuzztest/fuzztest_bundlemanager/bmsbundleinstallerhost_fuzzer/bmsbundleinstallerhost_fuzzer.cpp @@ -0,0 +1,101 @@ +/* + * 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 "bmsbundleinstallerhost_fuzzer.h" + +#define private public + +#include +#include +#include + +#include "bundle_installer_host.h" +#include "bundle_mgr_service.h" +#include "message_parcel.h" +#include "securec.h" +#include "../../bms_fuzztest_util.h" + +using namespace OHOS::AppExecFwk; +using namespace OHOS::AppExecFwk::BMSFuzzTestUtil; +namespace OHOS { +constexpr size_t U32_AT_SIZE = 4; +constexpr size_t MESSAGE_SIZE = 10; +constexpr size_t CODE_MAX = 13; + +bool DoSomethingInterestingWithMyAPI(const uint8_t* data, size_t size) +{ + auto bundleInstallerHost = std::make_unique(); + FuzzedDataProvider fdp(data, size); +#ifdef ON_64BIT_SYSTEM + for (uint32_t code = 0; code <= CODE_MAX; code++) { + MessageParcel datas; + std::u16string descriptor = BundleInstallerHost::GetDescriptor(); + datas.WriteInterfaceToken(descriptor); + datas.WriteBuffer(data, size); + datas.RewindRead(0); + MessageParcel reply; + MessageOption option; + DelayedSingleton::GetInstance()->OnStop(); + bundleInstallerHost->OnRemoteRequest(code, datas, reply, option); + } +#endif + int32_t userId = fdp.ConsumeIntegral(); + int32_t appIndex = fdp.ConsumeIntegral(); + int32_t dplType = fdp.ConsumeIntegral(); + int32_t streamInstallerId = fdp.ConsumeIntegral(); + std::string bundleFilePath = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH); + std::string bundleName = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH); + std::string modulePackage = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH); + std::vector bundleFilePaths = GenerateStringArray(fdp); + InstallParam installParam; + GenerateInstallParam(fdp, installParam); + + UninstallParam uninstallParam; + sptr statusReceiver; + std::vector originHapPaths = GenerateStringArray(fdp); + bundleInstallerHost->Init(); + bundleInstallerHost->Install(bundleFilePath, installParam, statusReceiver); + bundleInstallerHost->Recover(bundleName, installParam, statusReceiver); + bundleInstallerHost->Install(bundleFilePaths, installParam, statusReceiver); + bundleInstallerHost->Uninstall(bundleName, installParam, statusReceiver); + bundleInstallerHost->Uninstall(bundleName, modulePackage, installParam, statusReceiver); + bundleInstallerHost->Uninstall(uninstallParam, statusReceiver); + bundleInstallerHost->InstallByBundleName(bundleName, installParam, statusReceiver); + bundleInstallerHost->InstallSandboxApp(bundleName, dplType, userId, appIndex); + bundleInstallerHost->UninstallSandboxApp(bundleName, appIndex, userId); + bundleInstallerHost->CreateStreamInstaller(installParam, statusReceiver, originHapPaths); + bundleInstallerHost->DestoryBundleStreamInstaller(streamInstallerId); + bundleInstallerHost->StreamInstall(bundleFilePaths, installParam, statusReceiver); + bundleInstallerHost->UpdateBundleForSelf(bundleFilePaths, installParam, statusReceiver); + bundleInstallerHost->UninstallAndRecover(bundleName, installParam, statusReceiver); + bundleInstallerHost->GetCurTaskNum(); + bundleInstallerHost->GetThreadsNum(); + bundleInstallerHost->InstallCloneApp(bundleName, userId, appIndex); + bundleInstallerHost->UninstallCloneApp(bundleName, userId, appIndex, DestroyAppCloneParam()); + bundleInstallerHost->InstallExisted(bundleName, userId); + bundleInstallerHost->CheckInstallParam(installParam); + InstallParam installParam2; + GenerateInstallParam(fdp, installParam2); + bundleInstallerHost->IsPermissionVaild(installParam, installParam2); + return true; +} +} + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + OHOS::DoSomethingInterestingWithMyAPI(data, size); + return 0; +} \ No newline at end of file diff --git a/test/fuzztest/fuzztest_bundlemanager/bmsbundleinstallerhost_fuzzer/bmsbundleinstallerhost_fuzzer.h b/test/fuzztest/fuzztest_bundlemanager/bmsbundleinstallerhost_fuzzer/bmsbundleinstallerhost_fuzzer.h new file mode 100644 index 0000000000000000000000000000000000000000..740fa6ccbb12f24fc8965262d3c335798af2b9fb --- /dev/null +++ b/test/fuzztest/fuzztest_bundlemanager/bmsbundleinstallerhost_fuzzer/bmsbundleinstallerhost_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_BMSBUNDLEINSTALLERHOST_FUZZER_H +#define TEST_FUZZTEST_BMSBUNDLEINSTALLERHOST_FUZZER_H + +#define FUZZ_PROJECT_NAME "bmsbundleinstallerhost_fuzzer" + +#endif \ No newline at end of file diff --git a/test/fuzztest/fuzztest_bundlemanager/bmsbundleinstallerhost_fuzzer/corpus/init b/test/fuzztest/fuzztest_bundlemanager/bmsbundleinstallerhost_fuzzer/corpus/init new file mode 100644 index 0000000000000000000000000000000000000000..e4ceac1bcd4e3b3427eb63cea0c28304064333cc --- /dev/null +++ b/test/fuzztest/fuzztest_bundlemanager/bmsbundleinstallerhost_fuzzer/corpus/init @@ -0,0 +1,14 @@ +# Copyright (c) 2023 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +FUZZ \ No newline at end of file diff --git a/test/fuzztest/fuzztest_bundlemanager/bmsbundleinstallerhost_fuzzer/project.xml b/test/fuzztest/fuzztest_bundlemanager/bmsbundleinstallerhost_fuzzer/project.xml new file mode 100644 index 0000000000000000000000000000000000000000..dca0b2a0aec9fea8bdf0151dad6ec8b1acc1fc50 --- /dev/null +++ b/test/fuzztest/fuzztest_bundlemanager/bmsbundleinstallerhost_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 10000 + + 300 + + 4096 + + diff --git a/test/fuzztest/fuzztest_bundlemanager/bmsbundleinstallerproxy_fuzzer/BUILD.gn b/test/fuzztest/fuzztest_bundlemanager/bmsbundleinstallerproxy_fuzzer/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..250f6be1a71d77f524ed63a2c368b76e182a8bdd --- /dev/null +++ b/test/fuzztest/fuzztest_bundlemanager/bmsbundleinstallerproxy_fuzzer/BUILD.gn @@ -0,0 +1,44 @@ +# Copyright (c) 2022-2023 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") +module_output_path = fuzz_test_path + +##############################fuzztest########################################## +ohos_fuzztest("BMSBundleInstallerProxyFuzzTest") { + module_out_path = module_output_path + fuzz_config_file = + "../../../fuzztest/fuzztest_bundlemanager/bmsbundleinstallerproxy_fuzzer" + + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + sources = [ "bmsbundleinstallerproxy_fuzzer.cpp" ] + + deps = [ + "${base_path}:appexecfwk_base", + "${common_path}:libappexecfwk_common", + "${core_path}:appexecfwk_core", + ] + external_deps = [ + "c_utils:utils", + "ipc:ipc_core", + ] +} diff --git a/test/fuzztest/fuzztest_bundlemanager/bmsbundleinstallerproxy_fuzzer/bmsbundleinstallerproxy_fuzzer.cpp b/test/fuzztest/fuzztest_bundlemanager/bmsbundleinstallerproxy_fuzzer/bmsbundleinstallerproxy_fuzzer.cpp new file mode 100644 index 0000000000000000000000000000000000000000..25902202adda7d95c6915680397b2eb8714ed123 --- /dev/null +++ b/test/fuzztest/fuzztest_bundlemanager/bmsbundleinstallerproxy_fuzzer/bmsbundleinstallerproxy_fuzzer.cpp @@ -0,0 +1,69 @@ +/* + * Copyright (c) 2022 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 "bundle_installer_proxy.h" + +#include "bmsbundleinstallerproxy_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) + { + sptr object; + BundleInstallerProxy bundleinstallerProxy(object); + + FuzzedDataProvider fdp(data, size); + std::string bundleFilePath = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH); + InstallParam installParam; + GenerateInstallParam(fdp, installParam); + sptr statusReceiver; + bundleinstallerProxy.Install(bundleFilePath, installParam, statusReceiver); + + std::string bundleName = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH); + bundleinstallerProxy.Recover(bundleName, installParam, statusReceiver); + + std::vector bundleFilePaths = GenerateStringArray(fdp); + bundleinstallerProxy.Install(bundleFilePaths, installParam, statusReceiver); + + bundleinstallerProxy.Uninstall(bundleName, installParam, statusReceiver); + std::string modulePackage = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH); + bundleinstallerProxy.Uninstall(bundleFilePath, modulePackage, installParam, statusReceiver); + int32_t dlpType = fdp.ConsumeIntegral(); + int32_t userId = fdp.ConsumeIntegral(); + int32_t appIndex = fdp.ConsumeIntegral(); + bundleinstallerProxy.InstallSandboxApp(bundleName, dlpType, userId, appIndex); + bundleinstallerProxy.UninstallSandboxApp(bundleName, appIndex, userId); + std::vector originHapPaths = GenerateStringArray(fdp); + bundleinstallerProxy.CreateStreamInstaller(installParam, statusReceiver, originHapPaths); + uint32_t streamInstallerId = fdp.ConsumeIntegral(); + bundleinstallerProxy.DestoryBundleStreamInstaller(streamInstallerId); + bundleinstallerProxy.StreamInstall(bundleFilePaths, installParam, statusReceiver); + 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/bmsbundleinstallerproxy_fuzzer/bmsbundleinstallerproxy_fuzzer.h b/test/fuzztest/fuzztest_bundlemanager/bmsbundleinstallerproxy_fuzzer/bmsbundleinstallerproxy_fuzzer.h new file mode 100644 index 0000000000000000000000000000000000000000..c89ac4b476b6d649a13a57f246574bef9f8a77ba --- /dev/null +++ b/test/fuzztest/fuzztest_bundlemanager/bmsbundleinstallerproxy_fuzzer/bmsbundleinstallerproxy_fuzzer.h @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2022 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_BMSBUNDLEINSTALLERPROXY_FUZZER_H +#define TEST_FUZZTEST_BMSBUNDLEINSTALLERPROXY_FUZZER_H + +#define FUZZ_PROJECT_NAME "bmsbundleinstallerproxy_fuzzer" + +#endif \ No newline at end of file diff --git a/test/fuzztest/fuzztest_bundlemanager/bmsbundleinstallerproxy_fuzzer/corpus/init b/test/fuzztest/fuzztest_bundlemanager/bmsbundleinstallerproxy_fuzzer/corpus/init new file mode 100644 index 0000000000000000000000000000000000000000..bc977bd9738ee9a70b362067f57a9c63d3adb801 --- /dev/null +++ b/test/fuzztest/fuzztest_bundlemanager/bmsbundleinstallerproxy_fuzzer/corpus/init @@ -0,0 +1,14 @@ +# Copyright (c) 2022 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +FUZZ \ No newline at end of file diff --git a/test/fuzztest/fuzztest_bundlemanager/bmsbundleinstallerproxy_fuzzer/project.xml b/test/fuzztest/fuzztest_bundlemanager/bmsbundleinstallerproxy_fuzzer/project.xml new file mode 100644 index 0000000000000000000000000000000000000000..6e8ad2cfde8f8bda4beb6cabbe7efd8bc3c54eec --- /dev/null +++ b/test/fuzztest/fuzztest_bundlemanager/bmsbundleinstallerproxy_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/test/fuzztest/fuzztest_bundlemanager/bmsbundlemgrhost_fuzzer/BUILD.gn b/test/fuzztest/fuzztest_bundlemanager/bmsbundlemgrhost_fuzzer/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..ec96c157afceb8ca5295617b0ff314018a38d94e --- /dev/null +++ b/test/fuzztest/fuzztest_bundlemanager/bmsbundlemgrhost_fuzzer/BUILD.gn @@ -0,0 +1,45 @@ +# Copyright (c) 2023 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") +module_output_path = fuzz_test_path + +##############################fuzztest########################################## +ohos_fuzztest("BMSBundleMgrHostFuzzTest") { + module_out_path = module_output_path + fuzz_config_file = + "../../../fuzztest/fuzztest_bundlemanager/bmsbundlemgrhost_fuzzer" + + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + sources = [ "bmsbundlemgrhost_fuzzer.cpp" ] + + deps = [ + "${base_path}:appexecfwk_base", + "${common_path}:libappexecfwk_common", + "${core_path}:appexecfwk_core", + ] + external_deps = [ + "ability_base:want", + "c_utils:utils", + "ipc:ipc_core", + ] +} diff --git a/test/fuzztest/fuzztest_bundlemanager/bmsbundlemgrhost_fuzzer/bmsbundlemgrhost_fuzzer.cpp b/test/fuzztest/fuzztest_bundlemanager/bmsbundlemgrhost_fuzzer/bmsbundlemgrhost_fuzzer.cpp new file mode 100644 index 0000000000000000000000000000000000000000..f11feba20583c478f1618bc4373ce28cbfde47ce --- /dev/null +++ b/test/fuzztest/fuzztest_bundlemanager/bmsbundlemgrhost_fuzzer/bmsbundlemgrhost_fuzzer.cpp @@ -0,0 +1,52 @@ +/* + * Copyright (c) 2023-2024 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 "bmsbundlemgrhost_fuzzer.h" + +#include +#include + +#include "bundle_mgr_host.h" +#include "securec.h" +#include "../../bms_fuzztest_util.h" + +using namespace OHOS::AppExecFwk; +namespace OHOS { +constexpr size_t CODE_MAX = 187; + +bool DoSomethingInterestingWithMyAPI(const uint8_t* data, size_t size) +{ + for (uint32_t code = 0; code <= CODE_MAX; code++) { + MessageParcel datas; + std::u16string descriptor = BundleMgrHost::GetDescriptor(); + datas.WriteInterfaceToken(descriptor); + datas.WriteBuffer(data, size); + datas.RewindRead(0); + MessageParcel reply; + MessageOption option; + BundleMgrHost bundleMgrHost; + bundleMgrHost.OnRemoteRequest(code, datas, reply, option); + } + 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/bmsbundlemgrhost_fuzzer/bmsbundlemgrhost_fuzzer.h b/test/fuzztest/fuzztest_bundlemanager/bmsbundlemgrhost_fuzzer/bmsbundlemgrhost_fuzzer.h new file mode 100644 index 0000000000000000000000000000000000000000..f9d1b9b424b4d8cd074fbb93e22da4ea173b8508 --- /dev/null +++ b/test/fuzztest/fuzztest_bundlemanager/bmsbundlemgrhost_fuzzer/bmsbundlemgrhost_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_BMSBUNDLEMGRHOST_FUZZER_H +#define TEST_FUZZTEST_BMSBUNDLEMGRHOST_FUZZER_H + +#define FUZZ_PROJECT_NAME "bmsbundlemgrhost_fuzzer" + +#endif \ No newline at end of file diff --git a/test/fuzztest/fuzztest_bundlemanager/bmsbundlemgrhost_fuzzer/corpus/init b/test/fuzztest/fuzztest_bundlemanager/bmsbundlemgrhost_fuzzer/corpus/init new file mode 100644 index 0000000000000000000000000000000000000000..e4ceac1bcd4e3b3427eb63cea0c28304064333cc --- /dev/null +++ b/test/fuzztest/fuzztest_bundlemanager/bmsbundlemgrhost_fuzzer/corpus/init @@ -0,0 +1,14 @@ +# Copyright (c) 2023 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +FUZZ \ No newline at end of file diff --git a/test/fuzztest/fuzztest_bundlemanager/bmsbundlemgrhost_fuzzer/project.xml b/test/fuzztest/fuzztest_bundlemanager/bmsbundlemgrhost_fuzzer/project.xml new file mode 100644 index 0000000000000000000000000000000000000000..4fdbc407f205680885fa42663163b5c987f123a6 --- /dev/null +++ b/test/fuzztest/fuzztest_bundlemanager/bmsbundlemgrhost_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/test/fuzztest/fuzztest_bundlemanager/bmsbundlemgrproxypartfour_fuzzer/BUILD.gn b/test/fuzztest/fuzztest_bundlemanager/bmsbundlemgrproxypartfour_fuzzer/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..37b64090aebaf41512166ed22189e74be7948053 --- /dev/null +++ b/test/fuzztest/fuzztest_bundlemanager/bmsbundlemgrproxypartfour_fuzzer/BUILD.gn @@ -0,0 +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. + +#####################hydra-fuzz################### +import("//build/config/features.gni") +import("//build/ohos.gni") +import("//build/test.gni") +import("../../../../appexecfwk.gni") +module_output_path = fuzz_test_path + +##############################fuzztest########################################## +ohos_fuzztest("BMSBundleMgrProxyFuzzPartFourTest") { + module_out_path = module_output_path + fuzz_config_file = + "../../../fuzztest/fuzztest_bundlemanager/bmsbundlemgrproxypartfour_fuzzer" + + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + sources = [ "bmsbundlemgrproxypartfour_fuzzer.cpp" ] + + deps = [ + "${base_path}:appexecfwk_base", + "${common_path}:libappexecfwk_common", + "${core_path}:appexecfwk_core", + ] + external_deps = [ + "ability_base:want", + "c_utils:utils", + "ipc:ipc_core", + ] +} diff --git a/test/fuzztest/fuzztest_bundlemanager/bmsbundlemgrproxypartfour_fuzzer/bmsbundlemgrproxypartfour_fuzzer.cpp b/test/fuzztest/fuzztest_bundlemanager/bmsbundlemgrproxypartfour_fuzzer/bmsbundlemgrproxypartfour_fuzzer.cpp new file mode 100644 index 0000000000000000000000000000000000000000..7514e091e7ec639247d915fd029bf22b4cd12566 --- /dev/null +++ b/test/fuzztest/fuzztest_bundlemanager/bmsbundlemgrproxypartfour_fuzzer/bmsbundlemgrproxypartfour_fuzzer.cpp @@ -0,0 +1,118 @@ +/* + * 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 + +#include "bundle_mgr_proxy.h" + +#include "bmsbundlemgrproxypartfour_fuzzer.h" +#include "../../bms_fuzztest_util.h" + +using Want = OHOS::AAFwk::Want; + +using namespace OHOS::AppExecFwk; +using namespace OHOS::AppExecFwk::BMSFuzzTestUtil; +namespace OHOS { + bool DoSomethingInterestingWithMyAPI(const uint8_t* data, size_t size) + { + sptr object; + BundleMgrProxy bundleMgrProxy(object); + FuzzedDataProvider fdp(data, size); + std::string bundleName = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH); + std::string moduleName = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH); + std::string abilityName = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH); + int32_t userId = fdp.ConsumeIntegral(); + int32_t appIndex = fdp.ConsumeIntegral(); + int32_t flags = fdp.ConsumeIntegral(); + int32_t triggerMode = fdp.ConsumeIntegral(); + + bundleMgrProxy.ResetAOTCompileStatus(bundleName, moduleName, triggerMode); + std::string profile; + ProfileType profileType = static_cast(fdp.ConsumeIntegralInRange(1, 7)); + bundleMgrProxy.GetJsonProfile(profileType, bundleName, moduleName, profile); + bundleMgrProxy.GetBundleResourceProxy(); + std::vector recoverableApplications; + bundleMgrProxy.GetRecoverableApplicationInfo(recoverableApplications); + BundleInfo bundleInfo; + bundleMgrProxy.GetUninstalledBundleInfo(bundleName, bundleInfo); + std::string additionalInfo = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH); + bundleMgrProxy.SetAdditionalInfo(bundleName, additionalInfo); + bundleMgrProxy.CreateBundleDataDir(userId); + std::string odid; + bundleMgrProxy.GetOdid(odid); + std::string developerId = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH); + std::vector bundleInfos; + bundleMgrProxy.GetAllBundleInfoByDeveloperId(developerId, bundleInfos, userId); + std::string appDistributionType = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH); + std::vector developerIdList; + bundleMgrProxy.GetDeveloperIds(appDistributionType, developerIdList); + std::vector results; + std::string compileMode = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH); + bool isAllBundle = fdp.ConsumeBool(); + bundleMgrProxy.CompileProcessAOT(bundleName, compileMode, isAllBundle, results); + bundleMgrProxy.ResetAOTCompileStatus(bundleName, moduleName, triggerMode); + bundleMgrProxy.CopyAp(bundleName, isAllBundle, results); + std::string link = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH); + bool canOpen = fdp.ConsumeBool(); + bundleMgrProxy.CanOpenLink(link, canOpen); + std::vector preinstalledApplicationInfos; + bundleMgrProxy.GetAllPreinstalledApplicationInfos(preinstalledApplicationInfos); + bool state = fdp.ConsumeBool(); + bool isNeedSendNotify = fdp.ConsumeBool(); + bundleMgrProxy.SwitchUninstallState(bundleName, state, isNeedSendNotify); + + std::string continueType = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH); + AbilityInfo abilityInfo; + bundleMgrProxy.QueryAbilityInfoByContinueType(bundleName, continueType, abilityInfo); + ElementName element; + bundleMgrProxy.QueryCloneAbilityInfo(element, flags, appIndex, abilityInfo, reinterpret_cast(data)); + bundleMgrProxy.GetCloneBundleInfo(bundleName, flags, appIndex, bundleInfo); + element.SetAbilityName(abilityName); + element.SetBundleName(bundleName); + SignatureInfo sinfo; + bundleMgrProxy.GetSignatureInfoByBundleName(bundleName, sinfo); + ShortcutInfo shortcutInfo; + bundleMgrProxy.AddDesktopShortcutInfo(shortcutInfo, userId); + bundleMgrProxy.DeleteDesktopShortcutInfo(shortcutInfo, userId); + std::vector shortcutInfos; + bundleMgrProxy.GetAllDesktopShortcutInfo(userId, shortcutInfos); + bundleMgrProxy.GetOdidByBundleName(bundleName, odid); + bundleMgrProxy.GetBundleInfosForContinuation(flags, bundleInfos, userId); + std::string deviceType; + bundleMgrProxy.GetCompatibleDeviceType(bundleName, deviceType); + std::string queryBundleName; + std::string appId = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH); + bundleMgrProxy.GetBundleNameByAppId(appId, queryBundleName); + std::string dataDir; + bundleMgrProxy.GetDirByBundleNameAndAppIndex(bundleName, appIndex, dataDir); + std::vector bundleDirs; + bundleMgrProxy.GetAllBundleDirs(userId, bundleDirs); + std::set appDistributionTypeEnums{ + AppDistributionTypeEnum::APP_DISTRIBUTION_TYPE_APP_GALLERY}; + bundleMgrProxy.SetAppDistributionTypes(appDistributionTypeEnums); + 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/bmsbundlemgrproxypartfour_fuzzer/bmsbundlemgrproxypartfour_fuzzer.h b/test/fuzztest/fuzztest_bundlemanager/bmsbundlemgrproxypartfour_fuzzer/bmsbundlemgrproxypartfour_fuzzer.h new file mode 100644 index 0000000000000000000000000000000000000000..7e6921b06d572aa8a6e1b5ae45f1384e66ca0a0e --- /dev/null +++ b/test/fuzztest/fuzztest_bundlemanager/bmsbundlemgrproxypartfour_fuzzer/bmsbundlemgrproxypartfour_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_BMSBUNDLEMGRPROXTPARTFOUR_FUZZER_H +#define TEST_FUZZTEST_BMSBUNDLEMGRPROXTPARTFOUR_FUZZER_H + +#define FUZZ_PROJECT_NAME "bmsbundlemgrproxypartfour_fuzzer" + +#endif \ No newline at end of file diff --git a/test/fuzztest/fuzztest_bundlemanager/bmsbundlemgrproxypartfour_fuzzer/corpus/init b/test/fuzztest/fuzztest_bundlemanager/bmsbundlemgrproxypartfour_fuzzer/corpus/init new file mode 100644 index 0000000000000000000000000000000000000000..bc977bd9738ee9a70b362067f57a9c63d3adb801 --- /dev/null +++ b/test/fuzztest/fuzztest_bundlemanager/bmsbundlemgrproxypartfour_fuzzer/corpus/init @@ -0,0 +1,14 @@ +# Copyright (c) 2022 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +FUZZ \ No newline at end of file diff --git a/test/fuzztest/fuzztest_bundlemanager/bmsbundlemgrproxypartfour_fuzzer/project.xml b/test/fuzztest/fuzztest_bundlemanager/bmsbundlemgrproxypartfour_fuzzer/project.xml new file mode 100644 index 0000000000000000000000000000000000000000..c7a73115e50e3bf14e38a1c71c37336f85045334 --- /dev/null +++ b/test/fuzztest/fuzztest_bundlemanager/bmsbundlemgrproxypartfour_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 10000 + + 300 + + 4096 + + diff --git a/test/fuzztest/fuzztest_bundlemanager/bmsbundlemgrproxypartone_fuzzer/BUILD.gn b/test/fuzztest/fuzztest_bundlemanager/bmsbundlemgrproxypartone_fuzzer/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..04564382d83912e15c227901dbc829accea245df --- /dev/null +++ b/test/fuzztest/fuzztest_bundlemanager/bmsbundlemgrproxypartone_fuzzer/BUILD.gn @@ -0,0 +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. + +#####################hydra-fuzz################### +import("//build/config/features.gni") +import("//build/ohos.gni") +import("//build/test.gni") +import("../../../../appexecfwk.gni") +module_output_path = fuzz_test_path + +##############################fuzztest########################################## +ohos_fuzztest("BMSBundleMgrProxyFuzzPartOneTest") { + module_out_path = module_output_path + fuzz_config_file = + "../../../fuzztest/fuzztest_bundlemanager/bmsbundlemgrproxypartone_fuzzer" + + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + sources = [ "bmsbundlemgrproxypartone_fuzzer.cpp" ] + + deps = [ + "${base_path}:appexecfwk_base", + "${common_path}:libappexecfwk_common", + "${core_path}:appexecfwk_core", + ] + external_deps = [ + "ability_base:want", + "c_utils:utils", + "ipc:ipc_core", + ] +} diff --git a/test/fuzztest/fuzztest_bundlemanager/bmsbundlemgrproxypartone_fuzzer/bmsbundlemgrproxypartone_fuzzer.cpp b/test/fuzztest/fuzztest_bundlemanager/bmsbundlemgrproxypartone_fuzzer/bmsbundlemgrproxypartone_fuzzer.cpp new file mode 100644 index 0000000000000000000000000000000000000000..b168eca205ae2e520ed1e06dbde1210dacc40d83 --- /dev/null +++ b/test/fuzztest/fuzztest_bundlemanager/bmsbundlemgrproxypartone_fuzzer/bmsbundlemgrproxypartone_fuzzer.cpp @@ -0,0 +1,165 @@ +/* + * 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 + +#include "bundle_mgr_proxy.h" + +#include "bmsbundlemgrproxypartone_fuzzer.h" +#include "../../bms_fuzztest_util.h" + +using Want = OHOS::AAFwk::Want; + +using namespace OHOS::AppExecFwk; +using namespace OHOS::AppExecFwk::BMSFuzzTestUtil; +namespace OHOS { + bool DoSomethingInterestingWithMyAPI(const uint8_t* data, size_t size) + { + sptr object; + BundleMgrProxy bundleMgrProxy(object); + FuzzedDataProvider fdp(data, size); + std::string bundleName = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH); + BundleInfo bundleInfo; + GenerateBundleInfo(fdp, bundleInfo); + std::vector bundleInfos; + bundleMgrProxy.QueryKeepAliveBundleInfos(bundleInfos); + + sptr bundleStatusCallback; + bundleMgrProxy.RegisterBundleStatusCallback(bundleStatusCallback); + bundleMgrProxy.ClearBundleStatusCallback(bundleStatusCallback); + + DumpFlag dumpFlag = static_cast(fdp.ConsumeIntegralInRange(1, 4)); + int32_t userId = fdp.ConsumeIntegral(); + std::string result = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH); + bundleMgrProxy.DumpInfos(dumpFlag, bundleName, userId, result); + + bool isEnable = fdp.ConsumeBool(); + bundleMgrProxy.IsApplicationEnabled(bundleName, isEnable); + bundleMgrProxy.SetApplicationEnabled(bundleName, isEnable, userId); + + AbilityInfo abilityInfo; + GenerateAbilityInfo(fdp, abilityInfo); + bundleMgrProxy.IsAbilityEnabled(abilityInfo, isEnable); + bundleMgrProxy.SetAbilityEnabled(abilityInfo, isEnable, reinterpret_cast(data)); + + FormInfo formInfo; + formInfo.bundleName = bundleName; + std::vector formInfos; + formInfos.push_back(formInfo); + bundleMgrProxy.GetAllFormsInfo(formInfos); + bundleMgrProxy.GetFormsInfoByApp(bundleName, formInfos); + std::string moduleName = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH); + bundleMgrProxy.GetFormsInfoByModule(bundleName, moduleName, formInfos); + + std::vector shortcutInfos; + bundleMgrProxy.GetShortcutInfos(bundleName, shortcutInfos); + bundleMgrProxy.GetShortcutInfoV9(bundleName, shortcutInfos); + + std::string eventKey = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH); + std::vector commonEventInfos; + bundleMgrProxy.GetAllCommonEventInfo(eventKey, commonEventInfos); + + std::string networkId = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH); + DistributedBundleInfo distributedBundleInfo; + bundleMgrProxy.GetDistributedBundleInfo(networkId, bundleName, distributedBundleInfo); + bundleMgrProxy.GetAppPrivilegeLevel(bundleName, reinterpret_cast(data)); + + Want want; + want.SetAction(bundleName); + ExtensionAbilityInfo extensionInfo; + std::vector extensionInfos; + int32_t flag = fdp.ConsumeIntegral(); + bundleMgrProxy.QueryExtensionAbilityInfos(want, userId, flag, extensionInfos); + bundleMgrProxy.QueryExtensionAbilityInfosV9(want, userId, flag, extensionInfos); + ExtensionAbilityType extensionType = + static_cast(fdp.ConsumeIntegralInRange(0, 24)); + bundleMgrProxy.QueryExtensionAbilityInfos(want, extensionType, userId, flag, extensionInfos); + bundleMgrProxy.QueryExtensionAbilityInfosV9(want, extensionType, userId, flag, extensionInfos); + bundleMgrProxy.QueryExtensionAbilityInfos(extensionType, flag, extensionInfos); + std::string permission = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH); + bundleMgrProxy.VerifyCallingPermission(permission); + std::string uri = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH); + bundleMgrProxy.QueryExtensionAbilityInfoByUri(uri, userId, extensionInfo); + bundleMgrProxy.ImplicitQueryInfoByPriority(want, userId, flag, abilityInfo, extensionInfo); + + abilityInfo.name = bundleName; + std::vector abilityInfos; + abilityInfos.push_back(abilityInfo); + bool findDafaultApp = fdp.ConsumeBool(); + bool withDefault = fdp.ConsumeBool(); + bundleMgrProxy.ImplicitQueryInfos( + want, flag, userId, withDefault, abilityInfos, extensionInfos, findDafaultApp); + + std::string abilityName = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH); + bundleMgrProxy.GetAbilityInfo(bundleName, abilityName, abilityInfo); + bundleMgrProxy.GetAbilityInfo(bundleName, moduleName, abilityName, abilityInfo); + BundleInfo info; + int32_t appIndex = fdp.ConsumeIntegral(); + bundleMgrProxy.GetSandboxBundleInfo(bundleName, appIndex, userId, info); + bundleMgrProxy.IsModuleRemovable(bundleName, moduleName, isEnable); + bundleMgrProxy.SetModuleRemovable(bundleName, moduleName, isEnable); + std::vector dependentModuleNames; + bundleMgrProxy.GetAllDependentModuleNames(bundleName, moduleName, dependentModuleNames); + bundleMgrProxy.GetModuleUpgradeFlag(bundleName, moduleName); + int32_t upgradeFlag = fdp.ConsumeIntegral(); + bundleMgrProxy.SetModuleUpgradeFlag(bundleName, moduleName, upgradeFlag); + bundleMgrProxy.ObtainCallingBundleName(bundleName); + std::vector bundleStats; + bundleMgrProxy.GetBundleStats(bundleName, userId, bundleStats); + sptr callback; + int32_t missionId = fdp.ConsumeIntegral(); + bundleMgrProxy.CheckAbilityEnableInstall(want, missionId, userId, callback); + std::unique_ptr mediaDataPtr; + bundleMgrProxy.GetMediaData(bundleName, moduleName, abilityName, mediaDataPtr, size, userId); + uint32_t resId = fdp.ConsumeIntegral(); + std::string localeInfo = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH); + bundleMgrProxy.GetStringById(bundleName, moduleName, resId, userId, localeInfo); + uint32_t density = fdp.ConsumeIntegral(); + bundleMgrProxy.GetIconById(bundleName, moduleName, resId, density, userId); + bundleMgrProxy.GetSandboxAbilityInfo(want, appIndex, flag, userId, abilityInfo); + bundleMgrProxy.GetSandboxExtAbilityInfos(want, appIndex, flag, userId, extensionInfos); + HapModuleInfo hapModuleInfo; + bundleMgrProxy.GetSandboxHapModuleInfo(abilityInfo, appIndex, userId, hapModuleInfo); + bundleMgrProxy.UnregisterBundleStatusCallback(); + bundleMgrProxy.GetBundleInstaller(); + bundleMgrProxy.GetBundleUserMgr(); + bundleMgrProxy.GetQuickFixManagerProxy(); + bundleMgrProxy.GetAppControlProxy(); + + ApplicationInfo appInfo; + bundleMgrProxy.GetApplicationInfo(bundleName, flag, userId, appInfo); + bundleMgrProxy.GetApplicationInfo(bundleName, flag, userId, appInfo); + bundleMgrProxy.GetApplicationInfoV9(bundleName, flag, userId, appInfo); + std::vector appInfos; + bundleMgrProxy.GetApplicationInfos(flag, userId, appInfos); + bundleMgrProxy.GetApplicationInfos(flag, userId, appInfos); + bundleMgrProxy.GetApplicationInfosV9(flag, userId, appInfos); + bundleMgrProxy.GetBundleInfo(bundleName, flag, bundleInfo, userId); + bundleMgrProxy.GetBundleInfo(bundleName, flag, bundleInfo, userId); + bundleMgrProxy.GetBundleInfoV9(bundleName, flag, bundleInfo, userId); + 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/bmsbundlemgrproxypartone_fuzzer/bmsbundlemgrproxypartone_fuzzer.h b/test/fuzztest/fuzztest_bundlemanager/bmsbundlemgrproxypartone_fuzzer/bmsbundlemgrproxypartone_fuzzer.h new file mode 100644 index 0000000000000000000000000000000000000000..e12ba0f4a707853e0ed5f3c3ef449e0dd32d752e --- /dev/null +++ b/test/fuzztest/fuzztest_bundlemanager/bmsbundlemgrproxypartone_fuzzer/bmsbundlemgrproxypartone_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_BMSBUNDLEMGRPROXTPARTONE_FUZZER_H +#define TEST_FUZZTEST_BMSBUNDLEMGRPROXTPARTONE_FUZZER_H + +#define FUZZ_PROJECT_NAME "bmsbundlemgrproxypartone_fuzzer" + +#endif \ No newline at end of file diff --git a/test/fuzztest/fuzztest_bundlemanager/bmsbundlemgrproxypartone_fuzzer/corpus/init b/test/fuzztest/fuzztest_bundlemanager/bmsbundlemgrproxypartone_fuzzer/corpus/init new file mode 100644 index 0000000000000000000000000000000000000000..bc977bd9738ee9a70b362067f57a9c63d3adb801 --- /dev/null +++ b/test/fuzztest/fuzztest_bundlemanager/bmsbundlemgrproxypartone_fuzzer/corpus/init @@ -0,0 +1,14 @@ +# Copyright (c) 2022 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +FUZZ \ No newline at end of file diff --git a/test/fuzztest/fuzztest_bundlemanager/bmsbundlemgrproxypartone_fuzzer/project.xml b/test/fuzztest/fuzztest_bundlemanager/bmsbundlemgrproxypartone_fuzzer/project.xml new file mode 100644 index 0000000000000000000000000000000000000000..c7a73115e50e3bf14e38a1c71c37336f85045334 --- /dev/null +++ b/test/fuzztest/fuzztest_bundlemanager/bmsbundlemgrproxypartone_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 10000 + + 300 + + 4096 + + diff --git a/test/fuzztest/fuzztest_bundlemanager/bmsbundlemgrproxypartthree_fuzzer/BUILD.gn b/test/fuzztest/fuzztest_bundlemanager/bmsbundlemgrproxypartthree_fuzzer/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..7ad1502f8a8a594f4ae912c2fa9046a7508f59c3 --- /dev/null +++ b/test/fuzztest/fuzztest_bundlemanager/bmsbundlemgrproxypartthree_fuzzer/BUILD.gn @@ -0,0 +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. + +#####################hydra-fuzz################### +import("//build/config/features.gni") +import("//build/ohos.gni") +import("//build/test.gni") +import("../../../../appexecfwk.gni") +module_output_path = fuzz_test_path + +##############################fuzztest########################################## +ohos_fuzztest("BMSBundleMgrProxyFuzzPartThreeTest") { + module_out_path = module_output_path + fuzz_config_file = + "../../../fuzztest/fuzztest_bundlemanager/bmsbundlemgrproxypartthree_fuzzer" + + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + sources = [ "bmsbundlemgrproxypartthree_fuzzer.cpp" ] + + deps = [ + "${base_path}:appexecfwk_base", + "${common_path}:libappexecfwk_common", + "${core_path}:appexecfwk_core", + ] + external_deps = [ + "ability_base:want", + "c_utils:utils", + "ipc:ipc_core", + ] +} diff --git a/test/fuzztest/fuzztest_bundlemanager/bmsbundlemgrproxypartthree_fuzzer/bmsbundlemgrproxypartthree_fuzzer.cpp b/test/fuzztest/fuzztest_bundlemanager/bmsbundlemgrproxypartthree_fuzzer/bmsbundlemgrproxypartthree_fuzzer.cpp new file mode 100644 index 0000000000000000000000000000000000000000..d028d03727a17210ef0cf628e218075305993961 --- /dev/null +++ b/test/fuzztest/fuzztest_bundlemanager/bmsbundlemgrproxypartthree_fuzzer/bmsbundlemgrproxypartthree_fuzzer.cpp @@ -0,0 +1,129 @@ +/* +* Copyright (c) 2022 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 + +#include "bundle_mgr_proxy.h" + +#include "bmsbundlemgrproxypartthree_fuzzer.h" +#include "../../bms_fuzztest_util.h" + +using Want = OHOS::AAFwk::Want; + +using namespace OHOS::AppExecFwk; +using namespace OHOS::AppExecFwk::BMSFuzzTestUtil; +namespace OHOS { + bool DoSomethingInterestingWithMyAPI(const uint8_t* data, size_t size) + { + sptr object; + BundleMgrProxy bundleMgrProxy(object); + FuzzedDataProvider fdp(data, size); + std::string bundleName = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH); + int32_t userId = fdp.ConsumeIntegral(); + int32_t appIndex = fdp.ConsumeIntegral(); + int32_t flags = fdp.ConsumeIntegral(); + std::string hapFilePath = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH); + + BundleInfo bundleInfo; + AbilityInfo abilityInfo; + bundleMgrProxy.GetBundleArchiveInfo(hapFilePath, flags, bundleInfo); + BundleFlag bundleFlag = GET_BUNDLE_DEFAULT; + bundleMgrProxy.GetBundleArchiveInfo(hapFilePath, bundleFlag, bundleInfo); + bundleMgrProxy.GetBundleArchiveInfoV9(hapFilePath, flags, bundleInfo); + HapModuleInfo hapModuleInfo; + bundleMgrProxy.GetHapModuleInfo(abilityInfo, hapModuleInfo); + bundleMgrProxy.GetHapModuleInfo(abilityInfo, userId, hapModuleInfo); + Want want; + bundleMgrProxy.GetLaunchWantForBundle(bundleName, want, userId); + PermissionDef permissionDef; + std::string permissionName = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH); + bundleMgrProxy.GetPermissionDef(permissionName, permissionDef); + + uint64_t cacheSize = fdp.ConsumeIntegral(); + bundleMgrProxy.CleanBundleCacheFilesAutomatic(cacheSize); + sptr cleanCacheCallback; + bundleMgrProxy.CleanBundleCacheFiles(bundleName, cleanCacheCallback, userId, appIndex); + bundleMgrProxy.CleanBundleDataFiles(bundleName, userId, appIndex); + + bundleMgrProxy.GetDependentBundleInfo(bundleName, bundleInfo); + int uid = fdp.ConsumeIntegral(); + bundleMgrProxy.GetNameForUid(uid, bundleName); + std::vector abilityInfos; + std::vector wants; + bundleMgrProxy.BatchQueryAbilityInfos(wants, flags, userId, abilityInfos); + bool isEnable = fdp.ConsumeBool(); + bundleMgrProxy.IsCloneApplicationEnabled(bundleName, appIndex, isEnable); + bundleMgrProxy.SetCloneApplicationEnabled(bundleName, appIndex, isEnable); + bundleMgrProxy.IsCloneAbilityEnabled(abilityInfo, appIndex, isEnable); + bundleMgrProxy.SetCloneAbilityEnabled(abilityInfo, appIndex, isEnable); + bundleMgrProxy.GetVerifyManager(); + bundleMgrProxy.GetExtendResourceManager(); + std::vector bundleStats; + bundleMgrProxy.GetAllBundleStats(userId, bundleStats); + bundleMgrProxy.GetDefaultAppProxy(); + bundleMgrProxy.GetAppControlProxy(); + bundleMgrProxy.SetDebugMode(isEnable); + bundleMgrProxy.VerifySystemApi(); + bundleMgrProxy.ProcessPreload(want); + bundleMgrProxy.GetOverlayManagerProxy(); + AppProvisionInfo appProvisionInfo; + bundleMgrProxy.GetAppProvisionInfo(bundleName, userId, appProvisionInfo); + std::vector baseSharedBundleInfos; + bundleMgrProxy.GetBaseSharedBundleInfos(bundleName, baseSharedBundleInfos); + std::vector sharedBundles; + bundleMgrProxy.GetAllSharedBundleInfo(sharedBundles); + std::string moduleName = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH); + bundleMgrProxy.GetSharedBundleInfo(bundleName, moduleName, sharedBundles); + SharedBundleInfo sharedBundleInfo; + bundleMgrProxy.GetSharedBundleInfoBySelf(bundleName, sharedBundleInfo); + std::vector dependencies; + bundleMgrProxy.GetSharedDependencies(bundleName, moduleName, dependencies); + std::vector proxyDatas; + bundleMgrProxy.GetProxyDataInfos(bundleName, moduleName, proxyDatas); + bundleMgrProxy.GetAllProxyDataInfos(proxyDatas); + std::string specifiedDistributionType; + bundleMgrProxy.GetSpecifiedDistributionType(bundleName, specifiedDistributionType); + std::string additionalInfo; + bundleMgrProxy.GetAdditionalInfo(bundleName, additionalInfo); + bundleMgrProxy.GetAdditionalInfoForAllUser(bundleName, additionalInfo); + std::string abilityName = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH); + std::string extName = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH); + std::string mimeType = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH); + bundleMgrProxy.SetExtNameOrMIMEToApp(bundleName, moduleName, abilityName, extName, mimeType); + bundleMgrProxy.DelExtNameOrMIMEToApp(bundleName, moduleName, abilityName, extName, mimeType); + std::vector infos; + bundleMgrProxy.QueryDataGroupInfos(bundleName, userId, infos); + std::string dir; + std::string dataGroupId = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH); + bundleMgrProxy.GetGroupDir(dataGroupId, dir); + bundleMgrProxy.QueryAppGalleryBundleName(bundleName); + std::string extensionTypeName = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH); + std::vector extensionInfos; + bundleMgrProxy.QueryExtensionAbilityInfosWithTypeName(want, extensionTypeName, flags, userId, extensionInfos); + bundleMgrProxy.QueryExtensionAbilityInfosOnlyWithTypeName(extensionTypeName, flags, userId, extensionInfos); + 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/bmsbundlemgrproxypartthree_fuzzer/bmsbundlemgrproxypartthree_fuzzer.h b/test/fuzztest/fuzztest_bundlemanager/bmsbundlemgrproxypartthree_fuzzer/bmsbundlemgrproxypartthree_fuzzer.h new file mode 100644 index 0000000000000000000000000000000000000000..1eb3bdcf2e2dde01d52c108f7e3e60a21761ef7a --- /dev/null +++ b/test/fuzztest/fuzztest_bundlemanager/bmsbundlemgrproxypartthree_fuzzer/bmsbundlemgrproxypartthree_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_BMSBUNDLEMGRPROXTPARTTHREE_FUZZER_H +#define TEST_FUZZTEST_BMSBUNDLEMGRPROXTPARTTHREE_FUZZER_H + +#define FUZZ_PROJECT_NAME "bmsbundlemgrproxypartthree_fuzzer" + +#endif \ No newline at end of file diff --git a/test/fuzztest/fuzztest_bundlemanager/bmsbundlemgrproxypartthree_fuzzer/corpus/init b/test/fuzztest/fuzztest_bundlemanager/bmsbundlemgrproxypartthree_fuzzer/corpus/init new file mode 100644 index 0000000000000000000000000000000000000000..bc977bd9738ee9a70b362067f57a9c63d3adb801 --- /dev/null +++ b/test/fuzztest/fuzztest_bundlemanager/bmsbundlemgrproxypartthree_fuzzer/corpus/init @@ -0,0 +1,14 @@ +# Copyright (c) 2022 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +FUZZ \ No newline at end of file diff --git a/test/fuzztest/fuzztest_bundlemanager/bmsbundlemgrproxypartthree_fuzzer/project.xml b/test/fuzztest/fuzztest_bundlemanager/bmsbundlemgrproxypartthree_fuzzer/project.xml new file mode 100644 index 0000000000000000000000000000000000000000..c7a73115e50e3bf14e38a1c71c37336f85045334 --- /dev/null +++ b/test/fuzztest/fuzztest_bundlemanager/bmsbundlemgrproxypartthree_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 10000 + + 300 + + 4096 + + diff --git a/test/fuzztest/fuzztest_bundlemanager/bmsbundlemgrproxyparttwo_fuzzer/BUILD.gn b/test/fuzztest/fuzztest_bundlemanager/bmsbundlemgrproxyparttwo_fuzzer/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..205fc40fe99777f0fe996ed2cff68655fd2b61af --- /dev/null +++ b/test/fuzztest/fuzztest_bundlemanager/bmsbundlemgrproxyparttwo_fuzzer/BUILD.gn @@ -0,0 +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. + +#####################hydra-fuzz################### +import("//build/config/features.gni") +import("//build/ohos.gni") +import("//build/test.gni") +import("../../../../appexecfwk.gni") +module_output_path = fuzz_test_path + +##############################fuzztest########################################## +ohos_fuzztest("BMSBundleMgrProxyFuzzPartTwoTest") { + module_out_path = module_output_path + fuzz_config_file = + "../../../fuzztest/fuzztest_bundlemanager/bmsbundlemgrproxyparttwo_fuzzer" + + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + sources = [ "bmsbundlemgrproxyparttwo_fuzzer.cpp" ] + + deps = [ + "${base_path}:appexecfwk_base", + "${common_path}:libappexecfwk_common", + "${core_path}:appexecfwk_core", + ] + external_deps = [ + "ability_base:want", + "c_utils:utils", + "ipc:ipc_core", + ] +} diff --git a/test/fuzztest/fuzztest_bundlemanager/bmsbundlemgrproxyparttwo_fuzzer/bmsbundlemgrproxyparttwo_fuzzer.cpp b/test/fuzztest/fuzztest_bundlemanager/bmsbundlemgrproxyparttwo_fuzzer/bmsbundlemgrproxyparttwo_fuzzer.cpp new file mode 100644 index 0000000000000000000000000000000000000000..8cacdcbf690e7e2495f3e75ea1bb65e897b45297 --- /dev/null +++ b/test/fuzztest/fuzztest_bundlemanager/bmsbundlemgrproxyparttwo_fuzzer/bmsbundlemgrproxyparttwo_fuzzer.cpp @@ -0,0 +1,105 @@ +/* + * 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 + +#include "bundle_mgr_proxy.h" + +#include "bmsbundlemgrproxyparttwo_fuzzer.h" +#include "../../bms_fuzztest_util.h" + +using Want = OHOS::AAFwk::Want; + +using namespace OHOS::AppExecFwk; +using namespace OHOS::AppExecFwk::BMSFuzzTestUtil; +namespace OHOS { + bool DoSomethingInterestingWithMyAPI(const uint8_t* data, size_t size) + { + sptr object; + BundleMgrProxy bundleMgrProxy(object); + FuzzedDataProvider fdp(data, size); + + ElementName name; + std::string bundleName = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH); + name.SetBundleName(bundleName); + Want want; + want.SetElement(name); + std::vector wants; + wants.push_back(want); + int32_t flags = fdp.ConsumeIntegral(); + int32_t userId = fdp.ConsumeIntegral(); + std::vector bundleInfos; + bundleMgrProxy.BatchGetBundleInfo(wants, flags, bundleInfos, userId); + std::vector bundleNames = GenerateStringArray(fdp); + bundleMgrProxy.BatchGetBundleInfo(bundleNames, flags, bundleInfos, userId); + BundleInfo bundleInfo; + bundleMgrProxy.GetBundleInfoForSelf(flags, bundleInfo); + BundlePackInfo bundlePackInfo; + bundleMgrProxy.GetBundlePackInfo(bundleName, flags, bundlePackInfo, userId); + bundleMgrProxy.GetBundlePackInfo(bundleName, BundleFlag::GET_BUNDLE_DEFAULT, bundlePackInfo, userId); + bundleMgrProxy.GetBundleInfos(BundleFlag::GET_BUNDLE_DEFAULT, bundleInfos, userId); + bundleMgrProxy.GetBundleInfos(flags, bundleInfos, userId); + bundleMgrProxy.GetBundleInfosV9(flags, bundleInfos, userId); + int uid = bundleMgrProxy.GetUidByBundleName(bundleName, userId); + int32_t appIndex = fdp.ConsumeIntegral(); + bundleMgrProxy.GetUidByBundleName(bundleName, userId, appIndex); + bundleMgrProxy.GetUidByDebugBundleName(bundleName, userId); + std::string appId = bundleMgrProxy.GetAppIdByBundleName(bundleName, userId); + bundleMgrProxy.GetBundleNameForUid(uid, bundleName); + bundleMgrProxy.GetBundlesForUid(uid, bundleNames); + bundleMgrProxy.GetNameAndIndexForUid(uid, bundleName, appIndex); + std::vector gids; + bundleMgrProxy.GetBundleGids(bundleName, gids); + bundleMgrProxy.GetBundleGidsByUid(bundleName, uid, gids); + bundleMgrProxy.GetAppType(bundleName); + bundleMgrProxy.CheckIsSystemAppByUid(uid); + std::string metaData = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH); + bundleMgrProxy.GetBundleInfosByMetaData(metaData, bundleInfos); + AbilityInfo abilityInfo; + bundleMgrProxy.QueryAbilityInfo(want, abilityInfo); + bundleMgrProxy.QueryAbilityInfo(want, flags, userId, abilityInfo, nullptr); + bundleMgrProxy.UpgradeAtomicService(want, userId); + bundleMgrProxy.QueryAbilityInfo(want, flags, userId, abilityInfo); + std::vector abilityInfos; + bundleMgrProxy.QueryAbilityInfos(want, abilityInfos); + bundleMgrProxy.QueryAbilityInfos( + want, GET_ABILITY_INFO_DEFAULT, userId, abilityInfos); + bundleMgrProxy.QueryAbilityInfosV9( + want, GET_ABILITY_INFO_DEFAULT, userId, abilityInfos); + bundleMgrProxy.QueryAbilityInfos( + want, GET_ABILITY_INFO_DEFAULT, userId, abilityInfos); + bundleMgrProxy.QueryLauncherAbilityInfos(want, userId, abilityInfos); + bundleMgrProxy.QueryAllAbilityInfos(want, userId, abilityInfos); + std::string uri = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH); + bundleMgrProxy.QueryAbilityInfoByUri(uri, abilityInfo); + bundleMgrProxy.QueryAbilityInfosByUri(uri, abilityInfos); + bundleMgrProxy.QueryAbilityInfoByUri(uri, userId, abilityInfo); + bundleMgrProxy.QueryKeepAliveBundleInfos(bundleInfos); + std::string abilityName = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH); + bundleMgrProxy.GetAbilityLabel(bundleName, abilityName); + 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/bmsbundlemgrproxyparttwo_fuzzer/bmsbundlemgrproxyparttwo_fuzzer.h b/test/fuzztest/fuzztest_bundlemanager/bmsbundlemgrproxyparttwo_fuzzer/bmsbundlemgrproxyparttwo_fuzzer.h new file mode 100644 index 0000000000000000000000000000000000000000..3842383ca847668e336305eb87a220924c8ea2ae --- /dev/null +++ b/test/fuzztest/fuzztest_bundlemanager/bmsbundlemgrproxyparttwo_fuzzer/bmsbundlemgrproxyparttwo_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_BMSBUNDLEMGRPROXTPARTTWO_FUZZER_H +#define TEST_FUZZTEST_BMSBUNDLEMGRPROXTPARTTWO_FUZZER_H + +#define FUZZ_PROJECT_NAME "bmsbundlemgrproxyparttwo_fuzzer" + +#endif \ No newline at end of file diff --git a/test/fuzztest/fuzztest_bundlemanager/bmsbundlemgrproxyparttwo_fuzzer/corpus/init b/test/fuzztest/fuzztest_bundlemanager/bmsbundlemgrproxyparttwo_fuzzer/corpus/init new file mode 100644 index 0000000000000000000000000000000000000000..bc977bd9738ee9a70b362067f57a9c63d3adb801 --- /dev/null +++ b/test/fuzztest/fuzztest_bundlemanager/bmsbundlemgrproxyparttwo_fuzzer/corpus/init @@ -0,0 +1,14 @@ +# Copyright (c) 2022 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +FUZZ \ No newline at end of file diff --git a/test/fuzztest/fuzztest_bundlemanager/bmsbundlemgrproxyparttwo_fuzzer/project.xml b/test/fuzztest/fuzztest_bundlemanager/bmsbundlemgrproxyparttwo_fuzzer/project.xml new file mode 100644 index 0000000000000000000000000000000000000000..c7a73115e50e3bf14e38a1c71c37336f85045334 --- /dev/null +++ b/test/fuzztest/fuzztest_bundlemanager/bmsbundlemgrproxyparttwo_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 10000 + + 300 + + 4096 + + diff --git a/test/fuzztest/fuzztest_bundlemanager/bmsbundleresourcehost_fuzzer/BUILD.gn b/test/fuzztest/fuzztest_bundlemanager/bmsbundleresourcehost_fuzzer/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..6ef9230a8d52a7f2ab462ba5b634b6d5d6d96c82 --- /dev/null +++ b/test/fuzztest/fuzztest_bundlemanager/bmsbundleresourcehost_fuzzer/BUILD.gn @@ -0,0 +1,45 @@ +# Copyright (c) 2023 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") +module_output_path = fuzz_test_path + +##############################fuzztest########################################## +ohos_fuzztest("BMSBundleResourceHostFuzzTest") { + module_out_path = module_output_path + fuzz_config_file = + "../../../fuzztest/fuzztest_bundlemanager/bmsbundleresourcehost_fuzzer" + + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + sources = [ "bmsbundleresourcehost_fuzzer.cpp" ] + + deps = [ + "${base_path}:appexecfwk_base", + "${common_path}:libappexecfwk_common", + "${core_path}:appexecfwk_core", + ] + external_deps = [ + "ability_base:want", + "c_utils:utils", + "ipc:ipc_core", + ] +} diff --git a/test/fuzztest/fuzztest_bundlemanager/bmsbundleresourcehost_fuzzer/bmsbundleresourcehost_fuzzer.cpp b/test/fuzztest/fuzztest_bundlemanager/bmsbundleresourcehost_fuzzer/bmsbundleresourcehost_fuzzer.cpp new file mode 100644 index 0000000000000000000000000000000000000000..3822a24371d189d3400cd6c79cbd3a37d53ce323 --- /dev/null +++ b/test/fuzztest/fuzztest_bundlemanager/bmsbundleresourcehost_fuzzer/bmsbundleresourcehost_fuzzer.cpp @@ -0,0 +1,54 @@ +/* + * Copyright (c) 2023 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 "bmsbundleresourcehost_fuzzer.h" + +#include +#include +#include + +#include "bundle_resource_host.h" +#include "securec.h" +#include "../../bms_fuzztest_util.h" + +using namespace OHOS::AppExecFwk; +using namespace OHOS::AppExecFwk::BMSFuzzTestUtil; +namespace OHOS { +constexpr uint32_t CODE_MAX = 6; + +bool DoSomethingInterestingWithMyAPI(const uint8_t* data, size_t size) +{ + MessageParcel datas; + std::u16string descriptor = BundleResourceHost::GetDescriptor(); + datas.WriteInterfaceToken(descriptor); + datas.WriteBuffer(data, size); + datas.RewindRead(0); + MessageParcel reply; + MessageOption option; + BundleResourceHost bundleResourceHost; + + FuzzedDataProvider fdp(data, size); + uint8_t code = fdp.ConsumeIntegralInRange(0, CODE_MAX); + bundleResourceHost.OnRemoteRequest(code, datas, reply, option); + return true; +} +} + +// Fuzzer entry point. +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + OHOS::DoSomethingInterestingWithMyAPI(data, size); + return 0; +} \ No newline at end of file diff --git a/test/fuzztest/fuzztest_bundlemanager/bmsbundleresourcehost_fuzzer/bmsbundleresourcehost_fuzzer.h b/test/fuzztest/fuzztest_bundlemanager/bmsbundleresourcehost_fuzzer/bmsbundleresourcehost_fuzzer.h new file mode 100644 index 0000000000000000000000000000000000000000..a9b9b2a9137166ece27df5ae0d1bfe2925141299 --- /dev/null +++ b/test/fuzztest/fuzztest_bundlemanager/bmsbundleresourcehost_fuzzer/bmsbundleresourcehost_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_BMSBUNDLERESOURCEHOST_FUZZER_H +#define TEST_FUZZTEST_BMSBUNDLERESOURCEHOST_FUZZER_H + +#define FUZZ_PROJECT_NAME "bmsbundleresourcehost_fuzzer" + +#endif \ No newline at end of file diff --git a/test/fuzztest/fuzztest_bundlemanager/bmsbundleresourcehost_fuzzer/corpus/init b/test/fuzztest/fuzztest_bundlemanager/bmsbundleresourcehost_fuzzer/corpus/init new file mode 100644 index 0000000000000000000000000000000000000000..e4ceac1bcd4e3b3427eb63cea0c28304064333cc --- /dev/null +++ b/test/fuzztest/fuzztest_bundlemanager/bmsbundleresourcehost_fuzzer/corpus/init @@ -0,0 +1,14 @@ +# Copyright (c) 2023 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +FUZZ \ No newline at end of file diff --git a/test/fuzztest/fuzztest_bundlemanager/bmsbundleresourcehost_fuzzer/project.xml b/test/fuzztest/fuzztest_bundlemanager/bmsbundleresourcehost_fuzzer/project.xml new file mode 100644 index 0000000000000000000000000000000000000000..4fdbc407f205680885fa42663163b5c987f123a6 --- /dev/null +++ b/test/fuzztest/fuzztest_bundlemanager/bmsbundleresourcehost_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/test/fuzztest/fuzztest_bundlemanager/bmsbundlestatuscallbackproxy_fuzzer/BUILD.gn b/test/fuzztest/fuzztest_bundlemanager/bmsbundlestatuscallbackproxy_fuzzer/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..38ea6d945d504ea3c572d64dd197d03e8be839dd --- /dev/null +++ b/test/fuzztest/fuzztest_bundlemanager/bmsbundlestatuscallbackproxy_fuzzer/BUILD.gn @@ -0,0 +1,44 @@ +# Copyright (c) 2022-2023 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") +module_output_path = fuzz_test_path + +##############################fuzztest########################################## +ohos_fuzztest("BMSBundleStatusCallbackProxyFuzzTest") { + module_out_path = module_output_path + fuzz_config_file = + "../../../fuzztest/fuzztest_bundlemanager/bmsbundlestatuscallbackproxy_fuzzer" + + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + sources = [ "bmsbundlestatuscallbackproxy_fuzzer.cpp" ] + + deps = [ + "${base_path}:appexecfwk_base", + "${common_path}:libappexecfwk_common", + "${core_path}:appexecfwk_core", + ] + external_deps = [ + "c_utils:utils", + "ipc:ipc_core", + ] +} diff --git a/test/fuzztest/fuzztest_bundlemanager/bmsbundlestatuscallbackproxy_fuzzer/bmsbundlestatuscallbackproxy_fuzzer.cpp b/test/fuzztest/fuzztest_bundlemanager/bmsbundlestatuscallbackproxy_fuzzer/bmsbundlestatuscallbackproxy_fuzzer.cpp new file mode 100644 index 0000000000000000000000000000000000000000..d3641394e8f78424c827f412693ee78e94868703 --- /dev/null +++ b/test/fuzztest/fuzztest_bundlemanager/bmsbundlestatuscallbackproxy_fuzzer/bmsbundlestatuscallbackproxy_fuzzer.cpp @@ -0,0 +1,56 @@ +/* + * 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 "bundle_status_callback_proxy.h" + +#include "bmsbundlestatuscallbackproxy_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) + { + sptr object; + BundleStatusCallbackProxy callbackProxy(object); + FuzzedDataProvider fdp(data, size); + std::string resultMsg = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH); + std::string bundleName = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH); + uint8_t installType = fdp.ConsumeIntegral(); + int32_t resultCode = fdp.ConsumeIntegral(); + int userId = fdp.ConsumeIntegral(); + callbackProxy.OnBundleStateChanged(installType, resultCode, resultMsg, bundleName); + callbackProxy.OnBundleAdded(bundleName, userId); + int32_t appIndex = fdp.ConsumeIntegral(); + callbackProxy.OnBundleAdded(bundleName, userId, appIndex); + callbackProxy.OnBundleUpdated(bundleName, userId); + callbackProxy.OnBundleUpdated(bundleName, userId, appIndex); + callbackProxy.OnBundleRemoved(bundleName, userId); + callbackProxy.OnBundleRemoved(bundleName, userId, appIndex); + 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/bmsbundlestatuscallbackproxy_fuzzer/bmsbundlestatuscallbackproxy_fuzzer.h b/test/fuzztest/fuzztest_bundlemanager/bmsbundlestatuscallbackproxy_fuzzer/bmsbundlestatuscallbackproxy_fuzzer.h new file mode 100644 index 0000000000000000000000000000000000000000..2860e82a0916f8643129b3e01dc6097c8b5cb852 --- /dev/null +++ b/test/fuzztest/fuzztest_bundlemanager/bmsbundlestatuscallbackproxy_fuzzer/bmsbundlestatuscallbackproxy_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_BMSBUNDLESTATUSCALLBACKPROXY_FUZZER_H +#define TEST_FUZZTEST_BMSBUNDLESTATUSCALLBACKPROXY_FUZZER_H + +#define FUZZ_PROJECT_NAME "bmsbundlestatuscallbackproxy_fuzzer" + +#endif \ No newline at end of file diff --git a/test/fuzztest/fuzztest_bundlemanager/bmsbundlestatuscallbackproxy_fuzzer/corpus/init b/test/fuzztest/fuzztest_bundlemanager/bmsbundlestatuscallbackproxy_fuzzer/corpus/init new file mode 100644 index 0000000000000000000000000000000000000000..bc977bd9738ee9a70b362067f57a9c63d3adb801 --- /dev/null +++ b/test/fuzztest/fuzztest_bundlemanager/bmsbundlestatuscallbackproxy_fuzzer/corpus/init @@ -0,0 +1,14 @@ +# Copyright (c) 2022 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +FUZZ \ No newline at end of file diff --git a/test/fuzztest/fuzztest_bundlemanager/bmsbundlestatuscallbackproxy_fuzzer/project.xml b/test/fuzztest/fuzztest_bundlemanager/bmsbundlestatuscallbackproxy_fuzzer/project.xml new file mode 100644 index 0000000000000000000000000000000000000000..6e8ad2cfde8f8bda4beb6cabbe7efd8bc3c54eec --- /dev/null +++ b/test/fuzztest/fuzztest_bundlemanager/bmsbundlestatuscallbackproxy_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/test/fuzztest/fuzztest_bundlemanager/bmsbundlestreaminstallerhost_fuzzer/BUILD.gn b/test/fuzztest/fuzztest_bundlemanager/bmsbundlestreaminstallerhost_fuzzer/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..4c2cc35422d4307b7a5bd3b534cb04a2ce85e5aa --- /dev/null +++ b/test/fuzztest/fuzztest_bundlemanager/bmsbundlestreaminstallerhost_fuzzer/BUILD.gn @@ -0,0 +1,44 @@ +# Copyright (c) 2023 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") +module_output_path = fuzz_test_path + +##############################fuzztest########################################## +ohos_fuzztest("BMSBundleStreamInstallerHostFuzzTest") { + module_out_path = module_output_path + fuzz_config_file = + "../../../fuzztest/fuzztest_bundlemanager/bmsbundlestreaminstallerhost_fuzzer" + + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + sources = [ "bmsbundlestreaminstallerhost_fuzzer.cpp" ] + + deps = [ + "${base_path}:appexecfwk_base", + "${common_path}:libappexecfwk_common", + "${core_path}:appexecfwk_core", + ] + external_deps = [ + "c_utils:utils", + "ipc:ipc_core", + ] +} diff --git a/test/fuzztest/fuzztest_bundlemanager/bmsbundlestreaminstallerhost_fuzzer/bmsbundlestreaminstallerhost_fuzzer.cpp b/test/fuzztest/fuzztest_bundlemanager/bmsbundlestreaminstallerhost_fuzzer/bmsbundlestreaminstallerhost_fuzzer.cpp new file mode 100644 index 0000000000000000000000000000000000000000..e250150f90b3dd6fe309242c25022bba099f413b --- /dev/null +++ b/test/fuzztest/fuzztest_bundlemanager/bmsbundlestreaminstallerhost_fuzzer/bmsbundlestreaminstallerhost_fuzzer.cpp @@ -0,0 +1,55 @@ +/* + * 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 "bmsbundlestreaminstallerhost_fuzzer.h" + +#include +#include +#include + +#include "bundle_stream_installer_host.h" +#include "message_parcel.h" +#include "securec.h" +#include "../../bms_fuzztest_util.h" + +using namespace OHOS::AppExecFwk; +using namespace OHOS::AppExecFwk::BMSFuzzTestUtil; +namespace OHOS { +constexpr uint32_t CODE_MAX = 4; + +bool DoSomethingInterestingWithMyAPI(const uint8_t* data, size_t size) +{ + MessageParcel datas; + std::u16string descriptor = BundleStreamInstallerHost::GetDescriptor(); + datas.WriteInterfaceToken(descriptor); + datas.WriteBuffer(data, size); + datas.RewindRead(0); + MessageParcel reply; + MessageOption option; + BundleStreamInstallerHost host; + FuzzedDataProvider fdp(data, size); + uint8_t code = fdp.ConsumeIntegralInRange(0, CODE_MAX); + host.OnRemoteRequest(code, datas, reply, option); + 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/bmsbundlestreaminstallerhost_fuzzer/bmsbundlestreaminstallerhost_fuzzer.h b/test/fuzztest/fuzztest_bundlemanager/bmsbundlestreaminstallerhost_fuzzer/bmsbundlestreaminstallerhost_fuzzer.h new file mode 100644 index 0000000000000000000000000000000000000000..cf128fb82c88ff8c5bb6ef571a0f4f46b4c9693a --- /dev/null +++ b/test/fuzztest/fuzztest_bundlemanager/bmsbundlestreaminstallerhost_fuzzer/bmsbundlestreaminstallerhost_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_BMSBUNDLESTREAMINSTALLERHOST_FUZZER_H +#define TEST_FUZZTEST_BMSBUNDLESTREAMINSTALLERHOST_FUZZER_H + +#define FUZZ_PROJECT_NAME "bmsbundlestreaminstallerhost_fuzzer" + +#endif \ No newline at end of file diff --git a/test/fuzztest/fuzztest_bundlemanager/bmsbundlestreaminstallerhost_fuzzer/corpus/init b/test/fuzztest/fuzztest_bundlemanager/bmsbundlestreaminstallerhost_fuzzer/corpus/init new file mode 100644 index 0000000000000000000000000000000000000000..e4ceac1bcd4e3b3427eb63cea0c28304064333cc --- /dev/null +++ b/test/fuzztest/fuzztest_bundlemanager/bmsbundlestreaminstallerhost_fuzzer/corpus/init @@ -0,0 +1,14 @@ +# Copyright (c) 2023 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +FUZZ \ No newline at end of file diff --git a/test/fuzztest/fuzztest_bundlemanager/bmsbundlestreaminstallerhost_fuzzer/project.xml b/test/fuzztest/fuzztest_bundlemanager/bmsbundlestreaminstallerhost_fuzzer/project.xml new file mode 100644 index 0000000000000000000000000000000000000000..4fdbc407f205680885fa42663163b5c987f123a6 --- /dev/null +++ b/test/fuzztest/fuzztest_bundlemanager/bmsbundlestreaminstallerhost_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/test/fuzztest/fuzztest_bundlemanager/bmsbundlestreaminstallerproxy_fuzzer/BUILD.gn b/test/fuzztest/fuzztest_bundlemanager/bmsbundlestreaminstallerproxy_fuzzer/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..73b8761477a4ad6ffcf281f4997094974175c8ec --- /dev/null +++ b/test/fuzztest/fuzztest_bundlemanager/bmsbundlestreaminstallerproxy_fuzzer/BUILD.gn @@ -0,0 +1,44 @@ +# 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") +module_output_path = fuzz_test_path + +##############################fuzztest########################################## +ohos_fuzztest("BMSBundleStreamInstallerProxyFuzzTest") { + module_out_path = module_output_path + fuzz_config_file = + "../../../fuzztest/fuzztest_bundlemanager/bmsbundlestreaminstallerproxy_fuzzer" + + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + sources = [ "bmsbundlestreaminstallerproxy_fuzzer.cpp" ] + + deps = [ + "${base_path}:appexecfwk_base", + "${common_path}:libappexecfwk_common", + "${core_path}:appexecfwk_core", + ] + external_deps = [ + "c_utils:utils", + "ipc:ipc_core", + ] +} diff --git a/test/fuzztest/fuzztest_bundlemanager/bmsbundlestreaminstallerproxy_fuzzer/bmsbundlestreaminstallerproxy_fuzzer.cpp b/test/fuzztest/fuzztest_bundlemanager/bmsbundlestreaminstallerproxy_fuzzer/bmsbundlestreaminstallerproxy_fuzzer.cpp new file mode 100644 index 0000000000000000000000000000000000000000..6d2a7deb1002c53b634dcd46158da1562d3dda7e --- /dev/null +++ b/test/fuzztest/fuzztest_bundlemanager/bmsbundlestreaminstallerproxy_fuzzer/bmsbundlestreaminstallerproxy_fuzzer.cpp @@ -0,0 +1,50 @@ +/* + * 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 "bundle_stream_installer_proxy.h" + +#include "bmsbundlestreaminstallerproxy_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) + { + sptr object; + BundleStreamInstallerProxy callbackProxy(object); + FuzzedDataProvider fdp(data, size); + std::string hapName = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH); + callbackProxy.CreateStream(hapName); + callbackProxy.Install(); + callbackProxy.GetInstallerId(); + uint32_t installerId = fdp.ConsumeIntegral(); + callbackProxy.SetInstallerId(installerId); + callbackProxy.UnInit(); + 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/bmsbundlestreaminstallerproxy_fuzzer/bmsbundlestreaminstallerproxy_fuzzer.h b/test/fuzztest/fuzztest_bundlemanager/bmsbundlestreaminstallerproxy_fuzzer/bmsbundlestreaminstallerproxy_fuzzer.h new file mode 100644 index 0000000000000000000000000000000000000000..f34bae6fcbfd4f75dbbe2936167f84d82630b03b --- /dev/null +++ b/test/fuzztest/fuzztest_bundlemanager/bmsbundlestreaminstallerproxy_fuzzer/bmsbundlestreaminstallerproxy_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_BMSBUNDLESTREAMINSTALLERPROXY_FUZZER_H +#define TEST_FUZZTEST_BMSBUNDLESTREAMINSTALLERPROXY_FUZZER_H + +#define FUZZ_PROJECT_NAME "bmsbundlestreaminstallerproxy_fuzzer" + +#endif \ No newline at end of file diff --git a/test/fuzztest/fuzztest_bundlemanager/bmsbundlestreaminstallerproxy_fuzzer/corpus/init b/test/fuzztest/fuzztest_bundlemanager/bmsbundlestreaminstallerproxy_fuzzer/corpus/init new file mode 100644 index 0000000000000000000000000000000000000000..bc977bd9738ee9a70b362067f57a9c63d3adb801 --- /dev/null +++ b/test/fuzztest/fuzztest_bundlemanager/bmsbundlestreaminstallerproxy_fuzzer/corpus/init @@ -0,0 +1,14 @@ +# Copyright (c) 2022 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +FUZZ \ No newline at end of file diff --git a/test/fuzztest/fuzztest_bundlemanager/bmsbundlestreaminstallerproxy_fuzzer/project.xml b/test/fuzztest/fuzztest_bundlemanager/bmsbundlestreaminstallerproxy_fuzzer/project.xml new file mode 100644 index 0000000000000000000000000000000000000000..6e8ad2cfde8f8bda4beb6cabbe7efd8bc3c54eec --- /dev/null +++ b/test/fuzztest/fuzztest_bundlemanager/bmsbundlestreaminstallerproxy_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/test/fuzztest/fuzztest_bundlemanager/bmsbundlesyscap_fuzzer/BUILD.gn b/test/fuzztest/fuzztest_bundlemanager/bmsbundlesyscap_fuzzer/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..65f0f56dd2fc1978a0e126b25963ff9585e52fb9 --- /dev/null +++ b/test/fuzztest/fuzztest_bundlemanager/bmsbundlesyscap_fuzzer/BUILD.gn @@ -0,0 +1,43 @@ +# 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") +module_output_path = fuzz_test_path + +##############################fuzztest########################################## +ohos_fuzztest("BMSBundleSysCapFuzzTest") { + module_out_path = module_output_path + fuzz_config_file = + "../../../fuzztest/fuzztest_bundlemanager/bmsbundlesyscap_fuzzer" + + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + sources = [ "bmsbundlesyscap_fuzzer.cpp" ] + + deps = [ + "${base_path}:appexecfwk_base", + "${common_path}:libappexecfwk_common", + ] + external_deps = [ + "c_utils:utils", + "init:libbegetutil", + ] +} diff --git a/test/fuzztest/fuzztest_bundlemanager/bmsbundlesyscap_fuzzer/bmsbundlesyscap_fuzzer.cpp b/test/fuzztest/fuzztest_bundlemanager/bmsbundlesyscap_fuzzer/bmsbundlesyscap_fuzzer.cpp new file mode 100644 index 0000000000000000000000000000000000000000..a548397fb4ac9856e4b87d4f78658e67da4e2c84 --- /dev/null +++ b/test/fuzztest/fuzztest_bundlemanager/bmsbundlesyscap_fuzzer/bmsbundlesyscap_fuzzer.cpp @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2022 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 "bmsbundlesyscap_fuzzer.h" + +#include +#include +#include + #include + +#include "systemcapability.h" +#include "../../bms_fuzztest_util.h" + +namespace OHOS { + bool DoSomethingInterestingWithMyAPI(const uint8_t* data, size_t size) + { + FuzzedDataProvider fdp(data, size); + std::string info = fdp.ConsumeRandomLengthString(AppExecFwk::BMSFuzzTestUtil::STRING_MAX_LENGTH); + return HasSystemCapability(info.c_str()); + } +} + +/* 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/bmsbundlesyscap_fuzzer/bmsbundlesyscap_fuzzer.h b/test/fuzztest/fuzztest_bundlemanager/bmsbundlesyscap_fuzzer/bmsbundlesyscap_fuzzer.h new file mode 100644 index 0000000000000000000000000000000000000000..81e12c6c64f6b5976686402d9bd90947196c70ba --- /dev/null +++ b/test/fuzztest/fuzztest_bundlemanager/bmsbundlesyscap_fuzzer/bmsbundlesyscap_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 BMSBUNDLE_SYSCAP_FUZZER_H +#define BMSBUNDLE_SYSCAP_FUZZER_H + +#define FUZZ_PROJECT_NAME "bmsbundlesyscap_fuzzer" + +#endif \ No newline at end of file diff --git a/test/fuzztest/fuzztest_bundlemanager/bmsbundlesyscap_fuzzer/corpus/init b/test/fuzztest/fuzztest_bundlemanager/bmsbundlesyscap_fuzzer/corpus/init new file mode 100644 index 0000000000000000000000000000000000000000..bc977bd9738ee9a70b362067f57a9c63d3adb801 --- /dev/null +++ b/test/fuzztest/fuzztest_bundlemanager/bmsbundlesyscap_fuzzer/corpus/init @@ -0,0 +1,14 @@ +# Copyright (c) 2022 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +FUZZ \ No newline at end of file diff --git a/test/fuzztest/fuzztest_bundlemanager/bmsbundlesyscap_fuzzer/project.xml b/test/fuzztest/fuzztest_bundlemanager/bmsbundlesyscap_fuzzer/project.xml new file mode 100644 index 0000000000000000000000000000000000000000..66e1dcac475475fb101b6f8670ec699e6e9696aa --- /dev/null +++ b/test/fuzztest/fuzztest_bundlemanager/bmsbundlesyscap_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/test/fuzztest/fuzztest_bundlemanager/bmsbundleuserinfo_fuzzer/BUILD.gn b/test/fuzztest/fuzztest_bundlemanager/bmsbundleuserinfo_fuzzer/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..165dbaa2d38a6877f610720d0a377fde5d91f0de --- /dev/null +++ b/test/fuzztest/fuzztest_bundlemanager/bmsbundleuserinfo_fuzzer/BUILD.gn @@ -0,0 +1,43 @@ +# 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") +module_output_path = fuzz_test_path + +##############################fuzztest########################################## +ohos_fuzztest("BMSBundleUserInfoFuzzTest") { + module_out_path = module_output_path + fuzz_config_file = + "../../../fuzztest/fuzztest_bundlemanager/bmsbundleuserinfo_fuzzer" + + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + sources = [ "bmsbundleuserinfo_fuzzer.cpp" ] + + deps = [ + "${base_path}:appexecfwk_base", + "${common_path}:libappexecfwk_common", + ] + external_deps = [ + "c_utils:utils", + "ipc:ipc_core", + ] +} diff --git a/test/fuzztest/fuzztest_bundlemanager/bmsbundleuserinfo_fuzzer/bmsbundleuserinfo_fuzzer.cpp b/test/fuzztest/fuzztest_bundlemanager/bmsbundleuserinfo_fuzzer/bmsbundleuserinfo_fuzzer.cpp new file mode 100644 index 0000000000000000000000000000000000000000..23525e6d7640c12426bd3892550c85cf82bca631 --- /dev/null +++ b/test/fuzztest/fuzztest_bundlemanager/bmsbundleuserinfo_fuzzer/bmsbundleuserinfo_fuzzer.cpp @@ -0,0 +1,57 @@ +/* + * 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 "bundle_user_info.h" +#include "parcel.h" + +#include "bmsbundleuserinfo_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) + { + Parcel dataMessageParcel; + BundleUserInfo bundleUserInfo; + FuzzedDataProvider fdp(data, size); + GenerateBundleUserInfo(fdp, bundleUserInfo); + if (!bundleUserInfo.Marshalling(dataMessageParcel)) { + return false; + } + auto rulePtr = BundleUserInfo::Unmarshalling(dataMessageParcel); + if (rulePtr == nullptr) { + return false; + } + delete rulePtr; + rulePtr = nullptr; + BundleUserInfo newBundleUserInfo; + GenerateBundleUserInfo(fdp, newBundleUserInfo); + bool ret = newBundleUserInfo.ReadFromParcel(dataMessageParcel); + return ret; + } +} + +// 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/bmsbundleuserinfo_fuzzer/bmsbundleuserinfo_fuzzer.h b/test/fuzztest/fuzztest_bundlemanager/bmsbundleuserinfo_fuzzer/bmsbundleuserinfo_fuzzer.h new file mode 100644 index 0000000000000000000000000000000000000000..94cd5bf5dad38ca939966dfd170572b78742ff3f --- /dev/null +++ b/test/fuzztest/fuzztest_bundlemanager/bmsbundleuserinfo_fuzzer/bmsbundleuserinfo_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_BMSBUNDLE_USER_INFO__FUZZER_H +#define TEST_FUZZTEST_BMSBUNDLE_USER_INFO__FUZZER_H + +#define FUZZ_PROJECT_NAME "bmsbundleuserinfo_fuzzer" + +#endif // TEST_FUZZTEST_BUNDLE_USER_INFO__FUZZER_H diff --git a/test/fuzztest/fuzztest_bundlemanager/bmsbundleuserinfo_fuzzer/corpus/init b/test/fuzztest/fuzztest_bundlemanager/bmsbundleuserinfo_fuzzer/corpus/init new file mode 100644 index 0000000000000000000000000000000000000000..1b910144fb1ff33a40a44b1d2a491b1ab05b598b --- /dev/null +++ b/test/fuzztest/fuzztest_bundlemanager/bmsbundleuserinfo_fuzzer/corpus/init @@ -0,0 +1,13 @@ +# Copyright (c) 2022 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +FUZZ \ No newline at end of file diff --git a/test/fuzztest/fuzztest_bundlemanager/bmsbundleuserinfo_fuzzer/project.xml b/test/fuzztest/fuzztest_bundlemanager/bmsbundleuserinfo_fuzzer/project.xml new file mode 100644 index 0000000000000000000000000000000000000000..6e8ad2cfde8f8bda4beb6cabbe7efd8bc3c54eec --- /dev/null +++ b/test/fuzztest/fuzztest_bundlemanager/bmsbundleuserinfo_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/test/fuzztest/fuzztest_bundlemanager/bmsbundleusermgrhost_fuzzer/BUILD.gn b/test/fuzztest/fuzztest_bundlemanager/bmsbundleusermgrhost_fuzzer/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..a19dfc52e002a57358c6c21aeb53bc1bf0c21e62 --- /dev/null +++ b/test/fuzztest/fuzztest_bundlemanager/bmsbundleusermgrhost_fuzzer/BUILD.gn @@ -0,0 +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. + +#####################hydra-fuzz################### +import("//build/config/features.gni") +import("//build/ohos.gni") +import("//build/test.gni") +import("../../../../appexecfwk.gni") +module_output_path = fuzz_test_path + +##############################fuzztest########################################## +ohos_fuzztest("BMSBundleUserMgrHostFuzzTest") { + module_out_path = module_output_path + fuzz_config_file = + "../../../fuzztest/fuzztest_bundlemanager/bmsbundleusermgrhost_fuzzer" + + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + sources = [ "bmsbundleusermgrhost_fuzzer.cpp" ] + + deps = [ + "${base_path}:appexecfwk_base", + "${common_path}:libappexecfwk_common", + "${core_path}:appexecfwk_core", + ] + external_deps = [ + "ability_base:want", + "c_utils:utils", + "ipc:ipc_core", + ] +} diff --git a/test/fuzztest/fuzztest_bundlemanager/bmsbundleusermgrhost_fuzzer/bmsbundleusermgrhost_fuzzer.cpp b/test/fuzztest/fuzztest_bundlemanager/bmsbundleusermgrhost_fuzzer/bmsbundleusermgrhost_fuzzer.cpp new file mode 100644 index 0000000000000000000000000000000000000000..9b7f2099cd7b271219549cdc6fda7f4b889b1661 --- /dev/null +++ b/test/fuzztest/fuzztest_bundlemanager/bmsbundleusermgrhost_fuzzer/bmsbundleusermgrhost_fuzzer.cpp @@ -0,0 +1,54 @@ +/* + * Copyright (c) 2023 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 "bmsbundleusermgrhost_fuzzer.h" + +#include +#include + #include + +#include "bundle_user_mgr_host.h" +#include "securec.h" + #include "../../bms_fuzztest_util.h" + +using namespace OHOS::AppExecFwk; +using namespace OHOS::AppExecFwk::BMSFuzzTestUtil; +namespace OHOS { +constexpr uint32_t CODE_MAX = 1; + +bool DoSomethingInterestingWithMyAPI(const uint8_t* data, size_t size) +{ + MessageParcel datas; + std::u16string descriptor = BundleUserMgrHost::GetDescriptor(); + datas.WriteInterfaceToken(descriptor); + datas.WriteBuffer(data, size); + datas.RewindRead(0); + MessageParcel reply; + MessageOption option; + BundleUserMgrHost bundleUserMgrHost; + FuzzedDataProvider fdp(data, size); + uint8_t code = fdp.ConsumeIntegralInRange(0, CODE_MAX); + bundleUserMgrHost.OnRemoteRequest(code, datas, reply, option); + 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/bmsbundleusermgrhost_fuzzer/bmsbundleusermgrhost_fuzzer.h b/test/fuzztest/fuzztest_bundlemanager/bmsbundleusermgrhost_fuzzer/bmsbundleusermgrhost_fuzzer.h new file mode 100644 index 0000000000000000000000000000000000000000..d7ec580e0fc19a7b27e970a147572c0c75f7d6d9 --- /dev/null +++ b/test/fuzztest/fuzztest_bundlemanager/bmsbundleusermgrhost_fuzzer/bmsbundleusermgrhost_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_BMSBUNDLEUSERMGRHOST_FUZZER_H +#define TEST_FUZZTEST_BMSBUNDLEUSERMGRHOST_FUZZER_H + +#define FUZZ_PROJECT_NAME "bmsbundleusermgrhost_fuzzer" + +#endif \ No newline at end of file diff --git a/test/fuzztest/fuzztest_bundlemanager/bmsbundleusermgrhost_fuzzer/corpus/init b/test/fuzztest/fuzztest_bundlemanager/bmsbundleusermgrhost_fuzzer/corpus/init new file mode 100644 index 0000000000000000000000000000000000000000..e4ceac1bcd4e3b3427eb63cea0c28304064333cc --- /dev/null +++ b/test/fuzztest/fuzztest_bundlemanager/bmsbundleusermgrhost_fuzzer/corpus/init @@ -0,0 +1,14 @@ +# Copyright (c) 2023 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +FUZZ \ No newline at end of file diff --git a/test/fuzztest/fuzztest_bundlemanager/bmsbundleusermgrhost_fuzzer/project.xml b/test/fuzztest/fuzztest_bundlemanager/bmsbundleusermgrhost_fuzzer/project.xml new file mode 100644 index 0000000000000000000000000000000000000000..4fdbc407f205680885fa42663163b5c987f123a6 --- /dev/null +++ b/test/fuzztest/fuzztest_bundlemanager/bmsbundleusermgrhost_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/test/fuzztest/fuzztest_bundlemanager/bmsbundleusermgrproxy_fuzzer/BUILD.gn b/test/fuzztest/fuzztest_bundlemanager/bmsbundleusermgrproxy_fuzzer/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..78bfd12d183165bf7df208a63f5918723a920e0b --- /dev/null +++ b/test/fuzztest/fuzztest_bundlemanager/bmsbundleusermgrproxy_fuzzer/BUILD.gn @@ -0,0 +1,44 @@ +# 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") +module_output_path = fuzz_test_path + +##############################fuzztest########################################## +ohos_fuzztest("BMSBundleUserMgrProxyFuzzTest") { + module_out_path = module_output_path + fuzz_config_file = + "../../../fuzztest/fuzztest_bundlemanager/bmsbundleusermgrproxy_fuzzer" + + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + sources = [ "bmsbundleusermgrproxy_fuzzer.cpp" ] + + deps = [ + "${base_path}:appexecfwk_base", + "${common_path}:libappexecfwk_common", + "${core_path}:appexecfwk_core", + ] + external_deps = [ + "c_utils:utils", + "ipc:ipc_core", + ] +} diff --git a/test/fuzztest/fuzztest_bundlemanager/bmsbundleusermgrproxy_fuzzer/bmsbundleusermgrproxy_fuzzer.cpp b/test/fuzztest/fuzztest_bundlemanager/bmsbundleusermgrproxy_fuzzer/bmsbundleusermgrproxy_fuzzer.cpp new file mode 100644 index 0000000000000000000000000000000000000000..138544d17bef002663bd91c37ab09ff818328406 --- /dev/null +++ b/test/fuzztest/fuzztest_bundlemanager/bmsbundleusermgrproxy_fuzzer/bmsbundleusermgrproxy_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 + +#include "bundle_user_mgr_proxy.h" + +#include "bmsbundleusermgrproxy_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) + { + sptr object; + BundleUserMgrProxy userMgrProxy(object); + FuzzedDataProvider fdp(data, size); + int32_t userId = fdp.ConsumeIntegral(); + userMgrProxy.CreateNewUser(userId); + userMgrProxy.RemoveUser(userId); + 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/bmsbundleusermgrproxy_fuzzer/bmsbundleusermgrproxy_fuzzer.h b/test/fuzztest/fuzztest_bundlemanager/bmsbundleusermgrproxy_fuzzer/bmsbundleusermgrproxy_fuzzer.h new file mode 100644 index 0000000000000000000000000000000000000000..718b52660c1a3c06d5185a38e0485ab50cf4abf6 --- /dev/null +++ b/test/fuzztest/fuzztest_bundlemanager/bmsbundleusermgrproxy_fuzzer/bmsbundleusermgrproxy_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_BMSBUNDLEUSERMGRPROXY_FUZZER_H +#define TEST_FUZZTEST_BMSBUNDLEUSERMGRPROXY_FUZZER_H + +#define FUZZ_PROJECT_NAME "bmsbundleusermgrproxy_fuzzer" + +#endif \ No newline at end of file diff --git a/test/fuzztest/fuzztest_bundlemanager/bmsbundleusermgrproxy_fuzzer/corpus/init b/test/fuzztest/fuzztest_bundlemanager/bmsbundleusermgrproxy_fuzzer/corpus/init new file mode 100644 index 0000000000000000000000000000000000000000..bc977bd9738ee9a70b362067f57a9c63d3adb801 --- /dev/null +++ b/test/fuzztest/fuzztest_bundlemanager/bmsbundleusermgrproxy_fuzzer/corpus/init @@ -0,0 +1,14 @@ +# Copyright (c) 2022 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +FUZZ \ No newline at end of file diff --git a/test/fuzztest/fuzztest_bundlemanager/bmsbundleusermgrproxy_fuzzer/project.xml b/test/fuzztest/fuzztest_bundlemanager/bmsbundleusermgrproxy_fuzzer/project.xml new file mode 100644 index 0000000000000000000000000000000000000000..6e8ad2cfde8f8bda4beb6cabbe7efd8bc3c54eec --- /dev/null +++ b/test/fuzztest/fuzztest_bundlemanager/bmsbundleusermgrproxy_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/test/fuzztest/fuzztest_bundlemanager/bmscheckissystemappbyuid_fuzzer/BUILD.gn b/test/fuzztest/fuzztest_bundlemanager/bmscheckissystemappbyuid_fuzzer/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..fdf30e22adaa7f6b38ea253ea2ee7bf36e8b4111 --- /dev/null +++ b/test/fuzztest/fuzztest_bundlemanager/bmscheckissystemappbyuid_fuzzer/BUILD.gn @@ -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. + +#####################hydra-fuzz################### +import("//build/config/features.gni") +import("//build/ohos.gni") +import("//build/test.gni") +import("../../../../appexecfwk.gni") +module_output_path = fuzz_test_path + +##############################fuzztest########################################## +ohos_fuzztest("BMSCheckIsSystemAppByUidFuzzTest") { + module_out_path = module_output_path + fuzz_config_file = + "../../../fuzztest/fuzztest_bundlemanager/bmscheckissystemappbyuid_fuzzer" + + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + sources = [ "bmscheckissystemappbyuid_fuzzer.cpp" ] + + deps = [ + "${base_path}:appexecfwk_base", + "${common_path}:libappexecfwk_common", + "${core_path}:appexecfwk_core", + ] + external_deps = [ + "ability_base:want", + "c_utils:utils", + "ipc:ipc_core", + "safwk:system_ability_fwk", + "samgr:samgr_proxy", + ] +} diff --git a/test/fuzztest/fuzztest_bundlemanager/bmscheckissystemappbyuid_fuzzer/bmscheckissystemappbyuid_fuzzer.cpp b/test/fuzztest/fuzztest_bundlemanager/bmscheckissystemappbyuid_fuzzer/bmscheckissystemappbyuid_fuzzer.cpp new file mode 100644 index 0000000000000000000000000000000000000000..cb46a9e5e97f58076da6f75e18a6b2cfe3330f6c --- /dev/null +++ b/test/fuzztest/fuzztest_bundlemanager/bmscheckissystemappbyuid_fuzzer/bmscheckissystemappbyuid_fuzzer.cpp @@ -0,0 +1,69 @@ +/* + * 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 "bmscheckissystemappbyuid_fuzzer.h" + +#include +#include +#include + #include + +#include "bundle_mgr_interface.h" +#include "if_system_ability_manager.h" +#include "iservice_registry.h" +#include "system_ability_definition.h" + #include "../../bms_fuzztest_util.h" + +using namespace OHOS::AppExecFwk; +using namespace OHOS::AppExecFwk::BMSFuzzTestUtil; + +namespace OHOS { + sptr GetBundleMgr() + { + auto systemAbilityManager = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); + if (systemAbilityManager == nullptr) { + std::cout << "GetBundleMgr GetSystemAbilityManager is null"; + return nullptr; + } + + auto bundleMgrSa = systemAbilityManager->GetSystemAbility(BUNDLE_MGR_SERVICE_SYS_ABILITY_ID); + if (bundleMgrSa == nullptr) { + std::cout << "[fuzz] GetBundleMgr GetSystemAbility is null"; + return nullptr; + } + + return iface_cast(bundleMgrSa); + } + + bool DoSomethingInterestingWithMyAPI(const uint8_t* data, size_t size) + { + auto bundleMgr = GetBundleMgr(); + if (bundleMgr == nullptr) { + return false; + } + FuzzedDataProvider fdp(data, size); + int uid = fdp.ConsumeIntegral(); + + return bundleMgr->CheckIsSystemAppByUid(uid); + } +} + +/* 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/bmscheckissystemappbyuid_fuzzer/bmscheckissystemappbyuid_fuzzer.h b/test/fuzztest/fuzztest_bundlemanager/bmscheckissystemappbyuid_fuzzer/bmscheckissystemappbyuid_fuzzer.h new file mode 100644 index 0000000000000000000000000000000000000000..f4d2a05e35ca18cce22fe3aec9953ebfdf54e688 --- /dev/null +++ b/test/fuzztest/fuzztest_bundlemanager/bmscheckissystemappbyuid_fuzzer/bmscheckissystemappbyuid_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 BMSCHECKSYSAPPUID_FUZZER_H +#define BMSCHECKSYSAPPUID_FUZZER_H + +#define FUZZ_PROJECT_NAME "bmscheckissystemappbyuid_fuzzer" + +#endif diff --git a/test/fuzztest/fuzztest_bundlemanager/bmscheckissystemappbyuid_fuzzer/corpus/init b/test/fuzztest/fuzztest_bundlemanager/bmscheckissystemappbyuid_fuzzer/corpus/init new file mode 100644 index 0000000000000000000000000000000000000000..bc977bd9738ee9a70b362067f57a9c63d3adb801 --- /dev/null +++ b/test/fuzztest/fuzztest_bundlemanager/bmscheckissystemappbyuid_fuzzer/corpus/init @@ -0,0 +1,14 @@ +# Copyright (c) 2022 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +FUZZ \ No newline at end of file diff --git a/test/fuzztest/fuzztest_bundlemanager/bmscheckissystemappbyuid_fuzzer/project.xml b/test/fuzztest/fuzztest_bundlemanager/bmscheckissystemappbyuid_fuzzer/project.xml new file mode 100644 index 0000000000000000000000000000000000000000..85e7ef2c1cc6471e288306f6e3dcea5287a78b0e --- /dev/null +++ b/test/fuzztest/fuzztest_bundlemanager/bmscheckissystemappbyuid_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/test/fuzztest/fuzztest_bundlemanager/bmscleanbundlecachefiles_fuzzer/BUILD.gn b/test/fuzztest/fuzztest_bundlemanager/bmscleanbundlecachefiles_fuzzer/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..8902d2e632abaa502a657f204afbaf2d906ef858 --- /dev/null +++ b/test/fuzztest/fuzztest_bundlemanager/bmscleanbundlecachefiles_fuzzer/BUILD.gn @@ -0,0 +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. + +#####################hydra-fuzz################### +import("//build/config/features.gni") +import("//build/ohos.gni") +import("//build/test.gni") +import("../../../../appexecfwk.gni") +module_output_path = fuzz_test_path + +##############################fuzztest########################################## +ohos_fuzztest("BMSCleanBundleCacheFilesFuzzTest") { + module_out_path = module_output_path + fuzz_config_file = + "../../../fuzztest/fuzztest_bundlemanager/bmscleanbundlecachefiles_fuzzer" + + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + sources = [ "bmscleanbundlecachefiles_fuzzer.cpp" ] + + deps = [ + "${base_path}:appexecfwk_base", + "${common_path}:libappexecfwk_common", + "${core_path}:appexecfwk_core", + ] + external_deps = [ + "ability_base:want", + "c_utils:utils", + "ipc:ipc_core", + ] +} diff --git a/test/fuzztest/fuzztest_bundlemanager/bmscleanbundlecachefiles_fuzzer/bmscleanbundlecachefiles_fuzzer.cpp b/test/fuzztest/fuzztest_bundlemanager/bmscleanbundlecachefiles_fuzzer/bmscleanbundlecachefiles_fuzzer.cpp new file mode 100644 index 0000000000000000000000000000000000000000..2bcd82eee4f1af2d206836d150129a675620fa32 --- /dev/null +++ b/test/fuzztest/fuzztest_bundlemanager/bmscleanbundlecachefiles_fuzzer/bmscleanbundlecachefiles_fuzzer.cpp @@ -0,0 +1,49 @@ +/* + * 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 "bundle_mgr_proxy.h" + +#include "bmscleanbundlecachefiles_fuzzer.h" +#include "../../bms_fuzztest_util.h" + +using Want = OHOS::AAFwk::Want; + +using namespace OHOS::AppExecFwk; +using namespace OHOS::AppExecFwk::BMSFuzzTestUtil; +namespace OHOS { + bool DoSomethingInterestingWithMyAPI(const uint8_t* data, size_t size) + { + sptr object; + BundleMgrProxy bundleMgrProxy(object); + FuzzedDataProvider fdp(data, size); + std::string bundleName = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH); + sptr cleanCacheCallback; + bundleMgrProxy.CleanBundleCacheFiles(bundleName, cleanCacheCallback, + reinterpret_cast(data)); + 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/bmscleanbundlecachefiles_fuzzer/bmscleanbundlecachefiles_fuzzer.h b/test/fuzztest/fuzztest_bundlemanager/bmscleanbundlecachefiles_fuzzer/bmscleanbundlecachefiles_fuzzer.h new file mode 100644 index 0000000000000000000000000000000000000000..908f286e823bc85a9876fcfb3dd3f24af869e647 --- /dev/null +++ b/test/fuzztest/fuzztest_bundlemanager/bmscleanbundlecachefiles_fuzzer/bmscleanbundlecachefiles_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_BMSCLEANBUNDLECACHEFILES_FUZZER_H +#define TEST_FUZZTEST_BMSCLEANBUNDLECACHEFILES_FUZZER_H + +#define FUZZ_PROJECT_NAME "bmscleanbundlecachefiles_fuzzer" + +#endif \ No newline at end of file diff --git a/test/fuzztest/fuzztest_bundlemanager/bmscleanbundlecachefiles_fuzzer/corpus/init b/test/fuzztest/fuzztest_bundlemanager/bmscleanbundlecachefiles_fuzzer/corpus/init new file mode 100644 index 0000000000000000000000000000000000000000..bc977bd9738ee9a70b362067f57a9c63d3adb801 --- /dev/null +++ b/test/fuzztest/fuzztest_bundlemanager/bmscleanbundlecachefiles_fuzzer/corpus/init @@ -0,0 +1,14 @@ +# Copyright (c) 2022 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +FUZZ \ No newline at end of file diff --git a/test/fuzztest/fuzztest_bundlemanager/bmscleanbundlecachefiles_fuzzer/project.xml b/test/fuzztest/fuzztest_bundlemanager/bmscleanbundlecachefiles_fuzzer/project.xml new file mode 100644 index 0000000000000000000000000000000000000000..6e8ad2cfde8f8bda4beb6cabbe7efd8bc3c54eec --- /dev/null +++ b/test/fuzztest/fuzztest_bundlemanager/bmscleanbundlecachefiles_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/test/fuzztest/fuzztest_bundlemanager/bmscleanbundledatafiles_fuzzer/BUILD.gn b/test/fuzztest/fuzztest_bundlemanager/bmscleanbundledatafiles_fuzzer/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..98cb623bf07ebb468ff2dca5ec33826e0da4c5fc --- /dev/null +++ b/test/fuzztest/fuzztest_bundlemanager/bmscleanbundledatafiles_fuzzer/BUILD.gn @@ -0,0 +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. + +#####################hydra-fuzz################### +import("//build/config/features.gni") +import("//build/ohos.gni") +import("//build/test.gni") +import("../../../../appexecfwk.gni") +module_output_path = fuzz_test_path + +##############################fuzztest########################################## +ohos_fuzztest("BMSCleanBundleDataFilesFuzzTest") { + module_out_path = module_output_path + fuzz_config_file = + "../../../fuzztest/fuzztest_bundlemanager/bmscleanbundledatafiles_fuzzer" + + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + sources = [ "bmscleanbundledatafiles_fuzzer.cpp" ] + + deps = [ + "${base_path}:appexecfwk_base", + "${common_path}:libappexecfwk_common", + "${core_path}:appexecfwk_core", + ] + external_deps = [ + "ability_base:want", + "c_utils:utils", + "ipc:ipc_core", + ] +} diff --git a/test/fuzztest/fuzztest_bundlemanager/bmscleanbundledatafiles_fuzzer/bmscleanbundledatafiles_fuzzer.cpp b/test/fuzztest/fuzztest_bundlemanager/bmscleanbundledatafiles_fuzzer/bmscleanbundledatafiles_fuzzer.cpp new file mode 100644 index 0000000000000000000000000000000000000000..dd8282b5769dc06e6cd6667378f23c53b85ef88f --- /dev/null +++ b/test/fuzztest/fuzztest_bundlemanager/bmscleanbundledatafiles_fuzzer/bmscleanbundledatafiles_fuzzer.cpp @@ -0,0 +1,49 @@ +/* + * 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 "bundle_mgr_proxy.h" + +#include "bmscleanbundledatafiles_fuzzer.h" +#include "../../bms_fuzztest_util.h" + +using Want = OHOS::AAFwk::Want; + +using namespace OHOS::AppExecFwk; +using namespace OHOS::AppExecFwk::BMSFuzzTestUtil; +namespace OHOS { + bool DoSomethingInterestingWithMyAPI(const uint8_t* data, size_t size) + { + sptr object; + BundleMgrProxy bundleMgrProxy(object); + FuzzedDataProvider fdp(data, size); + std::string bundleName = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH); + int userId = fdp.ConsumeIntegral(); + int appIndex = fdp.ConsumeIntegral(); + bundleMgrProxy.CleanBundleDataFiles(bundleName, userId, appIndex); + 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/bmscleanbundledatafiles_fuzzer/bmscleanbundledatafiles_fuzzer.h b/test/fuzztest/fuzztest_bundlemanager/bmscleanbundledatafiles_fuzzer/bmscleanbundledatafiles_fuzzer.h new file mode 100644 index 0000000000000000000000000000000000000000..86caa65e0973c2cc8b15ec58da5585ec708a1a4e --- /dev/null +++ b/test/fuzztest/fuzztest_bundlemanager/bmscleanbundledatafiles_fuzzer/bmscleanbundledatafiles_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_BMSCLEANBUNDLEDATAFILES_FUZZER_H +#define TEST_FUZZTEST_BMSCLEANBUNDLEDATAFILES_FUZZER_H + +#define FUZZ_PROJECT_NAME "bmscleanbundledatafiles_fuzzer" + +#endif \ No newline at end of file diff --git a/test/fuzztest/fuzztest_bundlemanager/bmscleanbundledatafiles_fuzzer/corpus/init b/test/fuzztest/fuzztest_bundlemanager/bmscleanbundledatafiles_fuzzer/corpus/init new file mode 100644 index 0000000000000000000000000000000000000000..bc977bd9738ee9a70b362067f57a9c63d3adb801 --- /dev/null +++ b/test/fuzztest/fuzztest_bundlemanager/bmscleanbundledatafiles_fuzzer/corpus/init @@ -0,0 +1,14 @@ +# Copyright (c) 2022 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +FUZZ \ No newline at end of file diff --git a/test/fuzztest/fuzztest_bundlemanager/bmscleanbundledatafiles_fuzzer/project.xml b/test/fuzztest/fuzztest_bundlemanager/bmscleanbundledatafiles_fuzzer/project.xml new file mode 100644 index 0000000000000000000000000000000000000000..6e8ad2cfde8f8bda4beb6cabbe7efd8bc3c54eec --- /dev/null +++ b/test/fuzztest/fuzztest_bundlemanager/bmscleanbundledatafiles_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/test/fuzztest/fuzztest_bundlemanager/bmscleancachecallbackproxy_fuzzer/BUILD.gn b/test/fuzztest/fuzztest_bundlemanager/bmscleancachecallbackproxy_fuzzer/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..a53c5c7d5e5d76c99de377387f180fd39c5c0960 --- /dev/null +++ b/test/fuzztest/fuzztest_bundlemanager/bmscleancachecallbackproxy_fuzzer/BUILD.gn @@ -0,0 +1,44 @@ +# 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") +module_output_path = fuzz_test_path + +##############################fuzztest########################################## +ohos_fuzztest("BMSCleanCacheCallbackProxyFuzzTest") { + module_out_path = module_output_path + fuzz_config_file = + "../../../fuzztest/fuzztest_bundlemanager/bmscleancachecallbackproxy_fuzzer" + + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + sources = [ "bmscleancachecallbackproxy_fuzzer.cpp" ] + + deps = [ + "${base_path}:appexecfwk_base", + "${common_path}:libappexecfwk_common", + "${core_path}:appexecfwk_core", + ] + external_deps = [ + "c_utils:utils", + "ipc:ipc_core", + ] +} diff --git a/test/fuzztest/fuzztest_bundlemanager/bmscleancachecallbackproxy_fuzzer/bmscleancachecallbackproxy_fuzzer.cpp b/test/fuzztest/fuzztest_bundlemanager/bmscleancachecallbackproxy_fuzzer/bmscleancachecallbackproxy_fuzzer.cpp new file mode 100644 index 0000000000000000000000000000000000000000..0b2abb29d4b6bee8fdc56ae68c628fdaecb18136 --- /dev/null +++ b/test/fuzztest/fuzztest_bundlemanager/bmscleancachecallbackproxy_fuzzer/bmscleancachecallbackproxy_fuzzer.cpp @@ -0,0 +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. + */ + +#include +#include +#include + +#include "clean_cache_callback_proxy.h" + +#include "bmscleancachecallbackproxy_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) + { + sptr object; + CleanCacheCallbackProxy callbackProxy(object); + FuzzedDataProvider fdp(data, size); + bool succeeded = fdp.ConsumeBool(); + callbackProxy.OnCleanCacheFinished(succeeded); + 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/bmscleancachecallbackproxy_fuzzer/bmscleancachecallbackproxy_fuzzer.h b/test/fuzztest/fuzztest_bundlemanager/bmscleancachecallbackproxy_fuzzer/bmscleancachecallbackproxy_fuzzer.h new file mode 100644 index 0000000000000000000000000000000000000000..436c6de38d80ae4c8d56bde263fb1721135fb359 --- /dev/null +++ b/test/fuzztest/fuzztest_bundlemanager/bmscleancachecallbackproxy_fuzzer/bmscleancachecallbackproxy_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_BMSCLEANCACHECALLBACKPROXY_FUZZER_H +#define TEST_FUZZTEST_BMSCLEANCACHECALLBACKPROXY_FUZZER_H + +#define FUZZ_PROJECT_NAME "bmscleancachecallbackproxy_fuzzer" + +#endif \ No newline at end of file diff --git a/test/fuzztest/fuzztest_bundlemanager/bmscleancachecallbackproxy_fuzzer/corpus/init b/test/fuzztest/fuzztest_bundlemanager/bmscleancachecallbackproxy_fuzzer/corpus/init new file mode 100644 index 0000000000000000000000000000000000000000..bc977bd9738ee9a70b362067f57a9c63d3adb801 --- /dev/null +++ b/test/fuzztest/fuzztest_bundlemanager/bmscleancachecallbackproxy_fuzzer/corpus/init @@ -0,0 +1,14 @@ +# Copyright (c) 2022 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +FUZZ \ No newline at end of file diff --git a/test/fuzztest/fuzztest_bundlemanager/bmscleancachecallbackproxy_fuzzer/project.xml b/test/fuzztest/fuzztest_bundlemanager/bmscleancachecallbackproxy_fuzzer/project.xml new file mode 100644 index 0000000000000000000000000000000000000000..6e8ad2cfde8f8bda4beb6cabbe7efd8bc3c54eec --- /dev/null +++ b/test/fuzztest/fuzztest_bundlemanager/bmscleancachecallbackproxy_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/test/fuzztest/fuzztest_bundlemanager/bmsdefaultapphost_fuzzer/BUILD.gn b/test/fuzztest/fuzztest_bundlemanager/bmsdefaultapphost_fuzzer/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..2a4b87ab2b6cdc277e7e101901027bb9c3957574 --- /dev/null +++ b/test/fuzztest/fuzztest_bundlemanager/bmsdefaultapphost_fuzzer/BUILD.gn @@ -0,0 +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. + +#####################hydra-fuzz################### +import("//build/config/features.gni") +import("//build/ohos.gni") +import("//build/test.gni") +import("../../../../appexecfwk.gni") +module_output_path = fuzz_test_path + +##############################fuzztest########################################## +ohos_fuzztest("BMSDefaultAppHostFuzzTest") { + module_out_path = module_output_path + fuzz_config_file = + "../../../fuzztest/fuzztest_bundlemanager/bmsdefaultapphost_fuzzer" + + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + sources = [ "bmsdefaultapphost_fuzzer.cpp" ] + + deps = [ + "${base_path}:appexecfwk_base", + "${common_path}:libappexecfwk_common", + "${core_path}:appexecfwk_core", + ] + external_deps = [ + "ability_base:want", + "c_utils:utils", + "ipc:ipc_core", + ] +} diff --git a/test/fuzztest/fuzztest_bundlemanager/bmsdefaultapphost_fuzzer/bmsdefaultapphost_fuzzer.cpp b/test/fuzztest/fuzztest_bundlemanager/bmsdefaultapphost_fuzzer/bmsdefaultapphost_fuzzer.cpp new file mode 100644 index 0000000000000000000000000000000000000000..2ed663303a94f97af89abea7534ebb8cdb6ea46f --- /dev/null +++ b/test/fuzztest/fuzztest_bundlemanager/bmsdefaultapphost_fuzzer/bmsdefaultapphost_fuzzer.cpp @@ -0,0 +1,54 @@ +/* + * 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 "bmsdefaultapphost_fuzzer.h" + +#include +#include +#include +#define private public +#include "default_app_host.h" +#include "securec.h" +#include "../../bms_fuzztest_util.h" + +using namespace OHOS::AppExecFwk; +using namespace OHOS::AppExecFwk::BMSFuzzTestUtil; +namespace OHOS { +constexpr uint32_t CODE_MAX = 3; + +bool DoSomethingInterestingWithMyAPI(const uint8_t* data, size_t size) +{ + MessageParcel datas; + std::u16string descriptor = DefaultAppHost::GetDescriptor(); + datas.WriteInterfaceToken(descriptor); + datas.WriteBuffer(data, size); + datas.RewindRead(0); + MessageParcel reply; + MessageOption option; + DefaultAppHost defaultAppHost; + FuzzedDataProvider fdp(data, size); + uint8_t code = fdp.ConsumeIntegralInRange(0, CODE_MAX); + defaultAppHost.OnRemoteRequest(code, datas, reply, option); + 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/bmsdefaultapphost_fuzzer/bmsdefaultapphost_fuzzer.h b/test/fuzztest/fuzztest_bundlemanager/bmsdefaultapphost_fuzzer/bmsdefaultapphost_fuzzer.h new file mode 100644 index 0000000000000000000000000000000000000000..c4cc3eb29ade73992d5ce56622018508f17090c2 --- /dev/null +++ b/test/fuzztest/fuzztest_bundlemanager/bmsdefaultapphost_fuzzer/bmsdefaultapphost_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_BMSAPPCONTROLHOST_FUZZER_H +#define TEST_FUZZTEST_BMSAPPCONTROLHOST_FUZZER_H + +#define FUZZ_PROJECT_NAME "bmsdefaultapphost_fuzzer" + +#endif \ No newline at end of file diff --git a/test/fuzztest/fuzztest_bundlemanager/bmsdefaultapphost_fuzzer/corpus/init b/test/fuzztest/fuzztest_bundlemanager/bmsdefaultapphost_fuzzer/corpus/init new file mode 100644 index 0000000000000000000000000000000000000000..e4ceac1bcd4e3b3427eb63cea0c28304064333cc --- /dev/null +++ b/test/fuzztest/fuzztest_bundlemanager/bmsdefaultapphost_fuzzer/corpus/init @@ -0,0 +1,14 @@ +# Copyright (c) 2023 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +FUZZ \ No newline at end of file diff --git a/test/fuzztest/fuzztest_bundlemanager/bmsdefaultapphost_fuzzer/project.xml b/test/fuzztest/fuzztest_bundlemanager/bmsdefaultapphost_fuzzer/project.xml new file mode 100644 index 0000000000000000000000000000000000000000..4fdbc407f205680885fa42663163b5c987f123a6 --- /dev/null +++ b/test/fuzztest/fuzztest_bundlemanager/bmsdefaultapphost_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/test/fuzztest/fuzztest_bundlemanager/bmsdeleteappinstallcontrolrule_fuzzer/BUILD.gn b/test/fuzztest/fuzztest_bundlemanager/bmsdeleteappinstallcontrolrule_fuzzer/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..3ab9dbb4bd8ef8fe8e15294ba6a5db52aa266017 --- /dev/null +++ b/test/fuzztest/fuzztest_bundlemanager/bmsdeleteappinstallcontrolrule_fuzzer/BUILD.gn @@ -0,0 +1,43 @@ +# Copyright (c) 2022-2023 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") +module_output_path = fuzz_test_path + +##############################fuzztest########################################## +ohos_fuzztest("BMSDeleteAppInstallControlRuleFuzzTest") { + module_out_path = module_output_path + fuzz_config_file = "../../../fuzztest/fuzztest_bundlemanager/bmsdeleteappinstallcontrolrule_fuzzer" + + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + sources = [ "bmsdeleteappinstallcontrolrule_fuzzer.cpp" ] + + deps = [ + "${base_path}:appexecfwk_base", + "${common_path}:libappexecfwk_common", + "${core_path}:appexecfwk_core", + ] + external_deps = [ + "c_utils:utils", + "ipc:ipc_core", + ] +} diff --git a/test/fuzztest/fuzztest_bundlemanager/bmsdeleteappinstallcontrolrule_fuzzer/bmsdeleteappinstallcontrolrule_fuzzer.cpp b/test/fuzztest/fuzztest_bundlemanager/bmsdeleteappinstallcontrolrule_fuzzer/bmsdeleteappinstallcontrolrule_fuzzer.cpp new file mode 100644 index 0000000000000000000000000000000000000000..ea2c1ec3df24973a6f1f82105a540f2193d73945 --- /dev/null +++ b/test/fuzztest/fuzztest_bundlemanager/bmsdeleteappinstallcontrolrule_fuzzer/bmsdeleteappinstallcontrolrule_fuzzer.cpp @@ -0,0 +1,50 @@ +/* + * 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 "app_control_proxy.h" + +#include "bmsdeleteappinstallcontrolrule_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) + { + sptr object; + AppControlProxy appControl(object); + + FuzzedDataProvider fdp(data, size); + AppInstallControlRuleType controlRuleType = + static_cast(fdp.ConsumeIntegralInRange(0, 3)); + std::vector appIds = GenerateStringArray(fdp); + int32_t userId = fdp.ConsumeIntegral(); + appControl.DeleteAppInstallControlRule(controlRuleType, appIds, userId); + appControl.DeleteAppInstallControlRule(controlRuleType, userId); + 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/bmsdeleteappinstallcontrolrule_fuzzer/bmsdeleteappinstallcontrolrule_fuzzer.h b/test/fuzztest/fuzztest_bundlemanager/bmsdeleteappinstallcontrolrule_fuzzer/bmsdeleteappinstallcontrolrule_fuzzer.h new file mode 100644 index 0000000000000000000000000000000000000000..0f3a1f547ed41ee4a6af86c7f5bb7af2a1db9bb8 --- /dev/null +++ b/test/fuzztest/fuzztest_bundlemanager/bmsdeleteappinstallcontrolrule_fuzzer/bmsdeleteappinstallcontrolrule_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_BMSDELETESPPINSTALLCONTROLRULE_FUZZER_H +#define TEST_FUZZTEST_BMSDELETESPPINSTALLCONTROLRULE_FUZZER_H + +#define FUZZ_PROJECT_NAME "bmsdeleteappinstallcontrolrule_fuzzer" + +#endif \ No newline at end of file diff --git a/test/fuzztest/fuzztest_bundlemanager/bmsdeleteappinstallcontrolrule_fuzzer/corpus/init b/test/fuzztest/fuzztest_bundlemanager/bmsdeleteappinstallcontrolrule_fuzzer/corpus/init new file mode 100644 index 0000000000000000000000000000000000000000..bc977bd9738ee9a70b362067f57a9c63d3adb801 --- /dev/null +++ b/test/fuzztest/fuzztest_bundlemanager/bmsdeleteappinstallcontrolrule_fuzzer/corpus/init @@ -0,0 +1,14 @@ +# Copyright (c) 2022 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +FUZZ \ No newline at end of file diff --git a/test/fuzztest/fuzztest_bundlemanager/bmsdeleteappinstallcontrolrule_fuzzer/project.xml b/test/fuzztest/fuzztest_bundlemanager/bmsdeleteappinstallcontrolrule_fuzzer/project.xml new file mode 100644 index 0000000000000000000000000000000000000000..6e8ad2cfde8f8bda4beb6cabbe7efd8bc3c54eec --- /dev/null +++ b/test/fuzztest/fuzztest_bundlemanager/bmsdeleteappinstallcontrolrule_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/test/fuzztest/fuzztest_bundlemanager/bmsdeleteapprunningcontrolrule_fuzzer/BUILD.gn b/test/fuzztest/fuzztest_bundlemanager/bmsdeleteapprunningcontrolrule_fuzzer/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..66eeece9ef68a58d42afd77ae550d9cb49738090 --- /dev/null +++ b/test/fuzztest/fuzztest_bundlemanager/bmsdeleteapprunningcontrolrule_fuzzer/BUILD.gn @@ -0,0 +1,43 @@ +# Copyright (c) 2022-2023 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") +module_output_path = fuzz_test_path + +##############################fuzztest########################################## +ohos_fuzztest("BMSDeleteAppRunningControlRuleFuzzTest") { + module_out_path = module_output_path + fuzz_config_file = "../../../fuzztest/fuzztest_bundlemanager/bmsdeleteapprunningcontrolrule_fuzzer" + + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + sources = [ "bmsdeleteapprunningcontrolrule_fuzzer.cpp" ] + + deps = [ + "${base_path}:appexecfwk_base", + "${common_path}:libappexecfwk_common", + "${core_path}:appexecfwk_core", + ] + external_deps = [ + "c_utils:utils", + "ipc:ipc_core", + ] +} diff --git a/test/fuzztest/fuzztest_bundlemanager/bmsdeleteapprunningcontrolrule_fuzzer/bmsdeleteapprunningcontrolrule_fuzzer.cpp b/test/fuzztest/fuzztest_bundlemanager/bmsdeleteapprunningcontrolrule_fuzzer/bmsdeleteapprunningcontrolrule_fuzzer.cpp new file mode 100644 index 0000000000000000000000000000000000000000..1d07ad9008161c1a09dad481cef7854f9686426f --- /dev/null +++ b/test/fuzztest/fuzztest_bundlemanager/bmsdeleteapprunningcontrolrule_fuzzer/bmsdeleteapprunningcontrolrule_fuzzer.cpp @@ -0,0 +1,63 @@ +/* + * 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 "app_control_proxy.h" + +#include "bmsdeleteapprunningcontrolrule_fuzzer.h" +#include "../../bms_fuzztest_util.h" + +using namespace OHOS::AppExecFwk; +using namespace OHOS::AppExecFwk::BMSFuzzTestUtil; +namespace { +void GetRandomAppRunningControlRule(FuzzedDataProvider& fdp, AppRunningControlRule& appRunningControlRule) +{ + appRunningControlRule.appId = fdp.ConsumeRandomLengthString(BMSFuzzTestUtil::STRING_MAX_LENGTH); + appRunningControlRule.controlMessage = fdp.ConsumeRandomLengthString(BMSFuzzTestUtil::STRING_MAX_LENGTH); +} +} +namespace OHOS { + bool DoSomethingInterestingWithMyAPI(const uint8_t* data, size_t size) + { + sptr object; + AppControlProxy appControl(object); + std::vector controlRule; + FuzzedDataProvider fdp(data, size); + size_t arraySize = fdp.ConsumeIntegralInRange(0, ARRAY_MAX_LENGTH); + controlRule.reserve(arraySize); + + for (size_t i = 0; i < arraySize; ++i) { + AppRunningControlRule rule; + GetRandomAppRunningControlRule(fdp, rule); + controlRule.emplace_back(rule); + } + int32_t userId = fdp.ConsumeIntegral(); + + appControl.DeleteAppRunningControlRule(controlRule, userId); + appControl.DeleteAppRunningControlRule(userId); + 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/bmsdeleteapprunningcontrolrule_fuzzer/bmsdeleteapprunningcontrolrule_fuzzer.h b/test/fuzztest/fuzztest_bundlemanager/bmsdeleteapprunningcontrolrule_fuzzer/bmsdeleteapprunningcontrolrule_fuzzer.h new file mode 100644 index 0000000000000000000000000000000000000000..e6443a8141964cd9401b27225e9b449373caae8a --- /dev/null +++ b/test/fuzztest/fuzztest_bundlemanager/bmsdeleteapprunningcontrolrule_fuzzer/bmsdeleteapprunningcontrolrule_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_BMSDELETEAPPRUNNINGCONTROLRULE_FUZZER_H +#define TEST_FUZZTEST_BMSDELETEAPPRUNNINGCONTROLRULE_FUZZER_H + +#define FUZZ_PROJECT_NAME "bmsdeleteapprunningcontrolrule_fuzzer" + +#endif \ No newline at end of file diff --git a/test/fuzztest/fuzztest_bundlemanager/bmsdeleteapprunningcontrolrule_fuzzer/corpus/init b/test/fuzztest/fuzztest_bundlemanager/bmsdeleteapprunningcontrolrule_fuzzer/corpus/init new file mode 100644 index 0000000000000000000000000000000000000000..bc977bd9738ee9a70b362067f57a9c63d3adb801 --- /dev/null +++ b/test/fuzztest/fuzztest_bundlemanager/bmsdeleteapprunningcontrolrule_fuzzer/corpus/init @@ -0,0 +1,14 @@ +# Copyright (c) 2022 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +FUZZ \ No newline at end of file diff --git a/test/fuzztest/fuzztest_bundlemanager/bmsdeleteapprunningcontrolrule_fuzzer/project.xml b/test/fuzztest/fuzztest_bundlemanager/bmsdeleteapprunningcontrolrule_fuzzer/project.xml new file mode 100644 index 0000000000000000000000000000000000000000..6e8ad2cfde8f8bda4beb6cabbe7efd8bc3c54eec --- /dev/null +++ b/test/fuzztest/fuzztest_bundlemanager/bmsdeleteapprunningcontrolrule_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/test/fuzztest/fuzztest_bundlemanager/bmsverifymanagerhost_fuzzer/BUILD.gn b/test/fuzztest/fuzztest_bundlemanager/bmsverifymanagerhost_fuzzer/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..0dbff1c7ae07cbcc96e687340b2af43934813843 --- /dev/null +++ b/test/fuzztest/fuzztest_bundlemanager/bmsverifymanagerhost_fuzzer/BUILD.gn @@ -0,0 +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. + +#####################hydra-fuzz################### +import("//build/config/features.gni") +import("//build/ohos.gni") +import("//build/test.gni") +import("../../../../appexecfwk.gni") +module_output_path = fuzz_test_path + +##############################fuzztest########################################## +ohos_fuzztest("BMSVerifyManagerHostFuzzTest") { + module_out_path = module_output_path + fuzz_config_file = + "../../../fuzztest/fuzztest_bundlemanager/bmsverifymanagerhost_fuzzer" + + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + sources = [ "bmsverifymanagerhost_fuzzer.cpp" ] + + deps = [ + "${base_path}:appexecfwk_base", + "${common_path}:libappexecfwk_common", + "${core_path}:appexecfwk_core", + ] + external_deps = [ + "ability_base:want", + "c_utils:utils", + "ipc:ipc_core", + ] +} diff --git a/test/fuzztest/fuzztest_bundlemanager/bmsverifymanagerhost_fuzzer/bmsverifymanagerhost_fuzzer.cpp b/test/fuzztest/fuzztest_bundlemanager/bmsverifymanagerhost_fuzzer/bmsverifymanagerhost_fuzzer.cpp new file mode 100644 index 0000000000000000000000000000000000000000..6f8cbe29ed951e37d5c2434b5ad4740bffe64a09 --- /dev/null +++ b/test/fuzztest/fuzztest_bundlemanager/bmsverifymanagerhost_fuzzer/bmsverifymanagerhost_fuzzer.cpp @@ -0,0 +1,53 @@ +/* + * 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 "bmsverifymanagerhost_fuzzer.h" + +#include +#include +#include + +#include "verify_manager_host.h" +#include "securec.h" +#include "../../bms_fuzztest_util.h" + +using namespace OHOS::AppExecFwk; +using namespace OHOS::AppExecFwk::BMSFuzzTestUtil; +namespace OHOS { +constexpr size_t MESSAGE_SIZE = 3; + +bool DoSomethingInterestingWithMyAPI(const uint8_t* data, size_t size) +{ + FuzzedDataProvider fdp(data, size); + uint32_t code = fdp.ConsumeIntegralInRange(0, MESSAGE_SIZE); + MessageParcel datas; + std::u16string descriptor = VerifyManagerHost::GetDescriptor(); + datas.WriteInterfaceToken(descriptor); + datas.WriteBuffer(data, size); + datas.RewindRead(0); + MessageParcel reply; + MessageOption option; + VerifyManagerHost verifyManagerHost; + verifyManagerHost.OnRemoteRequest(code, datas, reply, option); + return true; +} +} + +// Fuzzer entry point. +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + OHOS::DoSomethingInterestingWithMyAPI(data, size); + return 0; +} \ No newline at end of file diff --git a/test/fuzztest/fuzztest_bundlemanager/bmsverifymanagerhost_fuzzer/bmsverifymanagerhost_fuzzer.h b/test/fuzztest/fuzztest_bundlemanager/bmsverifymanagerhost_fuzzer/bmsverifymanagerhost_fuzzer.h new file mode 100644 index 0000000000000000000000000000000000000000..c4e3e33374e7204cd77a8d3da066ca76f84deefa --- /dev/null +++ b/test/fuzztest/fuzztest_bundlemanager/bmsverifymanagerhost_fuzzer/bmsverifymanagerhost_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_BMSVERIFYMANAGERHOST_FUZZER_H +#define TEST_FUZZTEST_BMSVERIFYMANAGERHOST_FUZZER_H + +#define FUZZ_PROJECT_NAME "bmsverifymanagerhost_fuzzer" + +#endif \ No newline at end of file diff --git a/test/fuzztest/fuzztest_bundlemanager/bmsverifymanagerhost_fuzzer/corpus/init b/test/fuzztest/fuzztest_bundlemanager/bmsverifymanagerhost_fuzzer/corpus/init new file mode 100644 index 0000000000000000000000000000000000000000..e7c3fecd8d4d4816e40088113a2316bb9eb2e13f --- /dev/null +++ b/test/fuzztest/fuzztest_bundlemanager/bmsverifymanagerhost_fuzzer/corpus/init @@ -0,0 +1,14 @@ +# Copyright (c) 2024 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +FUZZ \ No newline at end of file diff --git a/test/fuzztest/fuzztest_bundlemanager/bmsverifymanagerhost_fuzzer/project.xml b/test/fuzztest/fuzztest_bundlemanager/bmsverifymanagerhost_fuzzer/project.xml new file mode 100644 index 0000000000000000000000000000000000000000..7133b2b92440904a5ed04b838733acea0f97486a --- /dev/null +++ b/test/fuzztest/fuzztest_bundlemanager/bmsverifymanagerhost_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + +