diff --git a/test/fuzztest/BUILD.gn b/test/fuzztest/BUILD.gn index 006c2d698b0f82441bbb09c29137a0dc39f9b647..e00486f4c15b327da48655bfee43560606fe5374 100644 --- a/test/fuzztest/BUILD.gn +++ b/test/fuzztest/BUILD.gn @@ -312,6 +312,12 @@ group("fuzztest") { "deeplinkreserveconfig_fuzzer:fuzztest", "delegatordoabilityforeground_fuzzer:fuzztest", "dialogsessioninfo_fuzzer:fuzztest", + "dialogsessionmanager_fuzzer:fuzztest", + "dialogsessionmanagerfirst_fuzzer:fuzztest", + "dialogsessionmanagersecond_fuzzer:fuzztest", + "dialogsessionmanagerthird_fuzzer:fuzztest", + "dialogsessionmanagerfourth_fuzzer:fuzztest", + "dialogsessionmanagerfifth_fuzzer:fuzztest", "disposedobserver_fuzzer:fuzztest", "doabilitybackground_fuzzer:fuzztest", "doabilityforeground_fuzzer:fuzztest", diff --git a/test/fuzztest/ability_fuzz_util.h b/test/fuzztest/ability_fuzz_util.h index c69475acf34ca151d018bc225987f21f4d0daee2..862ee6f3488e5c31f21dee943eea89b323be4630 100644 --- a/test/fuzztest/ability_fuzz_util.h +++ b/test/fuzztest/ability_fuzz_util.h @@ -274,6 +274,182 @@ void GetRandomKeepAliveAppInfo(FuzzedDataProvider& fdp, AppInfo& info) info.instanceKey = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH); info.bundleName = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH); } + +void GetRandomAppqfInfo(FuzzedDataProvider& fdp, AppqfInfo& deployedAppqfInfo) +{ + deployedAppqfInfo.type = static_cast(fdp.ConsumeIntegralInRange(0, CODE_TWO)); + deployedAppqfInfo.versionCode = fdp.ConsumeIntegral(); + deployedAppqfInfo.versionName = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH); + deployedAppqfInfo.cpuAbi = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH); + deployedAppqfInfo.nativeLibraryPath = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH); + std::vector hqfInfos; +} + +void GetRandomDeployingAppqfInfo(FuzzedDataProvider& fdp, AppqfInfo& deployingAppqfInfo) +{ + deployingAppqfInfo.type = static_cast(fdp.ConsumeIntegralInRange(0, CODE_TWO)); + deployingAppqfInfo.versionCode = fdp.ConsumeIntegral(); + deployingAppqfInfo.versionName = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH); + deployingAppqfInfo.cpuAbi = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH); + deployingAppqfInfo.nativeLibraryPath = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH); + std::vector hqfInfos; +} + +void GetRandomAppQuickFix(FuzzedDataProvider& fdp, AppQuickFix& appQuickFix) +{ + appQuickFix.versionCode = fdp.ConsumeIntegral(); + appQuickFix.bundleName = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH); + appQuickFix.versionName = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH); + GetRandomAppqfInfo(fdp, appQuickFix.deployedAppqfInfo); + GetRandomDeployingAppqfInfo(fdp, appQuickFix.deployingAppqfInfo); +} + +void GetRandomResourceInfo(FuzzedDataProvider& fdp, Resource& labelResource) +{ + labelResource.bundleName = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH); + labelResource.moduleName = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH); + labelResource.id = fdp.ConsumeIntegral(); +} + +void GetRandomApplicationInfo(FuzzedDataProvider& fdp, ApplicationInfo& appInfo) +{ + appInfo.name = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH); + appInfo.bundleName = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH); + appInfo.versionCode = fdp.ConsumeIntegral(); + appInfo.versionName = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH); + appInfo.minCompatibleVersionCode = fdp.ConsumeIntegral(); + appInfo.apiCompatibleVersion = fdp.ConsumeIntegral(); + appInfo.apiTargetVersion = fdp.ConsumeIntegral(); + appInfo.crowdtestDeadline = fdp.ConsumeIntegral(); + appInfo.iconPath = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH); + appInfo.iconId = fdp.ConsumeIntegral(); + GetRandomResourceInfo(fdp, appInfo.labelResource); + appInfo.label = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH); + appInfo.labelId = fdp.ConsumeIntegral(); + GetRandomResourceInfo(fdp, appInfo.labelResource); + appInfo.description = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH); + appInfo.descriptionId = fdp.ConsumeIntegral(); + GetRandomResourceInfo(fdp, appInfo.labelResource); + appInfo.keepAlive = fdp.ConsumeBool(); + appInfo.removable = fdp.ConsumeBool(); + appInfo.singleton = fdp.ConsumeBool(); + appInfo.userDataClearable = fdp.ConsumeBool(); + appInfo.allowAppRunWhenDeviceFirstLocked = fdp.ConsumeBool(); + appInfo.accessible = fdp.ConsumeBool(); + appInfo.runningResourcesApply = fdp.ConsumeBool(); + appInfo.associatedWakeUp = fdp.ConsumeBool(); + appInfo.hideDesktopIcon = fdp.ConsumeBool(); + appInfo.formVisibleNotify = fdp.ConsumeBool(); + appInfo.installedForAllUser = fdp.ConsumeBool(); + appInfo.allowEnableNotification = fdp.ConsumeBool(); + appInfo.allowMultiProcess = fdp.ConsumeBool(); + appInfo.gwpAsanEnabled = fdp.ConsumeBool(); + appInfo.hasPlugin = fdp.ConsumeBool(); + appInfo.allowCommonEvent = GenerateStringArray(fdp); + appInfo.assetAccessGroups = GenerateStringArray(fdp); + appInfo.isSystemApp = fdp.ConsumeBool(); + appInfo.isLauncherApp = fdp.ConsumeBool(); + appInfo.isFreeInstallApp = fdp.ConsumeBool(); + appInfo.asanEnabled = fdp.ConsumeBool(); + appInfo.asanLogPath = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH); + appInfo.codePath = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH); + appInfo.dataDir = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH); + appInfo.dataBaseDir = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH); + appInfo.cacheDir = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH); + appInfo.entryDir = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH); + appInfo.apiReleaseType = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH); + appInfo.debug = fdp.ConsumeBool(); + appInfo.deviceId = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH); + appInfo.distributedNotificationEnabled = fdp.ConsumeBool(); + appInfo.entityType = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH); + appInfo.process = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH); + appInfo.supportedModes = fdp.ConsumeIntegral(); + appInfo.vendor = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH); + appInfo.appPrivilegeLevel = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH); + appInfo.appDistributionType = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH); + appInfo.appProvisionType = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH); + appInfo.accessTokenId = fdp.ConsumeIntegral(); + appInfo.applicationReservedFlag = fdp.ConsumeIntegral(); + appInfo.accessTokenIdEx = fdp.ConsumeIntegral(); + appInfo.enabled = fdp.ConsumeBool(); + appInfo.appIndex = fdp.ConsumeIntegral(); + appInfo.uid = fdp.ConsumeIntegral(); + appInfo.maxChildProcess = fdp.ConsumeIntegral(); + appInfo.nativeLibraryPath = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH); + appInfo.cpuAbi = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH); + appInfo.arkNativeFilePath = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH); + appInfo.arkNativeFileAbi = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH); + appInfo.permissions = GenerateStringArray(fdp); + appInfo.moduleSourceDirs = GenerateStringArray(fdp); + appInfo.targetBundleList = GenerateStringArray(fdp); + appInfo.fingerprint = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH); + GetRandomAppQuickFix(fdp, appInfo.appQuickFix); + appInfo.icon = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH); + appInfo.flags = fdp.ConsumeIntegral(); + appInfo.entryModuleName = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH); + appInfo.isCompressNativeLibs = fdp.ConsumeBool(); + appInfo.signatureKey = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH); + appInfo.multiProjects = fdp.ConsumeBool(); + appInfo.tsanEnabled = fdp.ConsumeBool(); + appInfo.hwasanEnabled = fdp.ConsumeBool(); + appInfo.ubsanEnabled = fdp.ConsumeBool(); + appInfo.cloudFileSyncEnabled = fdp.ConsumeBool(); + appInfo.needAppDetail = fdp.ConsumeBool(); + appInfo.appDetailAbilityLibraryPath = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH); + appInfo.targetBundleName = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH); + appInfo.targetPriority = fdp.ConsumeIntegral(); + appInfo.overlayState = fdp.ConsumeIntegral(); + appInfo.bundleType = static_cast(fdp.ConsumeIntegralInRange(0, CODE_TWO)); + appInfo.compileSdkVersion = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH); + appInfo.compileSdkType = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH); + appInfo.organization = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH); + appInfo.installSource = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH); + appInfo.configuration = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH); +} + +void GetRandomStartWindowResourceInfo(FuzzedDataProvider& fdp, StartWindowResource& startWindowResource) +{ + startWindowResource.startWindowAppIconId = fdp.ConsumeIntegral(); + startWindowResource.startWindowIllustrationId = fdp.ConsumeIntegral(); + startWindowResource.startWindowBrandingImageId = fdp.ConsumeIntegral(); + startWindowResource.startWindowBackgroundColorId = fdp.ConsumeIntegral(); + startWindowResource.startWindowBackgroundImageId = fdp.ConsumeIntegral(); + startWindowResource.startWindowBackgroundImageFit = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH); +} + +void GetRandomAbilityRequestInfo(FuzzedDataProvider& fdp, AbilityRequest& info) +{ + info.restart = fdp.ConsumeBool(); + info.startRecent = fdp.ConsumeBool(); + info.uriReservedFlag = fdp.ConsumeBool(); + info.isFromIcon = fdp.ConsumeBool(); + info.isShellCall = fdp.ConsumeBool(); + info.isQueryERMS = fdp.ConsumeBool(); + info.isEmbeddedAllowed = fdp.ConsumeBool(); + info.callSpecifiedFlagTimeout = fdp.ConsumeBool(); + info.hideStartWindow = fdp.ConsumeBool(); + info.restartCount = fdp.ConsumeIntegral(); + info.uid = fdp.ConsumeIntegral(); + info.collaboratorType = static_cast(fdp.ConsumeIntegralInRange(0, CODE_TWO)); + info.callerTokenRecordId = fdp.ConsumeIntegral(); + info.userId = fdp.ConsumeIntegral(); + info.callerAccessTokenId = fdp.ConsumeIntegral(); + info.specifyTokenId = fdp.ConsumeIntegral(); + info.callerUid = fdp.ConsumeIntegral(); + info.requestCode = fdp.ConsumeIntegral(); + info.callType = static_cast(fdp.ConsumeIntegralInRange(0, CODE_TWO)); + info.restartTime = fdp.ConsumeIntegral(); + info.extensionType = static_cast(fdp.ConsumeIntegralInRange(0, CODE_TWO)); + info.extensionProcessMode = static_cast(fdp.ConsumeIntegralInRange(0, CODE_TWO)); + info.specifiedFlag = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH); + info.customProcess = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH); + info.reservedBundleName = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH); + info.appId = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH); + info.startTime = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH); + Want want; + GetRandomAbilityInfo(fdp, info.abilityInfo); + GetRandomApplicationInfo(fdp, info.appInfo); +} } // namespace AbilityFuzzUtil } // namespace AppExecFwk } // namespace OHOS diff --git a/test/fuzztest/dialogsessionmanager_fuzzer/BUILD.gn b/test/fuzztest/dialogsessionmanager_fuzzer/BUILD.gn index 140b43951c36bfc86a684504733aaca4a0ac8d7b..e08de4620fd6835b151552a3ffaa3f03cd59cad5 100644 --- a/test/fuzztest/dialogsessionmanager_fuzzer/BUILD.gn +++ b/test/fuzztest/dialogsessionmanager_fuzzer/BUILD.gn @@ -70,6 +70,7 @@ ohos_fuzztest("DialogSessionManagerFuzzTest") { "common_event_service:cesfwk_innerkits", "ffrt:libffrt", "hilog:libhilog", + "hisysevent:libhisysevent", "hitrace:hitrace_meter", "ipc:ipc_core", "libjpeg-turbo:turbojpeg", diff --git a/test/fuzztest/dialogsessionmanager_fuzzer/dialogsessionmanager_fuzzer.cpp b/test/fuzztest/dialogsessionmanager_fuzzer/dialogsessionmanager_fuzzer.cpp index 4ea228b711c6c10b687680344912a9d7c7ef8492..32579b47c248328987c0d048b2ce8341ff06dd59 100644 --- a/test/fuzztest/dialogsessionmanager_fuzzer/dialogsessionmanager_fuzzer.cpp +++ b/test/fuzztest/dialogsessionmanager_fuzzer/dialogsessionmanager_fuzzer.cpp @@ -89,10 +89,20 @@ bool DoSomethingInterestingWithMyAPI(const char *data, size_t size) DialogAbilityInfo callerAbilityInfo; dialogSessionManager->GenerateCallerAbilityInfo(abilityRequest, callerAbilityInfo); dialogSessionManager->GenerateSelectorTargetAbilityInfos(dialogAppInfos, targetAbilityInfos); - dialogSessionManager->GenerateDialogCallerInfo(abilityRequest, int32Param, dialogCallerInfo, isSelector); - dialogSessionManager->NotifySCBToRecoveryAfterInterception(dialogSessionId, abilityRequest); + SelectorType type = SelectorType::WITHOUT_SELECTOR; + dialogSessionManager->GenerateDialogSessionRecordCommon(abilityRequest, int32Param, wantParams, + dialogAppInfos, type, isSelector); + type = SelectorType::IMPLICIT_START_SELECTOR; + dialogSessionManager->GenerateDialogSessionRecordCommon(abilityRequest, int32Param, wantParams, + dialogAppInfos, type, isSelector); + type = SelectorType::APP_CLONE_SELECTOR; dialogSessionManager->GenerateDialogSessionRecordCommon(abilityRequest, int32Param, wantParams, - dialogAppInfos, isSelector); + dialogAppInfos, type, isSelector); + type = SelectorType::INTERCEPTOR_SELECTOR; + dialogSessionManager->GenerateDialogSessionRecordCommon(abilityRequest, int32Param, wantParams, + dialogAppInfos, type, isSelector); + dialogSessionManager->GenerateDialogCallerInfo(abilityRequest, int32Param, dialogCallerInfo, type, isSelector); + dialogSessionManager->NotifySCBToRecoveryAfterInterception(dialogSessionId, abilityRequest); dialogSessionManager->CreateJumpModalDialog(abilityRequest, int32Param, want); dialogSessionManager->CreateImplicitSelectorModalDialog(abilityRequest, want, int32Param, dialogAppInfos); dialogSessionManager->CreateCloneSelectorModalDialog(abilityRequest, want, int32Param, dialogAppInfos, diff --git a/test/fuzztest/dialogsessionmanagerfifth_fuzzer/BUILD.gn b/test/fuzztest/dialogsessionmanagerfifth_fuzzer/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..50f440f4369dcf47ca2a83b494ef4e5ae788efcf --- /dev/null +++ b/test/fuzztest/dialogsessionmanagerfifth_fuzzer/BUILD.gn @@ -0,0 +1,102 @@ +# Copyright (c) 2024-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("//foundation/ability/ability_runtime/ability_runtime.gni") +module_output_path = "ability_runtime/abilitymgr" + +##############################fuzztest########################################## +ohos_fuzztest("DialogSessionManagerFifthFuzzTest") { + module_out_path = module_output_path + + fuzz_config_file = + "${ability_runtime_test_path}/fuzztest/dialogsessionmanagerfifth_fuzzer" + include_dirs = [ + "${ability_runtime_innerkits_path}/ability_manager/include", + "${ability_runtime_services_path}/abilitymgr/include/utils", + "${ability_runtime_services_path}/abilitymgr/include", + ] + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + sources = [ + "${ability_runtime_path}/services/abilitymgr/src/dialog_session/dialog_session_manager.cpp", + "${ability_runtime_services_path}/abilitymgr/src/utils/start_ability_utils.cpp", + "dialogsessionmanagerfifth_fuzzer.cpp", + ] + + configs = [ + "${ability_runtime_innerkits_path}/ability_manager:ability_manager_public_config", + "${ability_runtime_services_path}/abilitymgr:abilityms_config", + ] + cflags = [] + if (target_cpu == "arm") { + cflags += [ "-DBINDER_IPC_32BIT" ] + } + deps = [ + "${ability_runtime_innerkits_path}/ability_manager:ability_manager", + "${ability_runtime_innerkits_path}/ability_manager:ability_start_options", + "${ability_runtime_innerkits_path}/app_manager:app_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:perm_verification", + ] + + external_deps = [ + "ability_base:want", + "ability_base:zuri", + "bundle_framework:appexecfwk_base", + "bundle_framework:appexecfwk_core", + "c_utils:utils", + "common_event_service:cesfwk_innerkits", + "ffrt:libffrt", + "hilog:libhilog", + "hisysevent:libhisysevent", + "hitrace:hitrace_meter", + "ipc:ipc_core", + "libjpeg-turbo:turbojpeg", + "napi:ace_napi", + "safwk:system_ability_fwk", + "samgr:samgr_proxy", + "window_manager:libmodal_system_ui_extension_client", + "window_manager:libwsutils", + ] + + if (background_task_mgr_continuous_task_enable) { + external_deps += [ "background_task_mgr:bgtaskmgr_innerkits" ] + } + + if (ability_runtime_graphics) { + external_deps += [ "window_manager:libwm" ] + } +} + +############################################################################### +group("fuzztest") { + testonly = true + deps = [] + deps += [ + # deps file + ":DialogSessionManagerFifthFuzzTest", + ] +} +############################################################################### diff --git a/test/fuzztest/dialogsessionmanagerfifth_fuzzer/corpus/init b/test/fuzztest/dialogsessionmanagerfifth_fuzzer/corpus/init new file mode 100644 index 0000000000000000000000000000000000000000..7ade8a0faafeaedba7241e7d4a97b8e1f9691932 --- /dev/null +++ b/test/fuzztest/dialogsessionmanagerfifth_fuzzer/corpus/init @@ -0,0 +1,16 @@ +/* + * 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. + */ + +FUZZ \ No newline at end of file diff --git a/test/fuzztest/dialogsessionmanagerfifth_fuzzer/dialogsessionmanagerfifth_fuzzer.cpp b/test/fuzztest/dialogsessionmanagerfifth_fuzzer/dialogsessionmanagerfifth_fuzzer.cpp new file mode 100644 index 0000000000000000000000000000000000000000..8537246bbf14a8426b5aa644d0301668c9294ee6 --- /dev/null +++ b/test/fuzztest/dialogsessionmanagerfifth_fuzzer/dialogsessionmanagerfifth_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 "dialogsessionmanagerfifth_fuzzer.h" +#include +#include +#include +#define private public +#include "dialog_session_manager.h" +#undef private +#include "ability_record.h" +#include "dialog_session_manager.h" + +using namespace OHOS::AAFwk; +using namespace OHOS::AppExecFwk; + +namespace OHOS { +namespace {} // namespace + +bool DoSomethingInterestingWithMyAPI(const uint8_t *data, size_t size) +{ + sptr dilogSessionInfo; + std::shared_ptr dialogCallerInfo; + std::string dialogSessionId; + FuzzedDataProvider fdp(data, size); + dialogSessionId = fdp.ConsumeRandomLengthString(); + std::shared_ptr dialogSessionManager = std::make_shared(); + if (dialogSessionManager == nullptr) { + return false; + } + dialogSessionManager->SetDialogSessionInfo(dialogSessionId, dilogSessionInfo, dialogCallerInfo); + return true; +} +} // namespace OHOS + +/* 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/dialogsessionmanagerfifth_fuzzer/dialogsessionmanagerfifth_fuzzer.h b/test/fuzztest/dialogsessionmanagerfifth_fuzzer/dialogsessionmanagerfifth_fuzzer.h new file mode 100644 index 0000000000000000000000000000000000000000..7d08cba4d86b2cb1871c94ad85c602d4248e7186 --- /dev/null +++ b/test/fuzztest/dialogsessionmanagerfifth_fuzzer/dialogsessionmanagerfifth_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 FUZZTEST_OHOS_ABILITY_RUNTIME_DIALOG_SESSION_MANAGER_FIFTH_FUZZER_H +#define FUZZTEST_OHOS_ABILITY_RUNTIME_DIALOG_SESSION_MANAGER_FIFTH_FUZZER_H + +#define FUZZ_PROJECT_NAME "dialogsessionmanagerfifth_fuzzer" + +#endif \ No newline at end of file diff --git a/test/fuzztest/dialogsessionmanagerfifth_fuzzer/project.xml b/test/fuzztest/dialogsessionmanagerfifth_fuzzer/project.xml new file mode 100644 index 0000000000000000000000000000000000000000..e72711e004d1b6a902ef03aefb893632c6da1404 --- /dev/null +++ b/test/fuzztest/dialogsessionmanagerfifth_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 600 + + 4096 + + \ No newline at end of file diff --git a/test/fuzztest/dialogsessionmanagerfirst_fuzzer/BUILD.gn b/test/fuzztest/dialogsessionmanagerfirst_fuzzer/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..2fec4d5687c08418b133249217a563b493d12c93 --- /dev/null +++ b/test/fuzztest/dialogsessionmanagerfirst_fuzzer/BUILD.gn @@ -0,0 +1,102 @@ +# Copyright (c) 2024-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("//foundation/ability/ability_runtime/ability_runtime.gni") +module_output_path = "ability_runtime/abilitymgr" + +##############################fuzztest########################################## +ohos_fuzztest("DialogSessionManagerFirstFuzzTest") { + module_out_path = module_output_path + + fuzz_config_file = + "${ability_runtime_test_path}/fuzztest/dialogsessionmanagerfirst_fuzzer" + include_dirs = [ + "${ability_runtime_innerkits_path}/ability_manager/include", + "${ability_runtime_services_path}/abilitymgr/include/utils", + "${ability_runtime_services_path}/abilitymgr/include", + ] + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + sources = [ + "${ability_runtime_path}/services/abilitymgr/src/dialog_session/dialog_session_manager.cpp", + "${ability_runtime_services_path}/abilitymgr/src/utils/start_ability_utils.cpp", + "dialogsessionmanagerfirst_fuzzer.cpp", + ] + + configs = [ + "${ability_runtime_innerkits_path}/ability_manager:ability_manager_public_config", + "${ability_runtime_services_path}/abilitymgr:abilityms_config", + ] + cflags = [] + if (target_cpu == "arm") { + cflags += [ "-DBINDER_IPC_32BIT" ] + } + deps = [ + "${ability_runtime_innerkits_path}/ability_manager:ability_manager", + "${ability_runtime_innerkits_path}/ability_manager:ability_start_options", + "${ability_runtime_innerkits_path}/app_manager:app_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:perm_verification", + ] + + external_deps = [ + "ability_base:want", + "ability_base:zuri", + "bundle_framework:appexecfwk_base", + "bundle_framework:appexecfwk_core", + "c_utils:utils", + "common_event_service:cesfwk_innerkits", + "ffrt:libffrt", + "hilog:libhilog", + "hisysevent:libhisysevent", + "hitrace:hitrace_meter", + "ipc:ipc_core", + "libjpeg-turbo:turbojpeg", + "napi:ace_napi", + "safwk:system_ability_fwk", + "samgr:samgr_proxy", + "window_manager:libmodal_system_ui_extension_client", + "window_manager:libwsutils", + ] + + if (background_task_mgr_continuous_task_enable) { + external_deps += [ "background_task_mgr:bgtaskmgr_innerkits" ] + } + + if (ability_runtime_graphics) { + external_deps += [ "window_manager:libwm" ] + } +} + +############################################################################### +group("fuzztest") { + testonly = true + deps = [] + deps += [ + # deps file + ":DialogSessionManagerFirstFuzzTest", + ] +} +############################################################################### diff --git a/test/fuzztest/dialogsessionmanagerfirst_fuzzer/corpus/init b/test/fuzztest/dialogsessionmanagerfirst_fuzzer/corpus/init new file mode 100644 index 0000000000000000000000000000000000000000..7ade8a0faafeaedba7241e7d4a97b8e1f9691932 --- /dev/null +++ b/test/fuzztest/dialogsessionmanagerfirst_fuzzer/corpus/init @@ -0,0 +1,16 @@ +/* + * 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. + */ + +FUZZ \ No newline at end of file diff --git a/test/fuzztest/dialogsessionmanagerfirst_fuzzer/dialogsessionmanagerfirst_fuzzer.cpp b/test/fuzztest/dialogsessionmanagerfirst_fuzzer/dialogsessionmanagerfirst_fuzzer.cpp new file mode 100644 index 0000000000000000000000000000000000000000..7cf7bde26066af8a09ceb706371508500a7885c1 --- /dev/null +++ b/test/fuzztest/dialogsessionmanagerfirst_fuzzer/dialogsessionmanagerfirst_fuzzer.cpp @@ -0,0 +1,80 @@ +/* + * 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 "dialogsessionmanagerfirst_fuzzer.h" +#include +#include +#include +#define private public +#include "dialog_session_manager.h" +#undef private +#include "ability_record.h" +#include "dialog_session_manager.h" +#include "../ability_fuzz_util.h" + +using namespace OHOS::AAFwk; +using namespace OHOS::AppExecFwk; + +namespace OHOS { +namespace { + constexpr size_t CODE_TWO = 2; +} // namespace + +sptr GetFuzzAbilityToken() +{ + sptr token = nullptr; + AbilityRequest abilityRequest; + abilityRequest.appInfo.bundleName = "com.example.fuzzTest"; + abilityRequest.abilityInfo.name = "MainAbility"; + abilityRequest.abilityInfo.type = AbilityType::DATA; + std::shared_ptr abilityRecord = AbilityRecord::CreateAbilityRecord(abilityRequest); + if (abilityRecord) { + token = abilityRecord->GetToken(); + } + return token; +} + +bool DoSomethingInterestingWithMyAPI(const uint8_t *data, size_t size) +{ + AbilityRequest info; + SelectorType type; + sptr callerToken = GetFuzzAbilityToken(); + std::string dialogSessionId; + FuzzedDataProvider fdp(data, size); + bool isSCBCall = fdp.ConsumeBool(); + int32_t userId = fdp.ConsumeIntegral(); + dialogSessionId = fdp.ConsumeRandomLengthString(); + bool needGrantUriPermission = fdp.ConsumeBool(); + type = static_cast(fdp.ConsumeIntegralInRange(0, CODE_TWO)); + AbilityFuzzUtil::GetRandomAbilityRequestInfo(fdp, info); + std::shared_ptr dialogSessionManager = std::make_shared(); + if (dialogSessionManager == nullptr) { + return false; + } + dialogSessionManager->SetQueryERMSInfo(dialogSessionId, info); + dialogSessionManager->UpdateExtensionWantWithDialogCallerInfo(info, callerToken, isSCBCall); + dialogSessionManager->OnlySetDialogCallerInfo(info, userId, type, dialogSessionId, needGrantUriPermission); + return true; +} +} // namespace OHOS + +/* 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/dialogsessionmanagerfirst_fuzzer/dialogsessionmanagerfirst_fuzzer.h b/test/fuzztest/dialogsessionmanagerfirst_fuzzer/dialogsessionmanagerfirst_fuzzer.h new file mode 100644 index 0000000000000000000000000000000000000000..b61d05bd044d7e162c7061d5f24fe36c0da0327b --- /dev/null +++ b/test/fuzztest/dialogsessionmanagerfirst_fuzzer/dialogsessionmanagerfirst_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 FUZZTEST_OHOS_ABILITY_RUNTIME_DIALOG_SESSION_MANAGER_FIRST_FUZZER_H +#define FUZZTEST_OHOS_ABILITY_RUNTIME_DIALOG_SESSION_MANAGER_FIRST_FUZZER_H + +#define FUZZ_PROJECT_NAME "dialogsessionmanagerfirst_fuzzer" + +#endif \ No newline at end of file diff --git a/test/fuzztest/dialogsessionmanagerfirst_fuzzer/project.xml b/test/fuzztest/dialogsessionmanagerfirst_fuzzer/project.xml new file mode 100644 index 0000000000000000000000000000000000000000..e72711e004d1b6a902ef03aefb893632c6da1404 --- /dev/null +++ b/test/fuzztest/dialogsessionmanagerfirst_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 600 + + 4096 + + \ No newline at end of file diff --git a/test/fuzztest/dialogsessionmanagerfourth_fuzzer/BUILD.gn b/test/fuzztest/dialogsessionmanagerfourth_fuzzer/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..6f9eea3245d18eee82046adb360cec9875d61fb2 --- /dev/null +++ b/test/fuzztest/dialogsessionmanagerfourth_fuzzer/BUILD.gn @@ -0,0 +1,107 @@ +# Copyright (c) 2024-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("//foundation/ability/ability_runtime/ability_runtime.gni") +module_output_path = "ability_runtime/abilitymgr" + +##############################fuzztest########################################## +ohos_fuzztest("DialogSessionManagerFourthFuzzTest") { + module_out_path = module_output_path + + fuzz_config_file = + "${ability_runtime_test_path}/fuzztest/dialogsessionmanagerfourth_fuzzer" + include_dirs = [ + "${ability_runtime_innerkits_path}/ability_manager/include", + "${ability_runtime_services_path}/abilitymgr/include/utils", + "${ability_runtime_services_path}/abilitymgr/include", + ] + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + sources = [ + "${ability_runtime_path}/services/abilitymgr/src/dialog_session/dialog_session_manager.cpp", + "${ability_runtime_services_path}/abilitymgr/src/query_erms_manager.cpp", + "${ability_runtime_path}/services/abilitymgr/src/query_erms_observer_manager.cpp", + "${ability_runtime_path}/services/common/src/task_handler_wrap.cpp", + "${ability_runtime_path}/services/common/src/queue_task_handler_wrap.cpp", + "${ability_runtime_path}/services/common/src/ffrt_task_handler_wrap.cpp", + "${ability_runtime_services_path}/abilitymgr/src/utils/start_ability_utils.cpp", + "dialogsessionmanagerfourth_fuzzer.cpp", + ] + + configs = [ + "${ability_runtime_innerkits_path}/ability_manager:ability_manager_public_config", + "${ability_runtime_services_path}/abilitymgr:abilityms_config", + ] + cflags = [] + if (target_cpu == "arm") { + cflags += [ "-DBINDER_IPC_32BIT" ] + } + deps = [ + "${ability_runtime_innerkits_path}/ability_manager:ability_manager", + "${ability_runtime_innerkits_path}/ability_manager:ability_start_options", + "${ability_runtime_innerkits_path}/app_manager:app_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:perm_verification", + ] + + external_deps = [ + "ability_base:want", + "ability_base:zuri", + "bundle_framework:appexecfwk_base", + "bundle_framework:appexecfwk_core", + "c_utils:utils", + "common_event_service:cesfwk_innerkits", + "ffrt:libffrt", + "hilog:libhilog", + "hisysevent:libhisysevent", + "hitrace:hitrace_meter", + "ipc:ipc_core", + "libjpeg-turbo:turbojpeg", + "napi:ace_napi", + "safwk:system_ability_fwk", + "samgr:samgr_proxy", + "window_manager:libmodal_system_ui_extension_client", + "window_manager:libwsutils", + ] + + if (background_task_mgr_continuous_task_enable) { + external_deps += [ "background_task_mgr:bgtaskmgr_innerkits" ] + } + + if (ability_runtime_graphics) { + external_deps += [ "window_manager:libwm" ] + } +} + +############################################################################### +group("fuzztest") { + testonly = true + deps = [] + deps += [ + # deps file + ":DialogSessionManagerFourthFuzzTest", + ] +} +############################################################################### diff --git a/test/fuzztest/dialogsessionmanagerfourth_fuzzer/corpus/init b/test/fuzztest/dialogsessionmanagerfourth_fuzzer/corpus/init new file mode 100644 index 0000000000000000000000000000000000000000..7ade8a0faafeaedba7241e7d4a97b8e1f9691932 --- /dev/null +++ b/test/fuzztest/dialogsessionmanagerfourth_fuzzer/corpus/init @@ -0,0 +1,16 @@ +/* + * 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. + */ + +FUZZ \ No newline at end of file diff --git a/test/fuzztest/dialogsessionmanagerfourth_fuzzer/dialogsessionmanagerfourth_fuzzer.cpp b/test/fuzztest/dialogsessionmanagerfourth_fuzzer/dialogsessionmanagerfourth_fuzzer.cpp new file mode 100644 index 0000000000000000000000000000000000000000..a57bbe744bb05242e477ac62fad3d76b435ba2a1 --- /dev/null +++ b/test/fuzztest/dialogsessionmanagerfourth_fuzzer/dialogsessionmanagerfourth_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 "dialogsessionmanagerfourth_fuzzer.h" +#include +#include +#include +#define private public +#include "dialog_session_manager.h" +#undef private + +using namespace OHOS::AAFwk; +using namespace OHOS::AppExecFwk; + +namespace OHOS { +namespace {} // namespace + +bool DoSomethingInterestingWithMyAPI(const uint8_t *data, size_t size) +{ + std::string dialogSessionId; + FuzzedDataProvider fdp(data, size); + dialogSessionId = fdp.ConsumeRandomLengthString(); + bool isAllowed = fdp.ConsumeBool(); + Want want; + std::shared_ptr dialogSessionManager = std::make_shared(); + if (dialogSessionManager == nullptr) { + return false; + } + dialogSessionManager->NotifyAbilityRequestFailure(dialogSessionId, want); + dialogSessionManager->SendDialogResult(want, dialogSessionId, isAllowed); + return true; +} +} // namespace OHOS + +/* 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/dialogsessionmanagerfourth_fuzzer/dialogsessionmanagerfourth_fuzzer.h b/test/fuzztest/dialogsessionmanagerfourth_fuzzer/dialogsessionmanagerfourth_fuzzer.h new file mode 100644 index 0000000000000000000000000000000000000000..5c06d58431da579a841883df4ac15af9c6f9918e --- /dev/null +++ b/test/fuzztest/dialogsessionmanagerfourth_fuzzer/dialogsessionmanagerfourth_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 FUZZTEST_OHOS_ABILITY_RUNTIME_DIALOG_SESSION_MANAGER_FOURTH_FUZZER_H +#define FUZZTEST_OHOS_ABILITY_RUNTIME_DIALOG_SESSION_MANAGER_FOURTH_FUZZER_H + +#define FUZZ_PROJECT_NAME "dialogsessionmanagerfourth_fuzzer" + +#endif \ No newline at end of file diff --git a/test/fuzztest/dialogsessionmanagerfourth_fuzzer/project.xml b/test/fuzztest/dialogsessionmanagerfourth_fuzzer/project.xml new file mode 100644 index 0000000000000000000000000000000000000000..e72711e004d1b6a902ef03aefb893632c6da1404 --- /dev/null +++ b/test/fuzztest/dialogsessionmanagerfourth_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 600 + + 4096 + + \ No newline at end of file diff --git a/test/fuzztest/dialogsessionmanagersecond_fuzzer/BUILD.gn b/test/fuzztest/dialogsessionmanagersecond_fuzzer/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..fa51707607fb890c7933c8bb4a884c26410429ac --- /dev/null +++ b/test/fuzztest/dialogsessionmanagersecond_fuzzer/BUILD.gn @@ -0,0 +1,107 @@ +# Copyright (c) 2024-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("//foundation/ability/ability_runtime/ability_runtime.gni") +module_output_path = "ability_runtime/abilitymgr" + +##############################fuzztest########################################## +ohos_fuzztest("DialogSessionManagerSecondFuzzTest") { + module_out_path = module_output_path + + fuzz_config_file = + "${ability_runtime_test_path}/fuzztest/dialogsessionmanagersecond_fuzzer" + include_dirs = [ + "${ability_runtime_innerkits_path}/ability_manager/include", + "${ability_runtime_services_path}/abilitymgr/include/utils", + "${ability_runtime_services_path}/abilitymgr/include", + ] + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + sources = [ + "${ability_runtime_path}/services/abilitymgr/src/dialog_session/dialog_session_manager.cpp", + "${ability_runtime_services_path}/abilitymgr/src/query_erms_manager.cpp", + "${ability_runtime_path}/services/abilitymgr/src/query_erms_observer_manager.cpp", + "${ability_runtime_path}/services/common/src/task_handler_wrap.cpp", + "${ability_runtime_path}/services/common/src/queue_task_handler_wrap.cpp", + "${ability_runtime_path}/services/common/src/ffrt_task_handler_wrap.cpp", + "${ability_runtime_services_path}/abilitymgr/src/utils/start_ability_utils.cpp", + "dialogsessionmanagersecond_fuzzer.cpp", + ] + + configs = [ + "${ability_runtime_innerkits_path}/ability_manager:ability_manager_public_config", + "${ability_runtime_services_path}/abilitymgr:abilityms_config", + ] + cflags = [] + if (target_cpu == "arm") { + cflags += [ "-DBINDER_IPC_32BIT" ] + } + deps = [ + "${ability_runtime_innerkits_path}/ability_manager:ability_manager", + "${ability_runtime_innerkits_path}/ability_manager:ability_start_options", + "${ability_runtime_innerkits_path}/app_manager:app_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:perm_verification", + ] + + external_deps = [ + "ability_base:want", + "ability_base:zuri", + "bundle_framework:appexecfwk_base", + "bundle_framework:appexecfwk_core", + "c_utils:utils", + "common_event_service:cesfwk_innerkits", + "ffrt:libffrt", + "hilog:libhilog", + "hisysevent:libhisysevent", + "hitrace:hitrace_meter", + "ipc:ipc_core", + "libjpeg-turbo:turbojpeg", + "napi:ace_napi", + "safwk:system_ability_fwk", + "samgr:samgr_proxy", + "window_manager:libmodal_system_ui_extension_client", + "window_manager:libwsutils", + ] + + if (background_task_mgr_continuous_task_enable) { + external_deps += [ "background_task_mgr:bgtaskmgr_innerkits" ] + } + + if (ability_runtime_graphics) { + external_deps += [ "window_manager:libwm" ] + } +} + +############################################################################### +group("fuzztest") { + testonly = true + deps = [] + deps += [ + # deps file + ":DialogSessionManagerSecondFuzzTest", + ] +} +############################################################################### diff --git a/test/fuzztest/dialogsessionmanagersecond_fuzzer/corpus/init b/test/fuzztest/dialogsessionmanagersecond_fuzzer/corpus/init new file mode 100644 index 0000000000000000000000000000000000000000..7ade8a0faafeaedba7241e7d4a97b8e1f9691932 --- /dev/null +++ b/test/fuzztest/dialogsessionmanagersecond_fuzzer/corpus/init @@ -0,0 +1,16 @@ +/* + * 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. + */ + +FUZZ \ No newline at end of file diff --git a/test/fuzztest/dialogsessionmanagersecond_fuzzer/dialogsessionmanagersecond_fuzzer.cpp b/test/fuzztest/dialogsessionmanagersecond_fuzzer/dialogsessionmanagersecond_fuzzer.cpp new file mode 100644 index 0000000000000000000000000000000000000000..92e6fbb3761e4556d3b73c14dfac55717fa23696 --- /dev/null +++ b/test/fuzztest/dialogsessionmanagersecond_fuzzer/dialogsessionmanagersecond_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 "dialogsessionmanagersecond_fuzzer.h" +#include +#include +#include +#define private public +#include "dialog_session_manager.h" +#undef private + +using namespace OHOS::AAFwk; +using namespace OHOS::AppExecFwk; + +namespace OHOS { +namespace {} // namespace + +bool DoSomethingInterestingWithMyAPI(const uint8_t *data, size_t size) +{ + std::string dialogSessionId; + FuzzedDataProvider fdp(data, size); + dialogSessionId = fdp.ConsumeRandomLengthString(); + bool isAllowed = fdp.ConsumeBool(); + std::shared_ptr dialogSessionManager = std::make_shared(); + if (dialogSessionManager == nullptr) { + return false; + } + dialogSessionManager->NotifyQueryERMSFinished(dialogSessionId, isAllowed); + dialogSessionManager->GetDialogSessionInfo(dialogSessionId); + dialogSessionManager->GetDialogCallerInfo(dialogSessionId); + dialogSessionManager->GetStartupSessionInfo(dialogSessionId); + dialogSessionManager->ClearDialogContext(dialogSessionId); + dialogSessionManager->ClearAllDialogContexts(); + return true; +} +} // namespace OHOS + +/* 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/dialogsessionmanagersecond_fuzzer/dialogsessionmanagersecond_fuzzer.h b/test/fuzztest/dialogsessionmanagersecond_fuzzer/dialogsessionmanagersecond_fuzzer.h new file mode 100644 index 0000000000000000000000000000000000000000..778b77125c236ffbfa298b0021bbbdd63e8337ee --- /dev/null +++ b/test/fuzztest/dialogsessionmanagersecond_fuzzer/dialogsessionmanagersecond_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 FUZZTEST_OHOS_ABILITY_RUNTIME_DIALOG_SESSION_MANAGER_SECOND_FUZZER_H +#define FUZZTEST_OHOS_ABILITY_RUNTIME_DIALOG_SESSION_MANAGER_SECOND_FUZZER_H + +#define FUZZ_PROJECT_NAME "dialogsessionmanagersecond_fuzzer" + +#endif \ No newline at end of file diff --git a/test/fuzztest/dialogsessionmanagersecond_fuzzer/project.xml b/test/fuzztest/dialogsessionmanagersecond_fuzzer/project.xml new file mode 100644 index 0000000000000000000000000000000000000000..e72711e004d1b6a902ef03aefb893632c6da1404 --- /dev/null +++ b/test/fuzztest/dialogsessionmanagersecond_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 600 + + 4096 + + \ No newline at end of file diff --git a/test/fuzztest/dialogsessionmanagerthird_fuzzer/BUILD.gn b/test/fuzztest/dialogsessionmanagerthird_fuzzer/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..4b6337959fcd1039208d2ebeeea4a8b5a295c722 --- /dev/null +++ b/test/fuzztest/dialogsessionmanagerthird_fuzzer/BUILD.gn @@ -0,0 +1,102 @@ +# Copyright (c) 2024-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("//foundation/ability/ability_runtime/ability_runtime.gni") +module_output_path = "ability_runtime/abilitymgr" + +##############################fuzztest########################################## +ohos_fuzztest("DialogSessionManagerThirdFuzzTest") { + module_out_path = module_output_path + + fuzz_config_file = + "${ability_runtime_test_path}/fuzztest/dialogsessionmanagerthird_fuzzer" + include_dirs = [ + "${ability_runtime_innerkits_path}/ability_manager/include", + "${ability_runtime_services_path}/abilitymgr/include/utils", + "${ability_runtime_services_path}/abilitymgr/include", + ] + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + sources = [ + "${ability_runtime_path}/services/abilitymgr/src/dialog_session/dialog_session_manager.cpp", + "${ability_runtime_services_path}/abilitymgr/src/utils/start_ability_utils.cpp", + "dialogsessionmanagerthird_fuzzer.cpp", + ] + + configs = [ + "${ability_runtime_innerkits_path}/ability_manager:ability_manager_public_config", + "${ability_runtime_services_path}/abilitymgr:abilityms_config", + ] + cflags = [] + if (target_cpu == "arm") { + cflags += [ "-DBINDER_IPC_32BIT" ] + } + deps = [ + "${ability_runtime_innerkits_path}/ability_manager:ability_manager", + "${ability_runtime_innerkits_path}/ability_manager:ability_start_options", + "${ability_runtime_innerkits_path}/app_manager:app_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:perm_verification", + ] + + external_deps = [ + "ability_base:want", + "ability_base:zuri", + "bundle_framework:appexecfwk_base", + "bundle_framework:appexecfwk_core", + "c_utils:utils", + "common_event_service:cesfwk_innerkits", + "ffrt:libffrt", + "hilog:libhilog", + "hisysevent:libhisysevent", + "hitrace:hitrace_meter", + "ipc:ipc_core", + "libjpeg-turbo:turbojpeg", + "napi:ace_napi", + "safwk:system_ability_fwk", + "samgr:samgr_proxy", + "window_manager:libmodal_system_ui_extension_client", + "window_manager:libwsutils", + ] + + if (background_task_mgr_continuous_task_enable) { + external_deps += [ "background_task_mgr:bgtaskmgr_innerkits" ] + } + + if (ability_runtime_graphics) { + external_deps += [ "window_manager:libwm" ] + } +} + +############################################################################### +group("fuzztest") { + testonly = true + deps = [] + deps += [ + # deps file + ":DialogSessionManagerThirdFuzzTest", + ] +} +############################################################################### diff --git a/test/fuzztest/dialogsessionmanagerthird_fuzzer/corpus/init b/test/fuzztest/dialogsessionmanagerthird_fuzzer/corpus/init new file mode 100644 index 0000000000000000000000000000000000000000..7ade8a0faafeaedba7241e7d4a97b8e1f9691932 --- /dev/null +++ b/test/fuzztest/dialogsessionmanagerthird_fuzzer/corpus/init @@ -0,0 +1,16 @@ +/* + * 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. + */ + +FUZZ \ No newline at end of file diff --git a/test/fuzztest/dialogsessionmanagerthird_fuzzer/dialogsessionmanagerthird_fuzzer.cpp b/test/fuzztest/dialogsessionmanagerthird_fuzzer/dialogsessionmanagerthird_fuzzer.cpp new file mode 100644 index 0000000000000000000000000000000000000000..cc7b8ad0e706da450540b94cec167611a0942882 --- /dev/null +++ b/test/fuzztest/dialogsessionmanagerthird_fuzzer/dialogsessionmanagerthird_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 "dialogsessionmanagerthird_fuzzer.h" +#include +#include +#include +#define private public +#include "dialog_session_manager.h" +#undef private +#include "ability_record.h" +#include "../ability_fuzz_util.h" + +using namespace OHOS::AAFwk; +using namespace OHOS::AppExecFwk; + +namespace OHOS { +namespace {} // namespace + +bool DoSomethingInterestingWithMyAPI(const uint8_t *data, size_t size) +{ + AbilityRequest info; + std::vector targetAbilityInfos; + FuzzedDataProvider fdp(data, size); + AbilityFuzzUtil::GetRandomAbilityRequestInfo(fdp, info); + std::shared_ptr dialogSessionManager = std::make_shared(); + if (dialogSessionManager == nullptr) { + return false; + } + dialogSessionManager->GenerateJumpTargetAbilityInfos(info, targetAbilityInfos); + return true; +} +} // namespace OHOS + +/* 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/dialogsessionmanagerthird_fuzzer/dialogsessionmanagerthird_fuzzer.h b/test/fuzztest/dialogsessionmanagerthird_fuzzer/dialogsessionmanagerthird_fuzzer.h new file mode 100644 index 0000000000000000000000000000000000000000..d37b63c330c995dda0d69f072bfbf51c7a0a3600 --- /dev/null +++ b/test/fuzztest/dialogsessionmanagerthird_fuzzer/dialogsessionmanagerthird_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 FUZZTEST_OHOS_ABILITY_RUNTIME_DIALOG_SESSION_MANAGER_THIRD_FUZZER_H +#define FUZZTEST_OHOS_ABILITY_RUNTIME_DIALOG_SESSION_MANAGER_THIRD_FUZZER_H + +#define FUZZ_PROJECT_NAME "dialogsessionmanagerthird_fuzzer" + +#endif \ No newline at end of file diff --git a/test/fuzztest/dialogsessionmanagerthird_fuzzer/project.xml b/test/fuzztest/dialogsessionmanagerthird_fuzzer/project.xml new file mode 100644 index 0000000000000000000000000000000000000000..e72711e004d1b6a902ef03aefb893632c6da1404 --- /dev/null +++ b/test/fuzztest/dialogsessionmanagerthird_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 600 + + 4096 + + \ No newline at end of file