From 9ee2a253d9c4b0c8394c9437ee92e6e76a19626f Mon Sep 17 00:00:00 2001 From: zhaoyrr Date: Tue, 1 Jul 2025 21:44:15 +0800 Subject: [PATCH 1/2] add fuzz Signed-off-by: zhaoyrr Change-Id: Ib13e43350083bf04a81c86812da5d7d99954f891 --- test/fuzztest/BUILD.gn | 5 + test/fuzztest/ability_fuzz_util.h | 34 +++++++ .../appexitreasonhelper_fuzzer.cpp | 35 +++++++ .../appexitreasonhelper_fuzzer.h | 0 .../appexitreasonhelper_fuzzer/corpus/init | 16 ++++ .../appexitreasonhelper_fuzzer/project.xml | 25 +++++ test/fuzztest/bundlemgrhelper_fuzzer/BUILD.gn | 4 +- .../bundlemgrhelper_fuzzer.cpp | 72 +++++++++++++- .../bundlemgrhelper_fuzzer.h | 2 +- .../bundlemgrhelper_fuzzer/corpus/init | 2 +- .../bundlemgrhelper_fuzzer/project.xml | 4 +- .../BUILD.gn | 96 +++++++++++++++++++ ...nnectionobserverclientimplfifth_fuzzer.cpp | 71 ++++++++++++++ ...connectionobserverclientimplfifth_fuzzer.h | 21 ++++ .../corpus/init | 16 ++++ .../project.xml | 25 +++++ .../BUILD.gn | 96 +++++++++++++++++++ ...nnectionobserverclientimplfirst_fuzzer.cpp | 66 +++++++++++++ ...connectionobserverclientimplfirst_fuzzer.h | 21 ++++ .../corpus/init | 16 ++++ .../project.xml | 25 +++++ .../BUILD.gn | 96 +++++++++++++++++++ ...nectionobserverclientimplfourth_fuzzer.cpp | 65 +++++++++++++ ...onnectionobserverclientimplfourth_fuzzer.h | 21 ++++ .../corpus/init | 16 ++++ .../project.xml | 25 +++++ .../BUILD.gn | 96 +++++++++++++++++++ ...nectionobserverclientimplsecond_fuzzer.cpp | 66 +++++++++++++ ...onnectionobserverclientimplsecond_fuzzer.h | 21 ++++ .../corpus/init | 16 ++++ .../project.xml | 25 +++++ .../BUILD.gn | 96 +++++++++++++++++++ ...nnectionobserverclientimplthird_fuzzer.cpp | 67 +++++++++++++ ...connectionobserverclientimplthird_fuzzer.h | 21 ++++ .../corpus/init | 16 ++++ .../project.xml | 25 +++++ 36 files changed, 1314 insertions(+), 10 deletions(-) create mode 100644 test/fuzztest/appexitreasonhelper_fuzzer/appexitreasonhelper_fuzzer.cpp create mode 100644 test/fuzztest/appexitreasonhelper_fuzzer/appexitreasonhelper_fuzzer.h create mode 100755 test/fuzztest/appexitreasonhelper_fuzzer/corpus/init create mode 100755 test/fuzztest/appexitreasonhelper_fuzzer/project.xml create mode 100644 test/fuzztest/connectionobserverclientimplfifth_fuzzer/BUILD.gn create mode 100644 test/fuzztest/connectionobserverclientimplfifth_fuzzer/connectionobserverclientimplfifth_fuzzer.cpp create mode 100644 test/fuzztest/connectionobserverclientimplfifth_fuzzer/connectionobserverclientimplfifth_fuzzer.h create mode 100755 test/fuzztest/connectionobserverclientimplfifth_fuzzer/corpus/init create mode 100755 test/fuzztest/connectionobserverclientimplfifth_fuzzer/project.xml create mode 100644 test/fuzztest/connectionobserverclientimplfirst_fuzzer/BUILD.gn create mode 100644 test/fuzztest/connectionobserverclientimplfirst_fuzzer/connectionobserverclientimplfirst_fuzzer.cpp create mode 100644 test/fuzztest/connectionobserverclientimplfirst_fuzzer/connectionobserverclientimplfirst_fuzzer.h create mode 100644 test/fuzztest/connectionobserverclientimplfirst_fuzzer/corpus/init create mode 100644 test/fuzztest/connectionobserverclientimplfirst_fuzzer/project.xml create mode 100644 test/fuzztest/connectionobserverclientimplfourth_fuzzer/BUILD.gn create mode 100644 test/fuzztest/connectionobserverclientimplfourth_fuzzer/connectionobserverclientimplfourth_fuzzer.cpp create mode 100644 test/fuzztest/connectionobserverclientimplfourth_fuzzer/connectionobserverclientimplfourth_fuzzer.h create mode 100644 test/fuzztest/connectionobserverclientimplfourth_fuzzer/corpus/init create mode 100644 test/fuzztest/connectionobserverclientimplfourth_fuzzer/project.xml create mode 100644 test/fuzztest/connectionobserverclientimplsecond_fuzzer/BUILD.gn create mode 100644 test/fuzztest/connectionobserverclientimplsecond_fuzzer/connectionobserverclientimplsecond_fuzzer.cpp create mode 100644 test/fuzztest/connectionobserverclientimplsecond_fuzzer/connectionobserverclientimplsecond_fuzzer.h create mode 100644 test/fuzztest/connectionobserverclientimplsecond_fuzzer/corpus/init create mode 100644 test/fuzztest/connectionobserverclientimplsecond_fuzzer/project.xml create mode 100644 test/fuzztest/connectionobserverclientimplthird_fuzzer/BUILD.gn create mode 100644 test/fuzztest/connectionobserverclientimplthird_fuzzer/connectionobserverclientimplthird_fuzzer.cpp create mode 100644 test/fuzztest/connectionobserverclientimplthird_fuzzer/connectionobserverclientimplthird_fuzzer.h create mode 100644 test/fuzztest/connectionobserverclientimplthird_fuzzer/corpus/init create mode 100644 test/fuzztest/connectionobserverclientimplthird_fuzzer/project.xml diff --git a/test/fuzztest/BUILD.gn b/test/fuzztest/BUILD.gn index 189721e789c..338c52c5a61 100644 --- a/test/fuzztest/BUILD.gn +++ b/test/fuzztest/BUILD.gn @@ -295,6 +295,11 @@ group("fuzztest") { "completefirstframedrawing_fuzzer:fuzztest", "connectability_fuzzer:fuzztest", "connectionobserverclient_fuzzer:fuzztest", + "connectionobserverclientimplfirst_fuzzer:fuzztest", + "connectionobserverclientimplsecond_fuzzer:fuzztest", + "connectionobserverclientimplthird_fuzzer:fuzztest", + "connectionobserverclientimplfourth_fuzzer:fuzztest", + "connectionobserverclientimplfifth_fuzzer:fuzztest", "connectionstatemanager_fuzzer:fuzztest", "continueability_fuzzer:fuzztest", "continuemission_fuzzer:fuzztest", diff --git a/test/fuzztest/ability_fuzz_util.h b/test/fuzztest/ability_fuzz_util.h index e39e4612458..d15b795df42 100644 --- a/test/fuzztest/ability_fuzz_util.h +++ b/test/fuzztest/ability_fuzz_util.h @@ -24,6 +24,9 @@ #include "auto_startup_info.h" #include "bundle_info.h" #include "bundle_user_info.h" +#include "dlp_connection_info.h" +#include "dlp_state_data.h" +#include "extract_insight_intent_profile.h" #include "keep_alive_process_manager.h" namespace OHOS { @@ -67,6 +70,37 @@ void GetRandomAutoStartupInfo(FuzzedDataProvider& fdp, AutoStartupInfo& info) info.accessTokenId = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH); } +void GetRandomDlpConnectionInfo(FuzzedDataProvider& fdp, DlpConnectionInfo& info) +{ + info.dlpUid = fdp.ConsumeIntegral(); + info.openedAbilityCount = fdp.ConsumeIntegral(); +} + +void GetRandomConnectionData(FuzzedDataProvider& fdp, ConnectionData& info) +{ + info.isSuspended = fdp.ConsumeBool(); + info.extensionPid = fdp.ConsumeIntegral(); + info.extensionUid = fdp.ConsumeIntegral(); + info.callerUid = fdp.ConsumeIntegral(); + info.callerPid = fdp.ConsumeIntegral(); + info.extensionBundleName = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH); + info.extensionModuleName = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH); + info.extensionName = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH); + info.callerName = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH); +} + +void GetRandomDlpStateData(FuzzedDataProvider& fdp, DlpStateData& info) +{ + info.targetPid = fdp.ConsumeIntegral(); + info.targetUid = fdp.ConsumeIntegral(); + info.callerUid = fdp.ConsumeIntegral(); + info.callerPid = fdp.ConsumeIntegral(); + info.callerName = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH); + info.targetBundleName = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH); + info.targetModuleName = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH); + info.targetAbilityName = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH); +} + void GetRandomBundleInfo(FuzzedDataProvider& fdp, BundleInfo& info) { info.isNewVersion = fdp.ConsumeBool(); diff --git a/test/fuzztest/appexitreasonhelper_fuzzer/appexitreasonhelper_fuzzer.cpp b/test/fuzztest/appexitreasonhelper_fuzzer/appexitreasonhelper_fuzzer.cpp new file mode 100644 index 00000000000..d423330e1e3 --- /dev/null +++ b/test/fuzztest/appexitreasonhelper_fuzzer/appexitreasonhelper_fuzzer.cpp @@ -0,0 +1,35 @@ +/* + * 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 "appexitreasonhelper_fuzzer.h" + + #include "app_exit_reason_helper.h" + +using namespace OHOS::AAFwk; +using namespace OHOS::AppExecFwk; +using namespace OHOS::AbilityRuntime; + +namespace OHOS { +namespace { +constexpr size_t STRING_MAX_LENGTH = 128; +} + +bool DoSomethingInterestingWithMyAPI(const uint8_t* data, size_t size) +{ + std::list> abilityRecords; + std::vector abilities; + return true; +} +} diff --git a/test/fuzztest/appexitreasonhelper_fuzzer/appexitreasonhelper_fuzzer.h b/test/fuzztest/appexitreasonhelper_fuzzer/appexitreasonhelper_fuzzer.h new file mode 100644 index 00000000000..e69de29bb2d diff --git a/test/fuzztest/appexitreasonhelper_fuzzer/corpus/init b/test/fuzztest/appexitreasonhelper_fuzzer/corpus/init new file mode 100755 index 00000000000..7ade8a0faaf --- /dev/null +++ b/test/fuzztest/appexitreasonhelper_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/appexitreasonhelper_fuzzer/project.xml b/test/fuzztest/appexitreasonhelper_fuzzer/project.xml new file mode 100755 index 00000000000..4a9e5e0e8a1 --- /dev/null +++ b/test/fuzztest/appexitreasonhelper_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 600 + + 4096 + + diff --git a/test/fuzztest/bundlemgrhelper_fuzzer/BUILD.gn b/test/fuzztest/bundlemgrhelper_fuzzer/BUILD.gn index aacddf50980..5eec72cd64b 100755 --- a/test/fuzztest/bundlemgrhelper_fuzzer/BUILD.gn +++ b/test/fuzztest/bundlemgrhelper_fuzzer/BUILD.gn @@ -1,4 +1,4 @@ -# Copyright (c) 2024-2025 Huawei Device Co., Ltd. +# 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 @@ -67,6 +67,8 @@ ohos_fuzztest("BundleMgrHelperFuzzTest") { "common_event_service:cesfwk_innerkits", "ffrt:libffrt", "hilog:libhilog", + "hisysevent:libhisysevent", + "safwk:system_ability_fwk", "hitrace:hitrace_meter", "hitrace:libhitracechain", "ipc:ipc_core", diff --git a/test/fuzztest/bundlemgrhelper_fuzzer/bundlemgrhelper_fuzzer.cpp b/test/fuzztest/bundlemgrhelper_fuzzer/bundlemgrhelper_fuzzer.cpp index a6731b31a39..d3d3a90cb95 100755 --- a/test/fuzztest/bundlemgrhelper_fuzzer/bundlemgrhelper_fuzzer.cpp +++ b/test/fuzztest/bundlemgrhelper_fuzzer/bundlemgrhelper_fuzzer.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2024 Huawei Device Co., Ltd. + * 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 @@ -17,20 +17,33 @@ #include #include - +#include #define private public #define protected public #include "bundle_mgr_helper.h" +#include "ability_keep_alive_service.h" +#include "bundle_info.h" +#include "main_thread.h" +#include +#include "connection_observer.h" +#include "../ability_fuzz_util.h" #undef protected #undef private - +#include "keep_alive_process_manager.h" +#include "ability_util.h" +#include "app_mgr_client.h" +#include "parameters.h" +#include "permission_verification.h" #include "ability_record.h" +#include "continuous_task_callback_info.h" +#include "../ability_fuzz_util.h" + using namespace OHOS::AAFwk; using namespace OHOS::AppExecFwk; using namespace OHOS::AbilityRuntime; -namespace OHOS { +namespace OHOS{ namespace { constexpr int INPUT_ZERO = 0; constexpr int INPUT_ONE = 1; @@ -40,6 +53,7 @@ constexpr uint8_t ENABLE = 2; constexpr size_t OFFSET_ZERO = 24; constexpr size_t OFFSET_ONE = 16; constexpr size_t OFFSET_TWO = 8; +constexpr size_t STRING_MAX_LENGTH = 128; } uint32_t GetU32Data(const char* ptr) @@ -154,8 +168,56 @@ bool DoSomethingInterestingWithMyAPI(const char* data, size_t size) BundleMgrHelperFuzztest2(boolParam, stringParam, int32Param); return true; } -} + +bool DoSomethingInterestingWithMyAPI(const uint8_t* data, size_t size) +{ + std::shared_ptr bmHelper = std::make_shared(); + std::string bundleName; + int32_t userId; + bool bmsReady; + std::string hostBundleName; + std::string pluginBundleName; + std::string pluginModuleName; + BundleInfo bundleInfo; + int32_t flags; + std::vector appIndexes; + SignatureInfo signatureInfo; + HapModuleInfo hapModuleInfo; + std::string moduleName; + int32_t resId; + int32_t appIndex; + sptr pluginEventCallback; + std::vector pluginBundleInfos; + FuzzedDataProvider fdp(data, size); + bundleName = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH); + hostBundleName = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH); + pluginBundleName = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH); + moduleName = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH); + pluginModuleName = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH); + userId = fdp.ConsumeIntegral(); + flags = fdp.ConsumeIntegral(); + resId = fdp.ConsumeIntegral(); + appIndex = fdp.ConsumeIntegral(); + bmsReady = fdp.ConsumeBool(); + AbilityFuzzUtil::GetRandomBundleInfo(fdp, bundleInfo); + AbilityFuzzUtil::GenerateSignatureInfo(fdp, signatureInfo); + bmHelper->PreConnect(); + bmHelper->GetAppIdByBundleName(bundleName, userId); + bmHelper->ConnectTillSuccess(); + bmHelper->SetBmsReady(bmsReady); + bmHelper->GetPluginHapModuleInfo(hostBundleName, pluginBundleName, pluginModuleName, userId, hapModuleInfo); + bmHelper->GetBundleInfoForSelfWithOutCache (flags, bundleInfo); + bmHelper->GetCloneAppIndexes(bundleName, appIndexes, userId); + bmHelper->GetSignatureInfoByBundleName(bundleName, signatureInfo); + bmHelper->GetStringById(bundleName, moduleName, resId, userId); + bmHelper->GetDataDir(bundleName, appIndex); + bmHelper->GetPluginInfosForSelf(pluginBundleInfos); + bmHelper->RegisterPluginEventCallback(pluginEventCallback); + bmHelper->UnregisterPluginEventCallback(pluginEventCallback); + return true; +} +} /* Fuzzer entry point */ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { diff --git a/test/fuzztest/bundlemgrhelper_fuzzer/bundlemgrhelper_fuzzer.h b/test/fuzztest/bundlemgrhelper_fuzzer/bundlemgrhelper_fuzzer.h index cd4a7ce47a9..50a2b2df801 100755 --- a/test/fuzztest/bundlemgrhelper_fuzzer/bundlemgrhelper_fuzzer.h +++ b/test/fuzztest/bundlemgrhelper_fuzzer/bundlemgrhelper_fuzzer.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2024 Huawei Device Co., Ltd. + * 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 diff --git a/test/fuzztest/bundlemgrhelper_fuzzer/corpus/init b/test/fuzztest/bundlemgrhelper_fuzzer/corpus/init index 6198079a28e..7ade8a0faaf 100755 --- a/test/fuzztest/bundlemgrhelper_fuzzer/corpus/init +++ b/test/fuzztest/bundlemgrhelper_fuzzer/corpus/init @@ -1,5 +1,5 @@ /* - * Copyright (c) 2024 Huawei Device Co., Ltd. + * 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 diff --git a/test/fuzztest/bundlemgrhelper_fuzzer/project.xml b/test/fuzztest/bundlemgrhelper_fuzzer/project.xml index 7133b2b9244..4a9e5e0e8a1 100755 --- a/test/fuzztest/bundlemgrhelper_fuzzer/project.xml +++ b/test/fuzztest/bundlemgrhelper_fuzzer/project.xml @@ -1,5 +1,5 @@ - 1000 - 300 + 600 4096 diff --git a/test/fuzztest/connectionobserverclientimplfifth_fuzzer/BUILD.gn b/test/fuzztest/connectionobserverclientimplfifth_fuzzer/BUILD.gn new file mode 100644 index 00000000000..dbaafde4131 --- /dev/null +++ b/test/fuzztest/connectionobserverclientimplfifth_fuzzer/BUILD.gn @@ -0,0 +1,96 @@ +# Copyright (c) 2025 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +#####################hydra-fuzz################### +import("//build/config/features.gni") +import("//build/ohos.gni") +import("//build/test.gni") +import("//foundation/ability/ability_runtime/ability_runtime.gni") +module_output_path = "ability_runtime/abilitymgr" + +##############################fuzztest########################################## +ohos_fuzztest("ConnectionObserverClientImplFifthFuzzTest") { + module_out_path = module_output_path + + fuzz_config_file = "${ability_runtime_test_path}/fuzztest/connectionobserverclientimplfifth_fuzzer" + include_dirs = [ + "${ability_runtime_innerkits_path}/ability_manager/include", + "${ability_runtime_innerkits_path}/dataobs_manager/include", + ] + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + sources = [ "connectionobserverclientimplfifth_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_native_path}/ability/native:abilitykit_native", + "${ability_runtime_services_path}/abilitymgr:abilityms", + ] + + external_deps = [ + "ability_base:want", + "ability_base:zuri", + "ability_runtime:connection_obs_manager", + "background_task_mgr:bgtaskmgr_innerkits", + "bundle_framework:appexecfwk_base", + "c_utils:utils", + "common_event_service:cesfwk_core", + "common_event_service:cesfwk_innerkits", + "ffrt:libffrt", + "hisysevent:libhisysevent", + "input:libmmi-client", + "ipc:ipc_core", + "napi:ace_napi", + "relational_store:native_dataability", + "relational_store:native_rdb", + "safwk:system_ability_fwk", + "samgr:samgr_proxy", + ] + + if (ability_runtime_graphics) { + deps += [] + external_deps += [ + "i18n:intl_util", + "window_manager:libwm", + ] + } + if (ability_runtime_upms) { + deps += [ + "${ability_runtime_innerkits_path}/uri_permission:uri_permission_mgr", + ] + } + cflags_cc = [] + if (os_dlp_part_enabled) { + cflags_cc += [ "-DWITH_DLP" ] + } +} + +############################################################################### +group("fuzztest") { + testonly = true + deps = [] + deps += [ + # deps file + ":ConnectionObserverClientImplFifthFuzzTest", + ] +} +############################################################################### diff --git a/test/fuzztest/connectionobserverclientimplfifth_fuzzer/connectionobserverclientimplfifth_fuzzer.cpp b/test/fuzztest/connectionobserverclientimplfifth_fuzzer/connectionobserverclientimplfifth_fuzzer.cpp new file mode 100644 index 00000000000..b46b30ddcc4 --- /dev/null +++ b/test/fuzztest/connectionobserverclientimplfifth_fuzzer/connectionobserverclientimplfifth_fuzzer.cpp @@ -0,0 +1,71 @@ +/* + * 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 "connectionobserverclientimplfifth_fuzzer.h" + +#include +#include +#include + +#define private public +#define protected public +#include "connection_observer_client_impl.h" +#include "service_proxy_adapter.h" +#undef protected +#undef private + +#include "ability_record.h" +#include "continuous_task_callback_info.h" +#include "connection_observer.h" +#include "../ability_fuzz_util.h" + +using namespace OHOS::AAFwk; +using namespace OHOS::AppExecFwk; +using namespace OHOS::AbilityRuntime; + +namespace OHOS { +namespace { +constexpr size_t STRING_MAX_LENGTH = 128; +} + +bool DoSomethingInterestingWithMyAPI(const uint8_t* data, size_t size) +{ + auto connectionObserverClientImpl = std::make_shared(); + std::shared_ptr observer; + wptr remote; + FuzzedDataProvider fdp(data, size); + connectionObserverClientImpl->RemoveObserversLocked(observer); + connectionObserverClientImpl->GetServiceProxy(); + connectionObserverClientImpl->ConnectLocked(); + connectionObserverClientImpl->HandleRemoteDied(remote); + connectionObserverClientImpl->ResetProxy(remote); + connectionObserverClientImpl->ResetStatus(); + connectionObserverClientImpl->NotifyServiceDiedToObservers(); + connectionObserverClientImpl->GetObservers(); + auto deathRecipient = new (std::nothrow) AbilityRuntime::ConnectionObserverClientImpl::ServiceDeathRecipient( + connectionObserverClientImpl); + deathRecipient->OnRemoteDied(remote); + 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; +} + diff --git a/test/fuzztest/connectionobserverclientimplfifth_fuzzer/connectionobserverclientimplfifth_fuzzer.h b/test/fuzztest/connectionobserverclientimplfifth_fuzzer/connectionobserverclientimplfifth_fuzzer.h new file mode 100644 index 00000000000..1369f655448 --- /dev/null +++ b/test/fuzztest/connectionobserverclientimplfifth_fuzzer/connectionobserverclientimplfifth_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_CONNECTIONOBSERVERCLIENTIMPL_FIFTH_FUZZER_H +#define FUZZTEST_OHOS_ABILITY_RUNTIME_CONNECTIONOBSERVERCLIENTIMPL_FIFTH_FUZZER_H + +#define FUZZ_PROJECT_NAME "connectionobserverclientimplfifth_fuzzer" + +#endif // FUZZTEST_OHOS_ABILITY_RUNTIME_CONNECTIONOBSERVERCLIENTIMPL_FIFTH_FUZZER_H diff --git a/test/fuzztest/connectionobserverclientimplfifth_fuzzer/corpus/init b/test/fuzztest/connectionobserverclientimplfifth_fuzzer/corpus/init new file mode 100755 index 00000000000..7ade8a0faaf --- /dev/null +++ b/test/fuzztest/connectionobserverclientimplfifth_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/connectionobserverclientimplfifth_fuzzer/project.xml b/test/fuzztest/connectionobserverclientimplfifth_fuzzer/project.xml new file mode 100755 index 00000000000..4a9e5e0e8a1 --- /dev/null +++ b/test/fuzztest/connectionobserverclientimplfifth_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 600 + + 4096 + + diff --git a/test/fuzztest/connectionobserverclientimplfirst_fuzzer/BUILD.gn b/test/fuzztest/connectionobserverclientimplfirst_fuzzer/BUILD.gn new file mode 100644 index 00000000000..bb4e5a3eaac --- /dev/null +++ b/test/fuzztest/connectionobserverclientimplfirst_fuzzer/BUILD.gn @@ -0,0 +1,96 @@ +# Copyright (c) 2025 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +#####################hydra-fuzz################### +import("//build/config/features.gni") +import("//build/ohos.gni") +import("//build/test.gni") +import("//foundation/ability/ability_runtime/ability_runtime.gni") +module_output_path = "ability_runtime/abilitymgr" + +##############################fuzztest########################################## +ohos_fuzztest("ConnectionObserverClientImplFirstFuzzTest") { + module_out_path = module_output_path + + fuzz_config_file = "${ability_runtime_test_path}/fuzztest/connectionobserverclientimplfirst_fuzzer" + include_dirs = [ + "${ability_runtime_innerkits_path}/ability_manager/include", + "${ability_runtime_innerkits_path}/dataobs_manager/include", + ] + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + sources = [ "connectionobserverclientimplfirst_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_native_path}/ability/native:abilitykit_native", + "${ability_runtime_services_path}/abilitymgr:abilityms", + ] + + external_deps = [ + "ability_base:want", + "ability_base:zuri", + "ability_runtime:connection_obs_manager", + "background_task_mgr:bgtaskmgr_innerkits", + "bundle_framework:appexecfwk_base", + "c_utils:utils", + "common_event_service:cesfwk_core", + "common_event_service:cesfwk_innerkits", + "ffrt:libffrt", + "hisysevent:libhisysevent", + "input:libmmi-client", + "ipc:ipc_core", + "napi:ace_napi", + "relational_store:native_dataability", + "relational_store:native_rdb", + "safwk:system_ability_fwk", + "samgr:samgr_proxy", + ] + + if (ability_runtime_graphics) { + deps += [] + external_deps += [ + "i18n:intl_util", + "window_manager:libwm", + ] + } + if (ability_runtime_upms) { + deps += [ + "${ability_runtime_innerkits_path}/uri_permission:uri_permission_mgr", + ] + } + cflags_cc = [] + if (os_dlp_part_enabled) { + cflags_cc += [ "-DWITH_DLP" ] + } +} + +############################################################################### +group("fuzztest") { + testonly = true + deps = [] + deps += [ + # deps file + ":ConnectionObserverClientImplFirstFuzzTest", + ] +} +############################################################################### diff --git a/test/fuzztest/connectionobserverclientimplfirst_fuzzer/connectionobserverclientimplfirst_fuzzer.cpp b/test/fuzztest/connectionobserverclientimplfirst_fuzzer/connectionobserverclientimplfirst_fuzzer.cpp new file mode 100644 index 00000000000..da84774d7cb --- /dev/null +++ b/test/fuzztest/connectionobserverclientimplfirst_fuzzer/connectionobserverclientimplfirst_fuzzer.cpp @@ -0,0 +1,66 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "connectionobserverclientimplfirst_fuzzer.h" + +#include +#include +#include + +#define private public +#define protected public +#include "connection_observer_client_impl.h" +#include "service_proxy_adapter.h" +#undef protected +#undef private + +#include "ability_record.h" +#include "continuous_task_callback_info.h" +#include "connection_observer.h" +#include "../ability_fuzz_util.h" + +using namespace OHOS::AAFwk; +using namespace OHOS::AppExecFwk; +using namespace OHOS::AbilityRuntime; + +namespace OHOS { +namespace { +constexpr size_t STRING_MAX_LENGTH = 128; +} + +bool DoSomethingInterestingWithMyAPI(const uint8_t* data, size_t size) +{ + auto connectionObserverClientImpl = std::make_shared(); + std::vector infos; + DlpConnectionInfo info; + FuzzedDataProvider fdp(data, size); + size_t arraySize = fdp.ConsumeIntegralInRange(0, STRING_MAX_LENGTH); + for (size_t i = 0; i < arraySize; ++i) { + AbilityFuzzUtil::GetRandomDlpConnectionInfo(fdp, info); + infos.emplace_back(info); + } + connectionObserverClientImpl->GetDlpConnectionInfos(infos); + 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; +} + diff --git a/test/fuzztest/connectionobserverclientimplfirst_fuzzer/connectionobserverclientimplfirst_fuzzer.h b/test/fuzztest/connectionobserverclientimplfirst_fuzzer/connectionobserverclientimplfirst_fuzzer.h new file mode 100644 index 00000000000..5c17854cf30 --- /dev/null +++ b/test/fuzztest/connectionobserverclientimplfirst_fuzzer/connectionobserverclientimplfirst_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_CONNECTIONOBSERVERCLIENTIMPL_FIRST_FUZZER_H +#define FUZZTEST_OHOS_ABILITY_RUNTIME_CONNECTIONOBSERVERCLIENTIMPL_FIRST_FUZZER_H + +#define FUZZ_PROJECT_NAME "connectionobserverclientimplfirst_fuzzer" + +#endif // FUZZTEST_OHOS_ABILITY_RUNTIME_CONNECTIONOBSERVERCLIENTIMPL_FIRST_FUZZER_H diff --git a/test/fuzztest/connectionobserverclientimplfirst_fuzzer/corpus/init b/test/fuzztest/connectionobserverclientimplfirst_fuzzer/corpus/init new file mode 100644 index 00000000000..7ade8a0faaf --- /dev/null +++ b/test/fuzztest/connectionobserverclientimplfirst_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/connectionobserverclientimplfirst_fuzzer/project.xml b/test/fuzztest/connectionobserverclientimplfirst_fuzzer/project.xml new file mode 100644 index 00000000000..4a9e5e0e8a1 --- /dev/null +++ b/test/fuzztest/connectionobserverclientimplfirst_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 600 + + 4096 + + diff --git a/test/fuzztest/connectionobserverclientimplfourth_fuzzer/BUILD.gn b/test/fuzztest/connectionobserverclientimplfourth_fuzzer/BUILD.gn new file mode 100644 index 00000000000..19a311b8659 --- /dev/null +++ b/test/fuzztest/connectionobserverclientimplfourth_fuzzer/BUILD.gn @@ -0,0 +1,96 @@ +# Copyright (c) 2025 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +#####################hydra-fuzz################### +import("//build/config/features.gni") +import("//build/ohos.gni") +import("//build/test.gni") +import("//foundation/ability/ability_runtime/ability_runtime.gni") +module_output_path = "ability_runtime/abilitymgr" + +##############################fuzztest########################################## +ohos_fuzztest("ConnectionObserverClientImplFourthFuzzTest") { + module_out_path = module_output_path + + fuzz_config_file = "${ability_runtime_test_path}/fuzztest/connectionobserverclientimplfourth_fuzzer" + include_dirs = [ + "${ability_runtime_innerkits_path}/ability_manager/include", + "${ability_runtime_innerkits_path}/dataobs_manager/include", + ] + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + sources = [ "connectionobserverclientimplfourth_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_native_path}/ability/native:abilitykit_native", + "${ability_runtime_services_path}/abilitymgr:abilityms", + ] + + external_deps = [ + "ability_base:want", + "ability_base:zuri", + "ability_runtime:connection_obs_manager", + "background_task_mgr:bgtaskmgr_innerkits", + "bundle_framework:appexecfwk_base", + "c_utils:utils", + "common_event_service:cesfwk_core", + "common_event_service:cesfwk_innerkits", + "ffrt:libffrt", + "hisysevent:libhisysevent", + "input:libmmi-client", + "ipc:ipc_core", + "napi:ace_napi", + "relational_store:native_dataability", + "relational_store:native_rdb", + "safwk:system_ability_fwk", + "samgr:samgr_proxy", + ] + + if (ability_runtime_graphics) { + deps += [] + external_deps += [ + "i18n:intl_util", + "window_manager:libwm", + ] + } + if (ability_runtime_upms) { + deps += [ + "${ability_runtime_innerkits_path}/uri_permission:uri_permission_mgr", + ] + } + cflags_cc = [] + if (os_dlp_part_enabled) { + cflags_cc += [ "-DWITH_DLP" ] + } +} + +############################################################################### +group("fuzztest") { + testonly = true + deps = [] + deps += [ + # deps file + ":ConnectionObserverClientImplFourthFuzzTest", + ] +} +############################################################################### diff --git a/test/fuzztest/connectionobserverclientimplfourth_fuzzer/connectionobserverclientimplfourth_fuzzer.cpp b/test/fuzztest/connectionobserverclientimplfourth_fuzzer/connectionobserverclientimplfourth_fuzzer.cpp new file mode 100644 index 00000000000..e8f77731584 --- /dev/null +++ b/test/fuzztest/connectionobserverclientimplfourth_fuzzer/connectionobserverclientimplfourth_fuzzer.cpp @@ -0,0 +1,65 @@ +/* + * 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 "connectionobserverclientimplfourth_fuzzer.h" + +#include +#include +#include + +#define private public +#define protected public +#include "connection_observer_client_impl.h" +#include "service_proxy_adapter.h" +#undef protected +#undef private + +#include "ability_record.h" +#include "continuous_task_callback_info.h" +#include "connection_observer.h" +#include "../ability_fuzz_util.h" + +using namespace OHOS::AAFwk; +using namespace OHOS::AppExecFwk; +using namespace OHOS::AbilityRuntime; + +namespace OHOS { +namespace { +constexpr size_t STRING_MAX_LENGTH = 128; +} + +bool DoSomethingInterestingWithMyAPI(const uint8_t* data, size_t size) +{ + auto connectionObserverClientImpl = std::make_shared(); + std::shared_ptr observer; + std::shared_ptr proxy; + FuzzedDataProvider fdp(data, size); + connectionObserverClientImpl->RegisterObserver(observer); + connectionObserverClientImpl->UnregisterObserver(observer); + connectionObserverClientImpl->RegisterObserverToServiceLocked(proxy); + connectionObserverClientImpl->UnregisterFromServiceLocked(proxy); + connectionObserverClientImpl->AddObserversLocked(observer); + 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; +} + diff --git a/test/fuzztest/connectionobserverclientimplfourth_fuzzer/connectionobserverclientimplfourth_fuzzer.h b/test/fuzztest/connectionobserverclientimplfourth_fuzzer/connectionobserverclientimplfourth_fuzzer.h new file mode 100644 index 00000000000..58e944c0c23 --- /dev/null +++ b/test/fuzztest/connectionobserverclientimplfourth_fuzzer/connectionobserverclientimplfourth_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_CONNECTIONOBSERVERCLIENTIMPL_FOURTH_FUZZER_H +#define FUZZTEST_OHOS_ABILITY_RUNTIME_CONNECTIONOBSERVERCLIENTIMPL_FOURTH_FUZZER_H + +#define FUZZ_PROJECT_NAME "connectionobserverclientimplfourth_fuzzer" + +#endif // FUZZTEST_OHOS_ABILITY_RUNTIME_CONNECTIONOBSERVERCLIENTIMPL_FOURTH_FUZZER_H diff --git a/test/fuzztest/connectionobserverclientimplfourth_fuzzer/corpus/init b/test/fuzztest/connectionobserverclientimplfourth_fuzzer/corpus/init new file mode 100644 index 00000000000..7ade8a0faaf --- /dev/null +++ b/test/fuzztest/connectionobserverclientimplfourth_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/connectionobserverclientimplfourth_fuzzer/project.xml b/test/fuzztest/connectionobserverclientimplfourth_fuzzer/project.xml new file mode 100644 index 00000000000..4a9e5e0e8a1 --- /dev/null +++ b/test/fuzztest/connectionobserverclientimplfourth_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 600 + + 4096 + + diff --git a/test/fuzztest/connectionobserverclientimplsecond_fuzzer/BUILD.gn b/test/fuzztest/connectionobserverclientimplsecond_fuzzer/BUILD.gn new file mode 100644 index 00000000000..4c15da388c9 --- /dev/null +++ b/test/fuzztest/connectionobserverclientimplsecond_fuzzer/BUILD.gn @@ -0,0 +1,96 @@ +# Copyright (c) 2025 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +#####################hydra-fuzz################### +import("//build/config/features.gni") +import("//build/ohos.gni") +import("//build/test.gni") +import("//foundation/ability/ability_runtime/ability_runtime.gni") +module_output_path = "ability_runtime/abilitymgr" + +##############################fuzztest########################################## +ohos_fuzztest("ConnectionObserverClientImplSecondFuzzTest") { + module_out_path = module_output_path + + fuzz_config_file = "${ability_runtime_test_path}/fuzztest/connectionobserverclientimplsecond_fuzzer" + include_dirs = [ + "${ability_runtime_innerkits_path}/ability_manager/include", + "${ability_runtime_innerkits_path}/dataobs_manager/include", + ] + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + sources = [ "connectionobserverclientimplsecond_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_native_path}/ability/native:abilitykit_native", + "${ability_runtime_services_path}/abilitymgr:abilityms", + ] + + external_deps = [ + "ability_base:want", + "ability_base:zuri", + "ability_runtime:connection_obs_manager", + "background_task_mgr:bgtaskmgr_innerkits", + "bundle_framework:appexecfwk_base", + "c_utils:utils", + "common_event_service:cesfwk_core", + "common_event_service:cesfwk_innerkits", + "ffrt:libffrt", + "hisysevent:libhisysevent", + "input:libmmi-client", + "ipc:ipc_core", + "napi:ace_napi", + "relational_store:native_dataability", + "relational_store:native_rdb", + "safwk:system_ability_fwk", + "samgr:samgr_proxy", + ] + + if (ability_runtime_graphics) { + deps += [] + external_deps += [ + "i18n:intl_util", + "window_manager:libwm", + ] + } + if (ability_runtime_upms) { + deps += [ + "${ability_runtime_innerkits_path}/uri_permission:uri_permission_mgr", + ] + } + cflags_cc = [] + if (os_dlp_part_enabled) { + cflags_cc += [ "-DWITH_DLP" ] + } +} + +############################################################################### +group("fuzztest") { + testonly = true + deps = [] + deps += [ + # deps file + ":ConnectionObserverClientImplSecondFuzzTest", + ] +} +############################################################################### diff --git a/test/fuzztest/connectionobserverclientimplsecond_fuzzer/connectionobserverclientimplsecond_fuzzer.cpp b/test/fuzztest/connectionobserverclientimplsecond_fuzzer/connectionobserverclientimplsecond_fuzzer.cpp new file mode 100644 index 00000000000..01db20e6f30 --- /dev/null +++ b/test/fuzztest/connectionobserverclientimplsecond_fuzzer/connectionobserverclientimplsecond_fuzzer.cpp @@ -0,0 +1,66 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "connectionobserverclientimplsecond_fuzzer.h" + +#include +#include +#include + +#define private public +#define protected public +#include "connection_observer_client_impl.h" +#include "service_proxy_adapter.h" +#undef protected +#undef private + +#include "ability_record.h" +#include "continuous_task_callback_info.h" +#include "connection_observer.h" +#include "../ability_fuzz_util.h" + +using namespace OHOS::AAFwk; +using namespace OHOS::AppExecFwk; +using namespace OHOS::AbilityRuntime; + +namespace OHOS { +namespace { +constexpr size_t STRING_MAX_LENGTH = 128; +} + +bool DoSomethingInterestingWithMyAPI(const uint8_t* data, size_t size) +{ + auto connectionObserverClientImpl = std::make_shared(); + std::vector connectionData; + ConnectionData info; + FuzzedDataProvider fdp(data, size); + size_t arraySize = fdp.ConsumeIntegralInRange(0, STRING_MAX_LENGTH); + for (size_t i = 0; i < arraySize; ++i) { + AbilityFuzzUtil::GetRandomConnectionData(fdp, info); + connectionData.emplace_back(info); + } + connectionObserverClientImpl->GetConnectionData(connectionData); + 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; +} + diff --git a/test/fuzztest/connectionobserverclientimplsecond_fuzzer/connectionobserverclientimplsecond_fuzzer.h b/test/fuzztest/connectionobserverclientimplsecond_fuzzer/connectionobserverclientimplsecond_fuzzer.h new file mode 100644 index 00000000000..09216435fee --- /dev/null +++ b/test/fuzztest/connectionobserverclientimplsecond_fuzzer/connectionobserverclientimplsecond_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_CONNECTIONOBSERVERCLIENTIMPL_SECOND_FUZZER_H +#define FUZZTEST_OHOS_ABILITY_RUNTIME_CONNECTIONOBSERVERCLIENTIMPL_SECOND_FUZZER_H + +#define FUZZ_PROJECT_NAME "connectionobserverclientimplsecond_fuzzer" + +#endif // FUZZTEST_OHOS_ABILITY_RUNTIME_CONNECTIONOBSERVERCLIENTIMPL_SECOND_FUZZER_H diff --git a/test/fuzztest/connectionobserverclientimplsecond_fuzzer/corpus/init b/test/fuzztest/connectionobserverclientimplsecond_fuzzer/corpus/init new file mode 100644 index 00000000000..7ade8a0faaf --- /dev/null +++ b/test/fuzztest/connectionobserverclientimplsecond_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/connectionobserverclientimplsecond_fuzzer/project.xml b/test/fuzztest/connectionobserverclientimplsecond_fuzzer/project.xml new file mode 100644 index 00000000000..4a9e5e0e8a1 --- /dev/null +++ b/test/fuzztest/connectionobserverclientimplsecond_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 600 + + 4096 + + diff --git a/test/fuzztest/connectionobserverclientimplthird_fuzzer/BUILD.gn b/test/fuzztest/connectionobserverclientimplthird_fuzzer/BUILD.gn new file mode 100644 index 00000000000..182191a8017 --- /dev/null +++ b/test/fuzztest/connectionobserverclientimplthird_fuzzer/BUILD.gn @@ -0,0 +1,96 @@ +# Copyright (c) 2025 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +#####################hydra-fuzz################### +import("//build/config/features.gni") +import("//build/ohos.gni") +import("//build/test.gni") +import("//foundation/ability/ability_runtime/ability_runtime.gni") +module_output_path = "ability_runtime/abilitymgr" + +##############################fuzztest########################################## +ohos_fuzztest("ConnectionObserverClientImplThirdFuzzTest") { + module_out_path = module_output_path + + fuzz_config_file = "${ability_runtime_test_path}/fuzztest/connectionobserverclientimplthird_fuzzer" + include_dirs = [ + "${ability_runtime_innerkits_path}/ability_manager/include", + "${ability_runtime_innerkits_path}/dataobs_manager/include", + ] + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + sources = [ "connectionobserverclientimplthird_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_native_path}/ability/native:abilitykit_native", + "${ability_runtime_services_path}/abilitymgr:abilityms", + ] + + external_deps = [ + "ability_base:want", + "ability_base:zuri", + "ability_runtime:connection_obs_manager", + "background_task_mgr:bgtaskmgr_innerkits", + "bundle_framework:appexecfwk_base", + "c_utils:utils", + "common_event_service:cesfwk_core", + "common_event_service:cesfwk_innerkits", + "ffrt:libffrt", + "hisysevent:libhisysevent", + "input:libmmi-client", + "ipc:ipc_core", + "napi:ace_napi", + "relational_store:native_dataability", + "relational_store:native_rdb", + "safwk:system_ability_fwk", + "samgr:samgr_proxy", + ] + + if (ability_runtime_graphics) { + deps += [] + external_deps += [ + "i18n:intl_util", + "window_manager:libwm", + ] + } + if (ability_runtime_upms) { + deps += [ + "${ability_runtime_innerkits_path}/uri_permission:uri_permission_mgr", + ] + } + cflags_cc = [] + if (os_dlp_part_enabled) { + cflags_cc += [ "-DWITH_DLP" ] + } +} + +############################################################################### +group("fuzztest") { + testonly = true + deps = [] + deps += [ + # deps file + ":ConnectionObserverClientImplThirdFuzzTest", + ] +} +############################################################################### diff --git a/test/fuzztest/connectionobserverclientimplthird_fuzzer/connectionobserverclientimplthird_fuzzer.cpp b/test/fuzztest/connectionobserverclientimplthird_fuzzer/connectionobserverclientimplthird_fuzzer.cpp new file mode 100644 index 00000000000..3920aff8116 --- /dev/null +++ b/test/fuzztest/connectionobserverclientimplthird_fuzzer/connectionobserverclientimplthird_fuzzer.cpp @@ -0,0 +1,67 @@ +/* + * 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 "connectionobserverclientimplthird_fuzzer.h" + +#include +#include +#include + +#define private public +#define protected public +#include "connection_observer_client_impl.h" +#include "service_proxy_adapter.h" +#undef protected +#undef private + +#include "ability_record.h" +#include "continuous_task_callback_info.h" +#include "connection_observer.h" +#include "../ability_fuzz_util.h" + +using namespace OHOS::AAFwk; +using namespace OHOS::AppExecFwk; +using namespace OHOS::AbilityRuntime; + +namespace OHOS { +namespace { +constexpr size_t STRING_MAX_LENGTH = 128; +} + +bool DoSomethingInterestingWithMyAPI(const uint8_t* data, size_t size) +{ + auto connectionObserverClientImpl = std::make_shared(); + ConnectionData info; + DlpStateData infos; + FuzzedDataProvider fdp(data, size); + AbilityFuzzUtil::GetRandomConnectionData(fdp, info); + AbilityFuzzUtil::GetRandomDlpStateData(fdp, infos); + connectionObserverClientImpl->HandleExtensionConnected(info); + connectionObserverClientImpl->HandleExtensionDisconnected(info); + connectionObserverClientImpl->HandleExtensionSuspended(info); + connectionObserverClientImpl->HandleExtensionResumed(info); + connectionObserverClientImpl->HandleDlpAbilityOpened(infos); + 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; +} + diff --git a/test/fuzztest/connectionobserverclientimplthird_fuzzer/connectionobserverclientimplthird_fuzzer.h b/test/fuzztest/connectionobserverclientimplthird_fuzzer/connectionobserverclientimplthird_fuzzer.h new file mode 100644 index 00000000000..c54ab7d059f --- /dev/null +++ b/test/fuzztest/connectionobserverclientimplthird_fuzzer/connectionobserverclientimplthird_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_CONNECTIONOBSERVERCLIENTIMPL_THIRD_FUZZER_H +#define FUZZTEST_OHOS_ABILITY_RUNTIME_CONNECTIONOBSERVERCLIENTIMPL_THIRD_FUZZER_H + +#define FUZZ_PROJECT_NAME "connectionobserverclientimplthird_fuzzer" + +#endif // FUZZTEST_OHOS_ABILITY_RUNTIME_CONNECTIONOBSERVERCLIENTIMPL_THIRD_FUZZER_H diff --git a/test/fuzztest/connectionobserverclientimplthird_fuzzer/corpus/init b/test/fuzztest/connectionobserverclientimplthird_fuzzer/corpus/init new file mode 100644 index 00000000000..7ade8a0faaf --- /dev/null +++ b/test/fuzztest/connectionobserverclientimplthird_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/connectionobserverclientimplthird_fuzzer/project.xml b/test/fuzztest/connectionobserverclientimplthird_fuzzer/project.xml new file mode 100644 index 00000000000..4a9e5e0e8a1 --- /dev/null +++ b/test/fuzztest/connectionobserverclientimplthird_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 600 + + 4096 + + -- Gitee From 8e2fc13808b3cf03ebc175ac07175ae16d121a85 Mon Sep 17 00:00:00 2001 From: zhaoyrr Date: Tue, 1 Jul 2025 22:22:11 +0800 Subject: [PATCH 2/2] add Signed-off-by: zhaoyrr Change-Id: I5e5fd30af6216b59ad3b11dab7e484e35f97441f --- test/fuzztest/BUILD.gn | 4 +- .../appexitreasonhelper_fuzzer.cpp | 35 --------- .../appexitreasonhelper_fuzzer.h | 0 .../appexitreasonhelper_fuzzer/corpus/init | 16 ---- .../appexitreasonhelper_fuzzer/project.xml | 25 ------- test/fuzztest/bundlemgrhelper_fuzzer/BUILD.gn | 4 +- .../bundlemgrhelper_fuzzer.cpp | 73 +------------------ .../bundlemgrhelper_fuzzer.h | 2 +- 8 files changed, 8 insertions(+), 151 deletions(-) delete mode 100644 test/fuzztest/appexitreasonhelper_fuzzer/appexitreasonhelper_fuzzer.cpp delete mode 100644 test/fuzztest/appexitreasonhelper_fuzzer/appexitreasonhelper_fuzzer.h delete mode 100755 test/fuzztest/appexitreasonhelper_fuzzer/corpus/init delete mode 100755 test/fuzztest/appexitreasonhelper_fuzzer/project.xml mode change 100755 => 100644 test/fuzztest/bundlemgrhelper_fuzzer/BUILD.gn mode change 100755 => 100644 test/fuzztest/bundlemgrhelper_fuzzer/bundlemgrhelper_fuzzer.cpp mode change 100755 => 100644 test/fuzztest/bundlemgrhelper_fuzzer/bundlemgrhelper_fuzzer.h diff --git a/test/fuzztest/BUILD.gn b/test/fuzztest/BUILD.gn index 338c52c5a61..f91c148de47 100644 --- a/test/fuzztest/BUILD.gn +++ b/test/fuzztest/BUILD.gn @@ -295,11 +295,11 @@ group("fuzztest") { "completefirstframedrawing_fuzzer:fuzztest", "connectability_fuzzer:fuzztest", "connectionobserverclient_fuzzer:fuzztest", + "connectionobserverclientimplfifth_fuzzer:fuzztest", "connectionobserverclientimplfirst_fuzzer:fuzztest", + "connectionobserverclientimplfourth_fuzzer:fuzztest", "connectionobserverclientimplsecond_fuzzer:fuzztest", "connectionobserverclientimplthird_fuzzer:fuzztest", - "connectionobserverclientimplfourth_fuzzer:fuzztest", - "connectionobserverclientimplfifth_fuzzer:fuzztest", "connectionstatemanager_fuzzer:fuzztest", "continueability_fuzzer:fuzztest", "continuemission_fuzzer:fuzztest", diff --git a/test/fuzztest/appexitreasonhelper_fuzzer/appexitreasonhelper_fuzzer.cpp b/test/fuzztest/appexitreasonhelper_fuzzer/appexitreasonhelper_fuzzer.cpp deleted file mode 100644 index d423330e1e3..00000000000 --- a/test/fuzztest/appexitreasonhelper_fuzzer/appexitreasonhelper_fuzzer.cpp +++ /dev/null @@ -1,35 +0,0 @@ -/* - * 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 "appexitreasonhelper_fuzzer.h" - - #include "app_exit_reason_helper.h" - -using namespace OHOS::AAFwk; -using namespace OHOS::AppExecFwk; -using namespace OHOS::AbilityRuntime; - -namespace OHOS { -namespace { -constexpr size_t STRING_MAX_LENGTH = 128; -} - -bool DoSomethingInterestingWithMyAPI(const uint8_t* data, size_t size) -{ - std::list> abilityRecords; - std::vector abilities; - return true; -} -} diff --git a/test/fuzztest/appexitreasonhelper_fuzzer/appexitreasonhelper_fuzzer.h b/test/fuzztest/appexitreasonhelper_fuzzer/appexitreasonhelper_fuzzer.h deleted file mode 100644 index e69de29bb2d..00000000000 diff --git a/test/fuzztest/appexitreasonhelper_fuzzer/corpus/init b/test/fuzztest/appexitreasonhelper_fuzzer/corpus/init deleted file mode 100755 index 7ade8a0faaf..00000000000 --- a/test/fuzztest/appexitreasonhelper_fuzzer/corpus/init +++ /dev/null @@ -1,16 +0,0 @@ -/* - * 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/appexitreasonhelper_fuzzer/project.xml b/test/fuzztest/appexitreasonhelper_fuzzer/project.xml deleted file mode 100755 index 4a9e5e0e8a1..00000000000 --- a/test/fuzztest/appexitreasonhelper_fuzzer/project.xml +++ /dev/null @@ -1,25 +0,0 @@ - - - - - - 1000 - - 600 - - 4096 - - diff --git a/test/fuzztest/bundlemgrhelper_fuzzer/BUILD.gn b/test/fuzztest/bundlemgrhelper_fuzzer/BUILD.gn old mode 100755 new mode 100644 index 5eec72cd64b..8cad30e3784 --- a/test/fuzztest/bundlemgrhelper_fuzzer/BUILD.gn +++ b/test/fuzztest/bundlemgrhelper_fuzzer/BUILD.gn @@ -67,8 +67,6 @@ ohos_fuzztest("BundleMgrHelperFuzzTest") { "common_event_service:cesfwk_innerkits", "ffrt:libffrt", "hilog:libhilog", - "hisysevent:libhisysevent", - "safwk:system_ability_fwk", "hitrace:hitrace_meter", "hitrace:libhitracechain", "ipc:ipc_core", @@ -103,4 +101,4 @@ group("fuzztest") { ":BundleMgrHelperFuzzTest", ] } -############################################################################### +############################################################################### \ No newline at end of file diff --git a/test/fuzztest/bundlemgrhelper_fuzzer/bundlemgrhelper_fuzzer.cpp b/test/fuzztest/bundlemgrhelper_fuzzer/bundlemgrhelper_fuzzer.cpp old mode 100755 new mode 100644 index d3d3a90cb95..e0207ed9cc2 --- a/test/fuzztest/bundlemgrhelper_fuzzer/bundlemgrhelper_fuzzer.cpp +++ b/test/fuzztest/bundlemgrhelper_fuzzer/bundlemgrhelper_fuzzer.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2025 Huawei Device Co., Ltd. + * 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 @@ -17,33 +17,18 @@ #include #include -#include #define private public #define protected public #include "bundle_mgr_helper.h" -#include "ability_keep_alive_service.h" -#include "bundle_info.h" -#include "main_thread.h" -#include -#include "connection_observer.h" -#include "../ability_fuzz_util.h" #undef protected #undef private -#include "keep_alive_process_manager.h" -#include "ability_util.h" -#include "app_mgr_client.h" -#include "parameters.h" -#include "permission_verification.h" #include "ability_record.h" -#include "continuous_task_callback_info.h" -#include "../ability_fuzz_util.h" - using namespace OHOS::AAFwk; using namespace OHOS::AppExecFwk; using namespace OHOS::AbilityRuntime; -namespace OHOS{ +namespace OHOS { namespace { constexpr int INPUT_ZERO = 0; constexpr int INPUT_ONE = 1; @@ -53,7 +38,6 @@ constexpr uint8_t ENABLE = 2; constexpr size_t OFFSET_ZERO = 24; constexpr size_t OFFSET_ONE = 16; constexpr size_t OFFSET_TWO = 8; -constexpr size_t STRING_MAX_LENGTH = 128; } uint32_t GetU32Data(const char* ptr) @@ -168,56 +152,8 @@ bool DoSomethingInterestingWithMyAPI(const char* data, size_t size) BundleMgrHelperFuzztest2(boolParam, stringParam, int32Param); return true; } - - -bool DoSomethingInterestingWithMyAPI(const uint8_t* data, size_t size) -{ - std::shared_ptr bmHelper = std::make_shared(); - std::string bundleName; - int32_t userId; - bool bmsReady; - std::string hostBundleName; - std::string pluginBundleName; - std::string pluginModuleName; - BundleInfo bundleInfo; - int32_t flags; - std::vector appIndexes; - SignatureInfo signatureInfo; - HapModuleInfo hapModuleInfo; - std::string moduleName; - int32_t resId; - int32_t appIndex; - sptr pluginEventCallback; - std::vector pluginBundleInfos; - FuzzedDataProvider fdp(data, size); - bundleName = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH); - hostBundleName = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH); - pluginBundleName = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH); - moduleName = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH); - pluginModuleName = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH); - userId = fdp.ConsumeIntegral(); - flags = fdp.ConsumeIntegral(); - resId = fdp.ConsumeIntegral(); - appIndex = fdp.ConsumeIntegral(); - bmsReady = fdp.ConsumeBool(); - AbilityFuzzUtil::GetRandomBundleInfo(fdp, bundleInfo); - AbilityFuzzUtil::GenerateSignatureInfo(fdp, signatureInfo); - bmHelper->PreConnect(); - bmHelper->GetAppIdByBundleName(bundleName, userId); - bmHelper->ConnectTillSuccess(); - bmHelper->SetBmsReady(bmsReady); - bmHelper->GetPluginHapModuleInfo(hostBundleName, pluginBundleName, pluginModuleName, userId, hapModuleInfo); - bmHelper->GetBundleInfoForSelfWithOutCache (flags, bundleInfo); - bmHelper->GetCloneAppIndexes(bundleName, appIndexes, userId); - bmHelper->GetSignatureInfoByBundleName(bundleName, signatureInfo); - bmHelper->GetStringById(bundleName, moduleName, resId, userId); - bmHelper->GetDataDir(bundleName, appIndex); - bmHelper->GetPluginInfosForSelf(pluginBundleInfos); - bmHelper->RegisterPluginEventCallback(pluginEventCallback); - bmHelper->UnregisterPluginEventCallback(pluginEventCallback); - return true; -} } + /* Fuzzer entry point */ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { @@ -249,5 +185,4 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) free(ch); ch = nullptr; return 0; -} - +} \ No newline at end of file diff --git a/test/fuzztest/bundlemgrhelper_fuzzer/bundlemgrhelper_fuzzer.h b/test/fuzztest/bundlemgrhelper_fuzzer/bundlemgrhelper_fuzzer.h old mode 100755 new mode 100644 index 50a2b2df801..4010c643692 --- a/test/fuzztest/bundlemgrhelper_fuzzer/bundlemgrhelper_fuzzer.h +++ b/test/fuzztest/bundlemgrhelper_fuzzer/bundlemgrhelper_fuzzer.h @@ -18,4 +18,4 @@ #define FUZZ_PROJECT_NAME "bundlemgrhelper_fuzzer" -#endif // FUZZTEST_OHOS_ABILITY_RUNTIME_BUNDLEMGRHELPER_FUZZER_H +#endif // FUZZTEST_OHOS_ABILITY_RUNTIME_BUNDLEMGRHELPER_FUZZER_H \ No newline at end of file -- Gitee