diff --git a/test/fuzztest/BUILD.gn b/test/fuzztest/BUILD.gn index 189721e789c112387267c050b4e59b1212bcc76b..f91c148de47fcb528ddf971ad543b94445f4dacf 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", + "connectionobserverclientimplfifth_fuzzer:fuzztest", + "connectionobserverclientimplfirst_fuzzer:fuzztest", + "connectionobserverclientimplfourth_fuzzer:fuzztest", + "connectionobserverclientimplsecond_fuzzer:fuzztest", + "connectionobserverclientimplthird_fuzzer:fuzztest", "connectionstatemanager_fuzzer:fuzztest", "continueability_fuzzer:fuzztest", "continuemission_fuzzer:fuzztest", diff --git a/test/fuzztest/BUILD.gn.rej b/test/fuzztest/BUILD.gn.rej new file mode 100644 index 0000000000000000000000000000000000000000..2d0702976524378dd8cfd2b08c2fa3c4d76acc49 --- /dev/null +++ b/test/fuzztest/BUILD.gn.rej @@ -0,0 +1,13 @@ +diff a/test/fuzztest/BUILD.gn b/test/fuzztest/BUILD.gn (rejected hunks) +@@ -295,6 +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", + "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 e39e4612458e9e0e24061abbe3d96e8af5eedeb5..d15b795df4234bb7e80a4e534ea1e5368f6d9f41 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/ability_fuzz_util.h.rej b/test/fuzztest/ability_fuzz_util.h.rej new file mode 100644 index 0000000000000000000000000000000000000000..08d283b0de269068826b38de7bc8c6580f6dccf8 --- /dev/null +++ b/test/fuzztest/ability_fuzz_util.h.rej @@ -0,0 +1,49 @@ +diff a/test/fuzztest/ability_fuzz_util.h b/test/fuzztest/ability_fuzz_util.h (rejected hunks) +@@ -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/bundlemgrhelper_fuzzer/BUILD.gn b/test/fuzztest/bundlemgrhelper_fuzzer/BUILD.gn old mode 100755 new mode 100644 index aacddf509805d1997b1a754608ae6c24bcaf4ff7..5893eb00e542caea93b4d8ac34df95b04b31fe08 --- a/test/fuzztest/bundlemgrhelper_fuzzer/BUILD.gn +++ b/test/fuzztest/bundlemgrhelper_fuzzer/BUILD.gn @@ -101,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 a6731b31a3925d34cb6bb0a3527a3e698c8d3eee..e0207ed9cc258316464dac413882da3648b04279 --- a/test/fuzztest/bundlemgrhelper_fuzzer/bundlemgrhelper_fuzzer.cpp +++ b/test/fuzztest/bundlemgrhelper_fuzzer/bundlemgrhelper_fuzzer.cpp @@ -17,13 +17,11 @@ #include #include - #define private public #define protected public #include "bundle_mgr_helper.h" #undef protected #undef private - #include "ability_record.h" using namespace OHOS::AAFwk; @@ -187,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 cd4a7ce47a9d658723ffb6ce5bbdce2e5531b952..d2585184d700690e9a7a08f0e17ffac3a7d15089 --- 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 diff --git a/test/fuzztest/bundlemgrhelper_fuzzer/project.xml b/test/fuzztest/bundlemgrhelper_fuzzer/project.xml index 7133b2b92440904a5ed04b838733acea0f97486a..c234074435b41c3b28d9e46a592916d292c6c583 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 0000000000000000000000000000000000000000..dbaafde4131039734ef0f942f84d72e31108b255 --- /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 0000000000000000000000000000000000000000..b46b30ddcc4b6846c7a268c1155ae40651985be2 --- /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 0000000000000000000000000000000000000000..1369f655448e5b33ccc37527933eef015ebe8f63 --- /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 0000000000000000000000000000000000000000..7ade8a0faafeaedba7241e7d4a97b8e1f9691932 --- /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 0000000000000000000000000000000000000000..4a9e5e0e8a11651fe5994c426bebaa63a1c7a980 --- /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 0000000000000000000000000000000000000000..bb4e5a3eaac0be27059540578f6e45f2cd15da6b --- /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 0000000000000000000000000000000000000000..da84774d7cb266cd1ea21fead422da444c60f8e4 --- /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 0000000000000000000000000000000000000000..5c17854cf30282b5a6fb0c993dfaae93f1dc2b48 --- /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 0000000000000000000000000000000000000000..7ade8a0faafeaedba7241e7d4a97b8e1f9691932 --- /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 0000000000000000000000000000000000000000..4a9e5e0e8a11651fe5994c426bebaa63a1c7a980 --- /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 0000000000000000000000000000000000000000..19a311b86597a71c3be3a9485ef50c070b8ac17a --- /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 0000000000000000000000000000000000000000..e8f777315841e1cf469b712506b241ed29658f9f --- /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 0000000000000000000000000000000000000000..58e944c0c2359be8dcfd57e1b688200bf86d4912 --- /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 0000000000000000000000000000000000000000..7ade8a0faafeaedba7241e7d4a97b8e1f9691932 --- /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 0000000000000000000000000000000000000000..4a9e5e0e8a11651fe5994c426bebaa63a1c7a980 --- /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 0000000000000000000000000000000000000000..4c15da388c993313a39f669fa42fa350aaaff407 --- /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 0000000000000000000000000000000000000000..01db20e6f304c1f2ca2b4e954da9e09747871b93 --- /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 0000000000000000000000000000000000000000..09216435fee51655a00530068f4dea4d576d34bb --- /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 0000000000000000000000000000000000000000..7ade8a0faafeaedba7241e7d4a97b8e1f9691932 --- /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 0000000000000000000000000000000000000000..4a9e5e0e8a11651fe5994c426bebaa63a1c7a980 --- /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 0000000000000000000000000000000000000000..182191a8017d2621980102aa7e8a030c797970e3 --- /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 0000000000000000000000000000000000000000..3920aff8116b368642fdd8d080954e2dc6c59279 --- /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 0000000000000000000000000000000000000000..c54ab7d059fef45e3e3fa5e39a551ad5a639a7aa --- /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 0000000000000000000000000000000000000000..7ade8a0faafeaedba7241e7d4a97b8e1f9691932 --- /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 0000000000000000000000000000000000000000..4a9e5e0e8a11651fe5994c426bebaa63a1c7a980 --- /dev/null +++ b/test/fuzztest/connectionobserverclientimplthird_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 600 + + 4096 + +