add fuzz test

Signed-off-by: zhangzezhong <zhangzezhong8@huawei-partners.com>
This commit is contained in:
zhangzezhong
2026-01-05 17:27:52 +08:00
parent 9939db868e
commit bbded9719b
18 changed files with 799 additions and 2 deletions
+4 -1
View File
@@ -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",
+177 -1
View File
@@ -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<std::string> 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<int32_t>());
startOptions.SetMaxWindowHeight(fdp.ConsumeIntegral<int32_t>());
}
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<uint32_t>();
bundleInfo.minCompatibleVersionCode = fdp.ConsumeIntegral<uint32_t>();
bundleInfo.compatibleVersion = fdp.ConsumeIntegral<uint32_t>();
bundleInfo.targetVersion = fdp.ConsumeIntegral<uint32_t>();
bundleInfo.appIndex = fdp.ConsumeIntegral<int32_t>();
bundleInfo.minSdkVersion = fdp.ConsumeIntegral<int32_t>();
bundleInfo.maxSdkVersion = fdp.ConsumeIntegral<int32_t>();
bundleInfo.overlayType = fdp.ConsumeIntegralInRange<int32_t>(CODE_MIN_ONE, CODE_MAX_THREE);
bundleInfo.uid = fdp.ConsumeIntegral<int>();
bundleInfo.gid = fdp.ConsumeIntegral<int>();
bundleInfo.installTime = fdp.ConsumeIntegral<int64_t>();
bundleInfo.updateTime = fdp.ConsumeIntegral<int64_t>();
bundleInfo.firstInstallTime = fdp.ConsumeIntegral<int64_t>();
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<AppExecFwk::BundleInfo> GenerateBundleInfoArray(FuzzedDataProvider& fdp, size_t arraySizeMax = CODE_TEN)
{
std::vector<AppExecFwk::BundleInfo> result;
size_t arraySize = fdp.ConsumeIntegralInRange<size_t>(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<uint32_t>();
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<uint32_t>();
applicationInfo.apiCompatibleVersion = fdp.ConsumeIntegral<uint32_t>();
applicationInfo.iconId = fdp.ConsumeIntegral<uint32_t>();
applicationInfo.labelId = fdp.ConsumeIntegral<uint32_t>();
applicationInfo.descriptionId = fdp.ConsumeIntegral<uint32_t>();
applicationInfo.accessTokenId = fdp.ConsumeIntegral<uint32_t>();
applicationInfo.applicationReservedFlag = fdp.ConsumeIntegral<uint32_t>();
applicationInfo.apiTargetVersion = fdp.ConsumeIntegral<int32_t>();
applicationInfo.minCompatibleVersionCode = fdp.ConsumeIntegral<int32_t>();
applicationInfo.supportedModes = fdp.ConsumeIntegral<int32_t>();
applicationInfo.appIndex = fdp.ConsumeIntegral<int32_t>();
applicationInfo.uid = fdp.ConsumeIntegral<int32_t>();
applicationInfo.flags = fdp.ConsumeIntegral<int32_t>();
applicationInfo.targetPriority = fdp.ConsumeIntegral<int32_t>();
applicationInfo.overlayState = fdp.ConsumeIntegral<int32_t>();
applicationInfo.maxChildProcess = fdp.ConsumeIntegral<int32_t>();
applicationInfo.applicationFlags = fdp.ConsumeIntegral<int32_t>();
applicationInfo.bundleType = static_cast<BundleType>(fdp.ConsumeIntegralInRange<int32_t>(0, CODE_FOUR));
applicationInfo.crowdtestDeadline = fdp.ConsumeIntegral<int64_t>();
applicationInfo.accessTokenIdEx = fdp.ConsumeIntegral<uint64_t>();
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
@@ -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);
@@ -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",
]
}
###############################################################################
@@ -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 <cstddef>
#include <cstdint>
#include <fuzzer/FuzzedDataProvider.h>
#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;
}
@@ -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
@@ -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
@@ -0,0 +1,25 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- 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_config>
<fuzztest>
<!-- maximum length of a test input -->
<max_len>1000</max_len>
<!-- maximum total time in seconds to run the fuzzer -->
<max_total_time>300</max_total_time>
<!-- memory usage limit in Mb -->
<rss_limit_mb>4096</rss_limit_mb>
</fuzztest>
</fuzz_config>
@@ -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",
]
}
###############################################################################
@@ -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
@@ -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 <cstddef>
#include <cstdint>
#include <fuzzer/FuzzedDataProvider.h>
#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<BundleInfo> bundleInfos = AbilityFuzzUtil::GenerateBundleInfoArray(fdp);
int32_t userId = fdp.ConsumeIntegral<int32_t>();
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;
}
@@ -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
@@ -0,0 +1,25 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- 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_config>
<fuzztest>
<!-- maximum length of a test input -->
<max_len>1000</max_len>
<!-- maximum total time in seconds to run the fuzzer -->
<max_total_time>300</max_total_time>
<!-- memory usage limit in Mb -->
<rss_limit_mb>4096</rss_limit_mb>
</fuzztest>
</fuzz_config>
@@ -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",
]
}
###############################################################################
@@ -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
@@ -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 <cstddef>
#include <cstdint>
#include <fuzzer/FuzzedDataProvider.h>
#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<uint32_t>();
int32_t userId = fdp.ConsumeIntegral<int32_t>();
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;
}
@@ -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
@@ -0,0 +1,25 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- 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_config>
<fuzztest>
<!-- maximum length of a test input -->
<max_len>1000</max_len>
<!-- maximum total time in seconds to run the fuzzer -->
<max_total_time>300</max_total_time>
<!-- memory usage limit in Mb -->
<rss_limit_mb>4096</rss_limit_mb>
</fuzztest>
</fuzz_config>