From 18099ba5c4802489cc41d139f3a429895db18203 Mon Sep 17 00:00:00 2001 From: yanhuan Date: Wed, 25 Jun 2025 11:43:05 +0800 Subject: [PATCH] =?UTF-8?q?dialogsessionmanager=20fuzz=E7=94=A8=E4=BE=8B?= =?UTF-8?q?=E8=A1=A5=E5=85=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: yanhuan --- test/fuzztest/BUILD.gn | 2 + .../dialogsessionmanagerfirst_fuzzer/BUILD.gn | 101 ++++++++++++++++++ .../corpus/init | 16 +++ .../dialogsessionmanagerfirst_fuzzer.cpp | 65 +++++++++++ .../dialogsessionmanagerfirst_fuzzer.h | 21 ++++ .../project.xml | 25 +++++ 6 files changed, 230 insertions(+) create mode 100644 test/fuzztest/dialogsessionmanagerfirst_fuzzer/BUILD.gn create mode 100644 test/fuzztest/dialogsessionmanagerfirst_fuzzer/corpus/init create mode 100644 test/fuzztest/dialogsessionmanagerfirst_fuzzer/dialogsessionmanagerfirst_fuzzer.cpp create mode 100644 test/fuzztest/dialogsessionmanagerfirst_fuzzer/dialogsessionmanagerfirst_fuzzer.h create mode 100644 test/fuzztest/dialogsessionmanagerfirst_fuzzer/project.xml diff --git a/test/fuzztest/BUILD.gn b/test/fuzztest/BUILD.gn index 189721e789c..2d0f6e9e59a 100644 --- a/test/fuzztest/BUILD.gn +++ b/test/fuzztest/BUILD.gn @@ -303,6 +303,8 @@ group("fuzztest") { "deeplinkreserveconfig_fuzzer:fuzztest", "delegatordoabilityforeground_fuzzer:fuzztest", "dialogsessioninfo_fuzzer:fuzztest", + "dialogsessionmanager_fuzzer", + "dialogsessionmanagerfirst_fuzzer", "disposedobserver_fuzzer:fuzztest", "doabilitybackground_fuzzer:fuzztest", "doabilityforeground_fuzzer:fuzztest", diff --git a/test/fuzztest/dialogsessionmanagerfirst_fuzzer/BUILD.gn b/test/fuzztest/dialogsessionmanagerfirst_fuzzer/BUILD.gn new file mode 100644 index 00000000000..9b55196c97f --- /dev/null +++ b/test/fuzztest/dialogsessionmanagerfirst_fuzzer/BUILD.gn @@ -0,0 +1,101 @@ +# 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", + "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 00000000000..6198079a28e --- /dev/null +++ b/test/fuzztest/dialogsessionmanagerfirst_fuzzer/corpus/init @@ -0,0 +1,16 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +FUZZ \ No newline at end of file diff --git a/test/fuzztest/dialogsessionmanagerfirst_fuzzer/dialogsessionmanagerfirst_fuzzer.cpp b/test/fuzztest/dialogsessionmanagerfirst_fuzzer/dialogsessionmanagerfirst_fuzzer.cpp new file mode 100644 index 00000000000..2764b4deeb3 --- /dev/null +++ b/test/fuzztest/dialogsessionmanagerfirst_fuzzer/dialogsessionmanagerfirst_fuzzer.cpp @@ -0,0 +1,65 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "dialogsessionmanagerfirst_fuzzer.h" +#include +#include +#include +#include "dialog_session_manager.h" +#include "ability_record.h" + +using namespace OHOS::AAFwk; +using namespace OHOS::AppExecFwk; + +namespace OHOS { +namespace {} // 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 abilityRequest; + sptr callerToken = GetFuzzAbilityToken(); + FuzzedDataProvider fdp(data, size); + bool isSCBCall = fdp.ConsumeBool(); + std::shared_ptr dialogSessionManager = std::make_shared(); + if (dialogSessionManager == nullptr) { + return false; + } + dialogSessionManager->UpdateExtensionWantWithDialogCallerInfo(abilityRequest, callerToken, isSCBCall); + 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(ch, 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 00000000000..df24110260a --- /dev/null +++ b/test/fuzztest/dialogsessionmanagerfirst_fuzzer/dialogsessionmanagerfirst_fuzzer.h @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#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 00000000000..6d3e765c7dc --- /dev/null +++ b/test/fuzztest/dialogsessionmanagerfirst_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + \ No newline at end of file -- Gitee