From bbded9719b5afe35c27cf2af3c3d76052cb0eafb Mon Sep 17 00:00:00 2001 From: zhangzezhong Date: Mon, 5 Jan 2026 17:27:52 +0800 Subject: [PATCH] add fuzz test Signed-off-by: zhangzezhong --- test/fuzztest/BUILD.gn | 5 +- test/fuzztest/ability_fuzz_util.h | 178 +++++++++++++++++- .../abilitykeepalivedatamanager_fuzzer.cpp | 1 + .../abilitykeepaliveinfo_fuzzer/BUILD.gn | 71 +++++++ .../abilitykeepaliveinfo_fuzzer.cpp | 48 +++++ .../abilitykeepaliveinfo_fuzzer.h | 21 +++ .../abilitykeepaliveinfo_fuzzer/corpus/init | 16 ++ .../abilitykeepaliveinfo_fuzzer/project.xml | 25 +++ test/fuzztest/keepaliveutils_fuzzer/BUILD.gn | 113 +++++++++++ .../keepaliveutils_fuzzer/corpus/init | 16 ++ .../keepaliveutils_fuzzer.cpp | 49 +++++ .../keepaliveutils_fuzzer.h | 21 +++ .../keepaliveutils_fuzzer/project.xml | 25 +++ .../modalsystemdialogutil_fuzzer/BUILD.gn | 96 ++++++++++ .../modalsystemdialogutil_fuzzer/corpus/init | 16 ++ .../modalsystemdialogutil_fuzzer.cpp | 54 ++++++ .../modalsystemdialogutil_fuzzer.h | 21 +++ .../modalsystemdialogutil_fuzzer/project.xml | 25 +++ 18 files changed, 799 insertions(+), 2 deletions(-) create mode 100644 test/fuzztest/abilitykeepaliveinfo_fuzzer/BUILD.gn create mode 100644 test/fuzztest/abilitykeepaliveinfo_fuzzer/abilitykeepaliveinfo_fuzzer.cpp create mode 100644 test/fuzztest/abilitykeepaliveinfo_fuzzer/abilitykeepaliveinfo_fuzzer.h create mode 100644 test/fuzztest/abilitykeepaliveinfo_fuzzer/corpus/init create mode 100644 test/fuzztest/abilitykeepaliveinfo_fuzzer/project.xml create mode 100644 test/fuzztest/keepaliveutils_fuzzer/BUILD.gn create mode 100644 test/fuzztest/keepaliveutils_fuzzer/corpus/init create mode 100644 test/fuzztest/keepaliveutils_fuzzer/keepaliveutils_fuzzer.cpp create mode 100644 test/fuzztest/keepaliveutils_fuzzer/keepaliveutils_fuzzer.h create mode 100644 test/fuzztest/keepaliveutils_fuzzer/project.xml create mode 100644 test/fuzztest/modalsystemdialogutil_fuzzer/BUILD.gn create mode 100644 test/fuzztest/modalsystemdialogutil_fuzzer/corpus/init create mode 100644 test/fuzztest/modalsystemdialogutil_fuzzer/modalsystemdialogutil_fuzzer.cpp create mode 100644 test/fuzztest/modalsystemdialogutil_fuzzer/modalsystemdialogutil_fuzzer.h create mode 100644 test/fuzztest/modalsystemdialogutil_fuzzer/project.xml diff --git a/test/fuzztest/BUILD.gn b/test/fuzztest/BUILD.gn index b14bbe8e2b..757e6843e4 100644 --- a/test/fuzztest/BUILD.gn +++ b/test/fuzztest/BUILD.gn @@ -1,4 +1,4 @@ -# Copyright (c) 2022-2025 Huawei Device Co., Ltd. +# Copyright (c) 2022-2026 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 @@ -99,6 +99,7 @@ group("fuzztest") { "abilityinterfacesappmgrnativechildnotifystub_fuzzer:fuzztest", "abilityinterfacesappmgrrenderstateobserverstub_fuzzer:fuzztest", "abilitykeepalivedatamanager_fuzzer:fuzztest", + "abilitykeepaliveinfo_fuzzer:fuzztest", "abilitykeepaliveservice_fuzzer:fuzztest", "abilitymanagerradar_fuzzer:fuzztest", "abilitymanagerserviceb_fuzzer:fuzztest", @@ -431,6 +432,7 @@ group("fuzztest") { "keepaliveprocessmanagertwelfth_fuzzer:fuzztest", "keepaliveprocessmanagertwentyth_fuzzer:fuzztest", "keepaliveprocessmanagertwentyoneth_fuzzer:fuzztest", + "keepaliveutils_fuzzer:fuzztest", "killapplication_fuzzer:fuzztest", "killapplicationself_fuzzer:fuzztest", "killprocessbyabilitytoken_fuzzer:fuzztest", @@ -456,6 +458,7 @@ group("fuzztest") { "missionlistmanagersecond_fuzzer:fuzztest", "missionlistmanagerthird_fuzzer:fuzztest", "missionsnapshot_fuzzer:fuzztest", + "modalsystemdialogutil_fuzzer:fuzztest", "modulerunningrecord_fuzzer:fuzztest", "multiinstanceutils_fuzzer:fuzztest", "multiuserconfigmgr_fuzzer:fuzztest", diff --git a/test/fuzztest/ability_fuzz_util.h b/test/fuzztest/ability_fuzz_util.h index af8f3070cf..4656af19e7 100644 --- a/test/fuzztest/ability_fuzz_util.h +++ b/test/fuzztest/ability_fuzz_util.h @@ -1,5 +1,5 @@ /* -* Copyright (c) 2025 Huawei Device Co., Ltd. +* Copyright (c) 2025-2026 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 @@ -38,8 +38,13 @@ namespace OHOS { namespace AppExecFwk { namespace AbilityFuzzUtil { constexpr size_t CODE_TWO = 2; +constexpr size_t CODE_FOUR = 4; +constexpr size_t CODE_TEN = 10; constexpr size_t CODE_MAX = 99; constexpr size_t STRING_MAX_LENGTH = 128; +constexpr uint32_t CODE_MIN_ONE = 1; +constexpr uint32_t CODE_MAX_THREE = 3; + std::vector GenerateStringArray(FuzzedDataProvider& fdp, size_t arraySizeMax = STRING_MAX_LENGTH, size_t stringSize = STRING_MAX_LENGTH) { @@ -508,6 +513,177 @@ void GetRandomStartOptions(FuzzedDataProvider& fdp, StartOptions& startOptions) startOptions.SetMaxWindowWidth(fdp.ConsumeIntegral()); startOptions.SetMaxWindowHeight(fdp.ConsumeIntegral()); } + +void GenerateBundleInfo(FuzzedDataProvider& fdp, AppExecFwk::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(CODE_MIN_ONE, CODE_MAX_THREE); + 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); + bundleInfo.moduleNames = GenerateStringArray(fdp); + bundleInfo.modulePublicDirs = GenerateStringArray(fdp); + bundleInfo.moduleDirs = GenerateStringArray(fdp); + bundleInfo.moduleResPaths = GenerateStringArray(fdp); + + bundleInfo.reqPermissions = GenerateStringArray(fdp); + bundleInfo.defPermissions = GenerateStringArray(fdp); +} + +std::vector GenerateBundleInfoArray(FuzzedDataProvider& fdp, size_t arraySizeMax = CODE_TEN) +{ + std::vector result; + size_t arraySize = fdp.ConsumeIntegralInRange(0, arraySizeMax); + result.reserve(arraySize); + + for (size_t i = 0; i < arraySize; ++i) { + AppExecFwk::BundleInfo bundleInfo; + GenerateBundleInfo(fdp, bundleInfo); + result.emplace_back(bundleInfo); + } + + return result; +} + +Resource GenerateResource(FuzzedDataProvider& fdp) +{ + Resource info; + info.id = fdp.ConsumeIntegral(); + info.bundleName = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH); + info.moduleName = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH); + return info; +} + +void GenerateApplicationInfo(FuzzedDataProvider& fdp, AppExecFwk::ApplicationInfo &applicationInfo) +{ + applicationInfo.keepAlive = fdp.ConsumeBool(); + applicationInfo.removable = fdp.ConsumeBool(); + applicationInfo.singleton = fdp.ConsumeBool(); + applicationInfo.userDataClearable = fdp.ConsumeBool(); + applicationInfo.allowAppRunWhenDeviceFirstLocked = fdp.ConsumeBool(); + applicationInfo.accessible = fdp.ConsumeBool(); + applicationInfo.runningResourcesApply = fdp.ConsumeBool(); + applicationInfo.associatedWakeUp = fdp.ConsumeBool(); + applicationInfo.hideDesktopIcon = fdp.ConsumeBool(); + applicationInfo.formVisibleNotify = fdp.ConsumeBool(); + applicationInfo.isSystemApp = fdp.ConsumeBool(); + applicationInfo.isLauncherApp = fdp.ConsumeBool(); + applicationInfo.isFreeInstallApp = fdp.ConsumeBool(); + applicationInfo.asanEnabled = fdp.ConsumeBool(); + applicationInfo.debug = fdp.ConsumeBool(); + applicationInfo.distributedNotificationEnabled = fdp.ConsumeBool(); + applicationInfo.installedForAllUser = fdp.ConsumeBool(); + applicationInfo.allowEnableNotification = fdp.ConsumeBool(); + applicationInfo.allowMultiProcess = fdp.ConsumeBool(); + applicationInfo.gwpAsanEnabled = fdp.ConsumeBool(); + applicationInfo.enabled = fdp.ConsumeBool(); + applicationInfo.hasPlugin = fdp.ConsumeBool(); + applicationInfo.multiProjects = fdp.ConsumeBool(); + applicationInfo.isCompressNativeLibs = fdp.ConsumeBool(); + applicationInfo.tsanEnabled = fdp.ConsumeBool(); + applicationInfo.hwasanEnabled = fdp.ConsumeBool(); + applicationInfo.ubsanEnabled = fdp.ConsumeBool(); + applicationInfo.cloudFileSyncEnabled = fdp.ConsumeBool(); + applicationInfo.cloudStructuredDataSyncEnabled = fdp.ConsumeBool(); + applicationInfo.needAppDetail = fdp.ConsumeBool(); + applicationInfo.versionCode = fdp.ConsumeIntegral(); + applicationInfo.apiCompatibleVersion = fdp.ConsumeIntegral(); + applicationInfo.iconId = fdp.ConsumeIntegral(); + applicationInfo.labelId = fdp.ConsumeIntegral(); + applicationInfo.descriptionId = fdp.ConsumeIntegral(); + applicationInfo.accessTokenId = fdp.ConsumeIntegral(); + applicationInfo.applicationReservedFlag = fdp.ConsumeIntegral(); + applicationInfo.apiTargetVersion = fdp.ConsumeIntegral(); + applicationInfo.minCompatibleVersionCode = fdp.ConsumeIntegral(); + applicationInfo.supportedModes = fdp.ConsumeIntegral(); + applicationInfo.appIndex = fdp.ConsumeIntegral(); + applicationInfo.uid = fdp.ConsumeIntegral(); + applicationInfo.flags = fdp.ConsumeIntegral(); + applicationInfo.targetPriority = fdp.ConsumeIntegral(); + applicationInfo.overlayState = fdp.ConsumeIntegral(); + applicationInfo.maxChildProcess = fdp.ConsumeIntegral(); + applicationInfo.applicationFlags = fdp.ConsumeIntegral(); + applicationInfo.bundleType = static_cast(fdp.ConsumeIntegralInRange(0, CODE_FOUR)); + applicationInfo.crowdtestDeadline = fdp.ConsumeIntegral(); + applicationInfo.accessTokenIdEx = fdp.ConsumeIntegral(); + applicationInfo.name = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH); + applicationInfo.bundleName = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH); + applicationInfo.versionName = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH); + applicationInfo.iconPath = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH); + applicationInfo.label = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH); + applicationInfo.description = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH); + applicationInfo.asanLogPath = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH); + applicationInfo.codePath = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH); + applicationInfo.dataDir = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH); + applicationInfo.dataBaseDir = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH); + applicationInfo.cacheDir = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH); + applicationInfo.entryDir = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH); + applicationInfo.apiReleaseType = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH); + applicationInfo.deviceId = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH); + applicationInfo.entityType = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH); + applicationInfo.process = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH); + applicationInfo.vendor = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH); + applicationInfo.appPrivilegeLevel = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH); + applicationInfo.appDistributionType = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH); + applicationInfo.appProvisionType = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH); + applicationInfo.nativeLibraryPath = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH); + applicationInfo.cpuAbi = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH); + applicationInfo.arkNativeFilePath = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH); + applicationInfo.arkNativeFileAbi = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH); + applicationInfo.fingerprint = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH); + applicationInfo.icon = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH); + applicationInfo.entryModuleName = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH); + applicationInfo.signatureKey = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH); + applicationInfo.targetBundleName = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH); + applicationInfo.compileSdkVersion = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH); + applicationInfo.compileSdkType = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH); + applicationInfo.organization = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH); + applicationInfo.appDetailAbilityLibraryPath = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH); + applicationInfo.installSource = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH); + applicationInfo.configuration = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH); + applicationInfo.iconResource = GenerateResource(fdp); + applicationInfo.labelResource = GenerateResource(fdp); + applicationInfo.descriptionResource = GenerateResource(fdp); + + applicationInfo.allowCommonEvent = GenerateStringArray(fdp); + applicationInfo.assetAccessGroups = GenerateStringArray(fdp); + + applicationInfo.permissions = GenerateStringArray(fdp); + applicationInfo.moduleSourceDirs = GenerateStringArray(fdp); + applicationInfo.targetBundleList = GenerateStringArray(fdp); +} } // namespace AbilityFuzzUtil } // namespace AppExecFwk } // namespace OHOS diff --git a/test/fuzztest/abilitykeepalivedatamanager_fuzzer/abilitykeepalivedatamanager_fuzzer.cpp b/test/fuzztest/abilitykeepalivedatamanager_fuzzer/abilitykeepalivedatamanager_fuzzer.cpp index 4c5aeadb5e..d0ccf515dc 100644 --- a/test/fuzztest/abilitykeepalivedatamanager_fuzzer/abilitykeepalivedatamanager_fuzzer.cpp +++ b/test/fuzztest/abilitykeepalivedatamanager_fuzzer/abilitykeepalivedatamanager_fuzzer.cpp @@ -59,6 +59,7 @@ bool DoSomethingInterestingWithMyAPI(const uint8_t* data, size_t size) AbilityKeepAliveDataManager::GetInstance().DeleteKeepAliveData(info); AbilityKeepAliveDataManager::GetInstance().DeleteKeepAliveDataWithSetterId(info); AbilityKeepAliveDataManager::GetInstance().ConvertKeepAliveStatusToValue(info); + AbilityKeepAliveDataManager::GetInstance().ConvertKeepAliveDataToKey(info); DistributedKv::Value value; AbilityFuzzUtil::GetRandomKeepAliveStatus(fdp, aliveStatus); AbilityKeepAliveDataManager::GetInstance().ConvertKeepAliveStatusFromValue(value, aliveStatus); diff --git a/test/fuzztest/abilitykeepaliveinfo_fuzzer/BUILD.gn b/test/fuzztest/abilitykeepaliveinfo_fuzzer/BUILD.gn new file mode 100644 index 0000000000..2450a3a74e --- /dev/null +++ b/test/fuzztest/abilitykeepaliveinfo_fuzzer/BUILD.gn @@ -0,0 +1,71 @@ +# Copyright (c) 2026 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/test.gni") +import("//foundation/ability/ability_runtime/ability_runtime.gni") +##############################fuzztest########################################## +module_output_path = "ability_runtime/appmgrservice" +ohos_fuzztest("AbilityKeepAliveInfoFuzzTest") { + module_out_path = module_output_path + fuzz_config_file = + "${ability_runtime_test_path}/fuzztest/abilitykeepaliveinfo_fuzzer" + include_dirs = [ + "${ability_runtime_services_path}/abilitymgr/include/utils", + "${ability_runtime_services_path}/abilitymgr/include/keep_alive", + "${ability_runtime_services_path}/abilitymgr/include", + ] + + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + + sources = [ + "${ability_runtime_services_path}/abilitymgr/src/keep_alive/keep_alive_info.cpp", + "abilitykeepaliveinfo_fuzzer.cpp", + ] + + deps = [ + "${ability_runtime_innerkits_path}/app_manager:app_manager", + "${ability_runtime_services_path}/appmgr:libappms", + "${ability_runtime_services_path}/common:task_handler_wrap", + ] + + external_deps = [ + "ability_base:want", + "appspawn:appspawn_client", + "bundle_framework:appexecfwk_base", + "bundle_framework:appexecfwk_core", + "c_utils:utils", + "ffrt:libffrt", + "hilog:libhilog", + "init:libbegetutil", + "ipc:ipc_core", + "samgr:samgr_proxy", + "window_manager:libwm", + ] +} + +############################################################################### +group("fuzztest") { + testonly = true + deps = [] + deps += [ + # deps file + ":AbilityKeepAliveInfoFuzzTest", + ] +} +############################################################################### diff --git a/test/fuzztest/abilitykeepaliveinfo_fuzzer/abilitykeepaliveinfo_fuzzer.cpp b/test/fuzztest/abilitykeepaliveinfo_fuzzer/abilitykeepaliveinfo_fuzzer.cpp new file mode 100644 index 0000000000..a13ce6ccb8 --- /dev/null +++ b/test/fuzztest/abilitykeepaliveinfo_fuzzer/abilitykeepaliveinfo_fuzzer.cpp @@ -0,0 +1,48 @@ +/* + * Copyright (c) 2026 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 "abilitykeepaliveinfo_fuzzer.h" + +#include +#include +#include + +#include "keep_alive_info.h" +#include "securec.h" + +using namespace OHOS::AbilityRuntime; + +namespace OHOS { +bool DoSomethingInterestingWithMyAPI(FuzzedDataProvider *fdp) +{ + KeepAliveInfo info; + Parcel parcel; + parcel.WriteString(fdp->ConsumeRandomLengthString()); + info.ReadFromParcel(parcel); + info.Unmarshalling(parcel); + info.Marshalling(parcel); + return true; +} +} + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data */ + FuzzedDataProvider fdp(data, size); + OHOS::DoSomethingInterestingWithMyAPI(&fdp); + return 0; +} + diff --git a/test/fuzztest/abilitykeepaliveinfo_fuzzer/abilitykeepaliveinfo_fuzzer.h b/test/fuzztest/abilitykeepaliveinfo_fuzzer/abilitykeepaliveinfo_fuzzer.h new file mode 100644 index 0000000000..c4f657419b --- /dev/null +++ b/test/fuzztest/abilitykeepaliveinfo_fuzzer/abilitykeepaliveinfo_fuzzer.h @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2026 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 FUZZTEST_OHOS_ABILITY_RUNTIME_ABILITYKEEPALIVEINFO_FUZZER_H +#define FUZZTEST_OHOS_ABILITY_RUNTIME_ABILITYKEEPALIVEINFO_FUZZER_H + +#define FUZZ_PROJECT_NAME "abilitykeepaliveinfo_fuzzer" + +#endif // FUZZTEST_OHOS_ABILITY_RUNTIME_ABILITYKEEPALIVEINFO_FUZZER_H \ No newline at end of file diff --git a/test/fuzztest/abilitykeepaliveinfo_fuzzer/corpus/init b/test/fuzztest/abilitykeepaliveinfo_fuzzer/corpus/init new file mode 100644 index 0000000000..7755254dd4 --- /dev/null +++ b/test/fuzztest/abilitykeepaliveinfo_fuzzer/corpus/init @@ -0,0 +1,16 @@ +/* + * Copyright (c) 2026 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/abilitykeepaliveinfo_fuzzer/project.xml b/test/fuzztest/abilitykeepaliveinfo_fuzzer/project.xml new file mode 100644 index 0000000000..d3de054d36 --- /dev/null +++ b/test/fuzztest/abilitykeepaliveinfo_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/test/fuzztest/keepaliveutils_fuzzer/BUILD.gn b/test/fuzztest/keepaliveutils_fuzzer/BUILD.gn new file mode 100644 index 0000000000..d0ddb7d9a9 --- /dev/null +++ b/test/fuzztest/keepaliveutils_fuzzer/BUILD.gn @@ -0,0 +1,113 @@ +# Copyright (c) 2026 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("//foundation/ability/ability_runtime/ability_runtime.gni") +module_output_path = "ability_runtime/abilitymgr" + +##############################fuzztest########################################## +ohos_fuzztest("KeepAliveUtilsFuzzTest") { + module_out_path = module_output_path + + fuzz_config_file = + "${ability_runtime_test_path}/fuzztest/keepaliveutils_fuzzer" + include_dirs = [ + "${ability_runtime_services_path}/abilitymgr/include/utils", + "${ability_runtime_test_path}/fuzztest/", + ] + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + sources = [ + "${ability_runtime_innerkits_path}/app_manager/src/appmgr/app_mgr_client.cpp", + "${ability_runtime_innerkits_path}/app_manager/src/appmgr/app_service_manager.cpp", + "${ability_runtime_native_path}/appkit/ability_bundle_manager_helper/bundle_mgr_helper.cpp", + "${ability_runtime_services_path}/abilitymgr/src/keep_alive/ability_keep_alive_data_manager.cpp", + "${ability_runtime_services_path}/abilitymgr/src/keep_alive/ability_keep_alive_service.cpp", + "${ability_runtime_services_path}/abilitymgr/src/keep_alive/keep_alive_info.cpp", + "${ability_runtime_services_path}/abilitymgr/src/keep_alive/keep_alive_process_manager.cpp", + "${ability_runtime_services_path}/abilitymgr/src/process_options.cpp", + "${ability_runtime_services_path}/abilitymgr/src/rdb/ability_resident_process_rdb.cpp", + "${ability_runtime_services_path}/abilitymgr/src/rdb/parser_util.cpp", + "${ability_runtime_services_path}/abilitymgr/src/rdb/rdb_data_manager.cpp", + "${ability_runtime_services_path}/abilitymgr/src/utils/keep_alive_utils.cpp", + "${ability_runtime_services_path}/common/src/app_utils.cpp", + "${ability_runtime_services_path}/common/src/json_utils.cpp", + "${ability_runtime_services_path}/common/src/permission_verification.cpp", + "${ability_runtime_services_path}/common/src/record_cost_time_util.cpp", + "keepaliveutils_fuzzer.cpp", + ] + + configs = [ + "${ability_runtime_innerkits_path}/ability_manager:ability_manager_public_config", + "${ability_runtime_services_path}/abilitymgr:abilityms_config", + ] + + deps = [ + "${ability_runtime_innerkits_path}/ability_manager:ability_manager", + "${ability_runtime_innerkits_path}/ability_manager:mission_info", + "${ability_runtime_native_path}/ability/native:abilitykit_native", + "${ability_runtime_path}/utils/server/startup:startup_util", + "${ability_runtime_services_path}/abilitymgr:abilityms", + "${ability_runtime_services_path}/common:app_util", + "${ability_runtime_services_path}/common:user_controller", + ] + + external_deps = [ + "ability_base:base", + "ability_base:want", + "access_token:libaccesstoken_sdk", + "access_token:libtokenid_sdk", + "background_task_mgr:bgtaskmgr_innerkits", + "bundle_framework:appexecfwk_base", + "bundle_framework:appexecfwk_core", + "c_utils:utils", + "common_event_service:cesfwk_core", + "common_event_service:cesfwk_innerkits", + "config_policy:configpolicy_util", + "eventhandler:libeventhandler", + "ffrt:libffrt", + "hilog:libhilog", + "hisysevent:libhisysevent", + "hitrace:hitrace_meter", + "init:libbeget_proxy", + "input:libmmi-client", + "ipc:ipc_core", + "kv_store:distributeddata_inner", + "napi:ace_napi", + "relational_store:native_dataability", + "relational_store:native_rdb", + "safwk:system_ability_fwk", + "samgr:samgr_proxy", + "window_manager:libwsutils", + "window_manager:scene_session", + "window_manager:session_manager_lite", + ] +} + +############################################################################### +group("fuzztest") { + testonly = true + deps = [] + deps += [ + # deps file + ":KeepAliveUtilsFuzzTest", + ] +} +############################################################################### diff --git a/test/fuzztest/keepaliveutils_fuzzer/corpus/init b/test/fuzztest/keepaliveutils_fuzzer/corpus/init new file mode 100644 index 0000000000..7755254dd4 --- /dev/null +++ b/test/fuzztest/keepaliveutils_fuzzer/corpus/init @@ -0,0 +1,16 @@ +/* + * Copyright (c) 2026 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/keepaliveutils_fuzzer/keepaliveutils_fuzzer.cpp b/test/fuzztest/keepaliveutils_fuzzer/keepaliveutils_fuzzer.cpp new file mode 100644 index 0000000000..d1a133ba63 --- /dev/null +++ b/test/fuzztest/keepaliveutils_fuzzer/keepaliveutils_fuzzer.cpp @@ -0,0 +1,49 @@ +/* + * Copyright (c) 2026 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 "keepaliveutils_fuzzer.h" + +#include +#include +#include + +#include "keep_alive_utils.h" +#include "ability_fuzz_util.h" + +using namespace OHOS::AAFwk; +using namespace OHOS::AppExecFwk; + +namespace OHOS { +bool DoSomethingInterestingWithMyAPI(const uint8_t* data, size_t size) +{ + FuzzedDataProvider fdp(data, size); + std::vector bundleInfos = AbilityFuzzUtil::GenerateBundleInfoArray(fdp); + int32_t userId = fdp.ConsumeIntegral(); + KeepAliveUtils::NotifyDisableKeepAliveProcesses(bundleInfos, userId); + BundleInfo bundleInfo; + AbilityFuzzUtil::GenerateBundleInfo(fdp, bundleInfo); + KeepAliveType type; + KeepAliveUtils::IsKeepAliveBundle(bundleInfo, userId, type); + 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/keepaliveutils_fuzzer/keepaliveutils_fuzzer.h b/test/fuzztest/keepaliveutils_fuzzer/keepaliveutils_fuzzer.h new file mode 100644 index 0000000000..0dfd567c63 --- /dev/null +++ b/test/fuzztest/keepaliveutils_fuzzer/keepaliveutils_fuzzer.h @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2026 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 FUZZTEST_OHOS_ABILITY_RUNTIME_KEEPALIVEUTILS_FUZZER_H +#define FUZZTEST_OHOS_ABILITY_RUNTIME_KEEPALIVEUTILS_FUZZER_H + +#define FUZZ_PROJECT_NAME "keepaliveutils_fuzzer" + +#endif // FUZZTEST_OHOS_ABILITY_RUNTIME_KEEPALIVEUTILS_FUZZER_H \ No newline at end of file diff --git a/test/fuzztest/keepaliveutils_fuzzer/project.xml b/test/fuzztest/keepaliveutils_fuzzer/project.xml new file mode 100644 index 0000000000..1884a288e3 --- /dev/null +++ b/test/fuzztest/keepaliveutils_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + \ No newline at end of file diff --git a/test/fuzztest/modalsystemdialogutil_fuzzer/BUILD.gn b/test/fuzztest/modalsystemdialogutil_fuzzer/BUILD.gn new file mode 100644 index 0000000000..601eee0d60 --- /dev/null +++ b/test/fuzztest/modalsystemdialogutil_fuzzer/BUILD.gn @@ -0,0 +1,96 @@ +# Copyright (c) 2026 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("//foundation/ability/ability_runtime/ability_runtime.gni") +module_output_path = "ability_runtime/abilitymgr" + +##############################fuzztest########################################## +ohos_fuzztest("ModalSystemDialogUtilFuzzTest") { + module_out_path = module_output_path + + fuzz_config_file = + "${ability_runtime_test_path}/fuzztest/modalsystemdialogutil_fuzzer" + include_dirs = [ + "${ability_runtime_services_path}/abilitymgr/include/utils", + "${ability_runtime_test_path}/fuzztest/", + ] + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + sources = [ + "${ability_runtime_native_path}/appkit/ability_bundle_manager_helper/bundle_mgr_helper.cpp", + "${ability_runtime_services_path}/abilitymgr/src/modal_system_dialog/modal_system_dialog_ui_extension.cpp", + "${ability_runtime_services_path}/abilitymgr/src/utils/modal_system_dialog_util.cpp", + "modalsystemdialogutil_fuzzer.cpp", + ] + + deps = [ + "${ability_runtime_innerkits_path}/ability_manager:ability_connect_callback_stub", + "${ability_runtime_innerkits_path}/ability_manager:ability_manager", + "${ability_runtime_native_path}/ability/native:abilitykit_native", + "${ability_runtime_native_path}/appkit:appkit_manager_helper", + "${ability_runtime_path}/utils/server/startup:startup_util", + "${ability_runtime_services_path}/abilitymgr:abilityms", + "${ability_runtime_services_path}/common:app_util", + "${ability_runtime_services_path}/common:user_controller", + ] + + external_deps = [ + "ability_base:base", + "ability_base:want", + "access_token:libaccesstoken_sdk", + "access_token:libtokenid_sdk", + "background_task_mgr:bgtaskmgr_innerkits", + "bundle_framework:appexecfwk_base", + "bundle_framework:appexecfwk_core", + "c_utils:utils", + "common_event_service:cesfwk_core", + "common_event_service:cesfwk_innerkits", + "config_policy:configpolicy_util", + "eventhandler:libeventhandler", + "ffrt:libffrt", + "hilog:libhilog", + "hisysevent:libhisysevent", + "hitrace:hitrace_meter", + "init:libbeget_proxy", + "input:libmmi-client", + "ipc:ipc_core", + "kv_store:distributeddata_inner", + "napi:ace_napi", + "relational_store:native_dataability", + "relational_store:native_rdb", + "safwk:system_ability_fwk", + "samgr:samgr_proxy", + "window_manager:libwsutils", + "window_manager:scene_session", + "window_manager:session_manager_lite", + ] +} + +############################################################################### +group("fuzztest") { + testonly = true + deps = [] + deps += [ + # deps file + ":ModalSystemDialogUtilFuzzTest", + ] +} +############################################################################### diff --git a/test/fuzztest/modalsystemdialogutil_fuzzer/corpus/init b/test/fuzztest/modalsystemdialogutil_fuzzer/corpus/init new file mode 100644 index 0000000000..7755254dd4 --- /dev/null +++ b/test/fuzztest/modalsystemdialogutil_fuzzer/corpus/init @@ -0,0 +1,16 @@ +/* + * Copyright (c) 2026 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/modalsystemdialogutil_fuzzer/modalsystemdialogutil_fuzzer.cpp b/test/fuzztest/modalsystemdialogutil_fuzzer/modalsystemdialogutil_fuzzer.cpp new file mode 100644 index 0000000000..b65cd48e48 --- /dev/null +++ b/test/fuzztest/modalsystemdialogutil_fuzzer/modalsystemdialogutil_fuzzer.cpp @@ -0,0 +1,54 @@ +/* + * Copyright (c) 2026 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 "modalsystemdialogutil_fuzzer.h" + +#include +#include +#include + +#include "modal_system_dialog_util.h" +#include "ability_fuzz_util.h" + +using namespace OHOS::AAFwk; +using namespace OHOS::AppExecFwk; + +namespace OHOS { +namespace { +constexpr size_t STRING_MAX_LENGTH = 128; +} + +bool DoSomethingInterestingWithMyAPI(const uint8_t* data, size_t size) +{ + FuzzedDataProvider fdp(data, size); + ApplicationInfo applicationInfo; + AbilityFuzzUtil::GenerateApplicationInfo(fdp, applicationInfo); + ModalSystemDialogUtil::CheckDebugAppNotInDeveloperMode(applicationInfo); + std::string bundleName = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH); + std::string moduleName = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH); + uint32_t labelId = fdp.ConsumeIntegral(); + int32_t userId = fdp.ConsumeIntegral(); + ModalSystemDialogUtil::ShowDeveloperModeDialog(bundleName, moduleName, labelId, 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/modalsystemdialogutil_fuzzer/modalsystemdialogutil_fuzzer.h b/test/fuzztest/modalsystemdialogutil_fuzzer/modalsystemdialogutil_fuzzer.h new file mode 100644 index 0000000000..611faad682 --- /dev/null +++ b/test/fuzztest/modalsystemdialogutil_fuzzer/modalsystemdialogutil_fuzzer.h @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2026 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 FUZZTEST_OHOS_ABILITY_RUNTIME_MODALSYSTEMDIALOGUTIL_FUZZER_H +#define FUZZTEST_OHOS_ABILITY_RUNTIME_MODALSYSTEMDIALOGUTIL_FUZZER_H + +#define FUZZ_PROJECT_NAME "modalsystemdialogutil_fuzzer" + +#endif // FUZZTEST_OHOS_ABILITY_RUNTIME_MODALSYSTEMDIALOGUTIL_FUZZER_H \ No newline at end of file diff --git a/test/fuzztest/modalsystemdialogutil_fuzzer/project.xml b/test/fuzztest/modalsystemdialogutil_fuzzer/project.xml new file mode 100644 index 0000000000..1884a288e3 --- /dev/null +++ b/test/fuzztest/modalsystemdialogutil_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + \ No newline at end of file