From ba2fd87f60cbb57c6523bf59620d9c8249dc2be9 Mon Sep 17 00:00:00 2001 From: sunxuhui Date: Mon, 15 Jul 2024 17:41:55 +0800 Subject: [PATCH] add fuzz Signed-off-by: sunxuhui --- test/fuzztest/BUILD.gn | 6 + .../BUILD.gn | 92 ++++++++++++++ ...itymgrpreloaduiextstateobserver_fuzzer.cpp | 78 ++++++++++++ ...ilitymgrpreloaduiextstateobserver_fuzzer.h | 21 ++++ .../corpus/init | 16 +++ .../project.xml | 25 ++++ .../fuzztest/assertfaultproxy_fuzzer/BUILD.gn | 88 +++++++++++++ .../assertfaultproxy_fuzzer.cpp | 117 ++++++++++++++++++ .../assertfaultproxy_fuzzer.h | 21 ++++ .../assertfaultproxy_fuzzer/corpus/init | 16 +++ .../assertfaultproxy_fuzzer/project.xml | 25 ++++ test/fuzztest/autostartupinfo_fuzzer/BUILD.gn | 85 +++++++++++++ .../autostartupinfo_fuzzer.cpp | 92 ++++++++++++++ .../autostartupinfo_fuzzer.h | 21 ++++ .../autostartupinfo_fuzzer/corpus/init | 16 +++ .../autostartupinfo_fuzzer/project.xml | 25 ++++ .../dialogsessioninfo_fuzzer/BUILD.gn | 82 ++++++++++++ .../dialogsessioninfo_fuzzer/corpus/init | 16 +++ .../dialogsessioninfo_fuzzer.cpp | 91 ++++++++++++++ .../dialogsessioninfo_fuzzer.h | 21 ++++ .../dialogsessioninfo_fuzzer/project.xml | 25 ++++ test/fuzztest/extensionconfig_fuzzer/BUILD.gn | 86 +++++++++++++ .../extensionconfig_fuzzer/corpus/init | 16 +++ .../extensionconfig_fuzzer.cpp | 102 +++++++++++++++ .../extensionconfig_fuzzer.h | 21 ++++ .../extensionconfig_fuzzer/project.xml | 25 ++++ .../toolstestobserver_fuzzer/BUILD.gn | 54 ++++++++ .../toolstestobserver_fuzzer/corpus/init | 16 +++ .../toolstestobserver_fuzzer/project.xml | 25 ++++ .../toolstestobserver_fuzzer.cpp | 98 +++++++++++++++ .../toolstestobserver_fuzzer.h | 21 ++++ 31 files changed, 1443 insertions(+) create mode 100644 test/fuzztest/abilitymgrpreloaduiextstateobserver_fuzzer/BUILD.gn create mode 100644 test/fuzztest/abilitymgrpreloaduiextstateobserver_fuzzer/abilitymgrpreloaduiextstateobserver_fuzzer.cpp create mode 100644 test/fuzztest/abilitymgrpreloaduiextstateobserver_fuzzer/abilitymgrpreloaduiextstateobserver_fuzzer.h create mode 100644 test/fuzztest/abilitymgrpreloaduiextstateobserver_fuzzer/corpus/init create mode 100644 test/fuzztest/abilitymgrpreloaduiextstateobserver_fuzzer/project.xml create mode 100644 test/fuzztest/assertfaultproxy_fuzzer/BUILD.gn create mode 100644 test/fuzztest/assertfaultproxy_fuzzer/assertfaultproxy_fuzzer.cpp create mode 100644 test/fuzztest/assertfaultproxy_fuzzer/assertfaultproxy_fuzzer.h create mode 100644 test/fuzztest/assertfaultproxy_fuzzer/corpus/init create mode 100644 test/fuzztest/assertfaultproxy_fuzzer/project.xml create mode 100644 test/fuzztest/autostartupinfo_fuzzer/BUILD.gn create mode 100644 test/fuzztest/autostartupinfo_fuzzer/autostartupinfo_fuzzer.cpp create mode 100644 test/fuzztest/autostartupinfo_fuzzer/autostartupinfo_fuzzer.h create mode 100644 test/fuzztest/autostartupinfo_fuzzer/corpus/init create mode 100644 test/fuzztest/autostartupinfo_fuzzer/project.xml create mode 100644 test/fuzztest/dialogsessioninfo_fuzzer/BUILD.gn create mode 100644 test/fuzztest/dialogsessioninfo_fuzzer/corpus/init create mode 100644 test/fuzztest/dialogsessioninfo_fuzzer/dialogsessioninfo_fuzzer.cpp create mode 100644 test/fuzztest/dialogsessioninfo_fuzzer/dialogsessioninfo_fuzzer.h create mode 100644 test/fuzztest/dialogsessioninfo_fuzzer/project.xml create mode 100644 test/fuzztest/extensionconfig_fuzzer/BUILD.gn create mode 100644 test/fuzztest/extensionconfig_fuzzer/corpus/init create mode 100644 test/fuzztest/extensionconfig_fuzzer/extensionconfig_fuzzer.cpp create mode 100644 test/fuzztest/extensionconfig_fuzzer/extensionconfig_fuzzer.h create mode 100644 test/fuzztest/extensionconfig_fuzzer/project.xml create mode 100644 test/fuzztest/toolstestobserver_fuzzer/BUILD.gn create mode 100644 test/fuzztest/toolstestobserver_fuzzer/corpus/init create mode 100644 test/fuzztest/toolstestobserver_fuzzer/project.xml create mode 100644 test/fuzztest/toolstestobserver_fuzzer/toolstestobserver_fuzzer.cpp create mode 100644 test/fuzztest/toolstestobserver_fuzzer/toolstestobserver_fuzzer.h diff --git a/test/fuzztest/BUILD.gn b/test/fuzztest/BUILD.gn index c3b6b2de52..b6217b4ed7 100644 --- a/test/fuzztest/BUILD.gn +++ b/test/fuzztest/BUILD.gn @@ -33,6 +33,7 @@ group("fuzztest") { "abilitymanagerservicesecond_fuzzer:fuzztest", "abilitymanagerservicesixth_fuzzer:fuzztest", "abilitymanagerservicethird_fuzzer:fuzztest", + "abilitymgrpreloaduiextstateobserver_fuzzer:fuzztest", "abilitymgrrest_fuzzer:fuzztest", "abilityrunningrecord_fuzzer:fuzztest", "abilitystubabilityrecovery_fuzzer:fuzztest", @@ -172,8 +173,10 @@ group("fuzztest") { "appmgrclientrest_fuzzer:fuzztest", "appmgrrest_fuzzer:fuzztest", "appstateobservermanager_fuzzer:fuzztest", + "assertfaultproxy_fuzzer:fuzztest", "attachabilitythread_fuzzer:fuzztest", "attachrenderprocess_fuzzer:fuzztest", + "autostartupinfo_fuzzer:fuzztest", "blockability_fuzzer:fuzztest", "blockamsservice_fuzzer:fuzztest", "blockappservice_fuzzer:fuzztest", @@ -191,11 +194,13 @@ group("fuzztest") { "continuemission_fuzzer:fuzztest", "dataabilitymanager_fuzzer:fuzztest", "delegatordoabilityforeground_fuzzer:fuzztest", + "dialogsessioninfo_fuzzer:fuzztest", "doabilitybackground_fuzzer:fuzztest", "doabilityforeground_fuzzer:fuzztest", "dumpabilityinfodone_fuzzer:fuzztest", "dumpstate_fuzzer:fuzztest", "dumpsysstate_fuzzer:fuzztest", + "extensionconfig_fuzzer:fuzztest", "forcetimeoutfortest_fuzzer:fuzztest", "freeinstallabilityfromremote_fuzzer:fuzztest", "getabilityrunninginfos_fuzzer:fuzztest", @@ -264,6 +269,7 @@ group("fuzztest") { "stopuser_fuzzer:fuzztest", "systemabilitytokencallbackstub_fuzzer:fuzztest", "terminateability_fuzzer:fuzztest", + "toolstestobserver_fuzzer:fuzztest", "unlockmissionforcleanup_fuzzer:fuzztest", "unregisterabilitylifecyclecallback_fuzzer:fuzztest", "unregisterapplicationstateobserver_fuzzer:fuzztest", diff --git a/test/fuzztest/abilitymgrpreloaduiextstateobserver_fuzzer/BUILD.gn b/test/fuzztest/abilitymgrpreloaduiextstateobserver_fuzzer/BUILD.gn new file mode 100644 index 0000000000..45d1f3d15a --- /dev/null +++ b/test/fuzztest/abilitymgrpreloaduiextstateobserver_fuzzer/BUILD.gn @@ -0,0 +1,92 @@ +# Copyright (c) 2024 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +#####################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("AbilitymgrPreloadUiextStateObserverFuzzTest") { + module_out_path = module_output_path + + fuzz_config_file = "${ability_runtime_test_path}/fuzztest/abilitymgrpreloaduiextstateobserver_fuzzer" + include_dirs = [ + "${ability_runtime_innerkits_path}/ability_manager/include", + "${ability_runtime_services_path}/abilitymgr/include", + ] + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + sources = [ + "${ability_runtime_innerkits_path}/app_manager/src/appmgr/ability_state_data.cpp", + "${ability_runtime_innerkits_path}/app_manager/src/appmgr/app_mgr_client.cpp", + "${ability_runtime_innerkits_path}/app_manager/src/appmgr/app_service_manager.cpp", + "${ability_runtime_innerkits_path}/app_manager/src/appmgr/app_state_data.cpp", + "${ability_runtime_innerkits_path}/app_manager/src/appmgr/application_state_observer_stub.cpp", + "${ability_runtime_innerkits_path}/app_manager/src/appmgr/page_state_data.cpp", + "${ability_runtime_innerkits_path}/app_manager/src/appmgr/process_data.cpp", + "${ability_runtime_services_path}/abilitymgr/src/extension_record.cpp", + "${ability_runtime_services_path}/abilitymgr/src/preload_uiext_state_observer.cpp", + "${bundlefwk_inner_api_path}/appexecfwk_base/src/application_info.cpp", + "abilitymgrpreloaduiextstateobserver_fuzzer.cpp", + ] + + configs = [ "${ability_runtime_innerkits_path}/ability_manager:ability_manager_public_config" ] + cflags = [] + if (target_cpu == "arm") { + cflags += [ "-DBINDER_IPC_32BIT" ] + } + deps = [ + "${ability_runtime_innerkits_path}/ability_manager:ability_manager", + "${ability_runtime_innerkits_path}/ability_manager:ability_start_options", + "${ability_runtime_native_path}/ability/native:abilitykit_native", + "${ability_runtime_services_path}/abilitymgr:abilityms", + ] + + external_deps = [ + "ability_base:want", + "ability_base:zuri", + "bundle_framework:appexecfwk_base", + "bundle_framework:appexecfwk_core", + "c_utils:utils", + "common_event_service:cesfwk_innerkits", + "ffrt:libffrt", + "hilog:libhilog", + "hitrace:hitrace_meter", + "ipc:ipc_core", + "napi:ace_napi", + "safwk:system_ability_fwk", + "samgr:samgr_proxy", + ] + + if (ability_runtime_graphics) { + external_deps += [ "input:libmmi-client" ] + } +} + +############################################################################### +group("fuzztest") { + testonly = true + deps = [] + deps += [ + # deps file + ":AbilitymgrPreloadUiextStateObserverFuzzTest", + ] +} +############################################################################### diff --git a/test/fuzztest/abilitymgrpreloaduiextstateobserver_fuzzer/abilitymgrpreloaduiextstateobserver_fuzzer.cpp b/test/fuzztest/abilitymgrpreloaduiextstateobserver_fuzzer/abilitymgrpreloaduiextstateobserver_fuzzer.cpp new file mode 100644 index 0000000000..d7b0d96575 --- /dev/null +++ b/test/fuzztest/abilitymgrpreloaduiextstateobserver_fuzzer/abilitymgrpreloaduiextstateobserver_fuzzer.cpp @@ -0,0 +1,78 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "abilitymgrpreloaduiextstateobserver_fuzzer.h" + +#include +#include +#include "securec.h" +#include +#define private public +#include "preload_uiext_state_observer.h" +#undef private + +using namespace OHOS::AAFwk; +using namespace OHOS::AppExecFwk; + +namespace OHOS { +namespace { +constexpr size_t FOO_MAX_LEN = 1024; +constexpr size_t U32_AT_SIZE = 4; +} // namespace + +bool DoSomethingInterestingWithMyAPI(const char *data, size_t size) +{ + std::weak_ptr extensionRecord; + std::shared_ptr preLoadUIExtStateObserver = + std::make_shared(extensionRecord); + ProcessData processData; + preLoadUIExtStateObserver-> OnProcessDied(processData); + return true; +} +} // namespace OHOS + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) +{ + /* Run your code on data */ + if (data == nullptr) { + std::cout << "invalid data" << std::endl; + return 0; + } + + /* Validate the length of size */ + if (size > OHOS::FOO_MAX_LEN || size < OHOS::U32_AT_SIZE) { + return 0; + } + + char *ch = (char *)malloc(size + 1); + if (ch == nullptr) { + std::cout << "malloc failed." << std::endl; + return 0; + } + + (void)memset_s(ch, size + 1, 0x00, size + 1); + if (memcpy_s(ch, size + 1, data, size) != EOK) { + std::cout << "copy failed." << std::endl; + free(ch); + ch = nullptr; + return 0; + } + + OHOS::DoSomethingInterestingWithMyAPI(ch, size); + free(ch); + ch = nullptr; + return 0; +} \ No newline at end of file diff --git a/test/fuzztest/abilitymgrpreloaduiextstateobserver_fuzzer/abilitymgrpreloaduiextstateobserver_fuzzer.h b/test/fuzztest/abilitymgrpreloaduiextstateobserver_fuzzer/abilitymgrpreloaduiextstateobserver_fuzzer.h new file mode 100644 index 0000000000..644efe2fbe --- /dev/null +++ b/test/fuzztest/abilitymgrpreloaduiextstateobserver_fuzzer/abilitymgrpreloaduiextstateobserver_fuzzer.h @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef FUZZTEST_OHOS_ABILITY_RUNTIME_ABILITYMGRPRELOADUIEXTSTATEOBSERVER_FUZZER_H +#define FUZZTEST_OHOS_ABILITY_RUNTIME_ABILITYMGRPRELOADUIEXTSTATEOBSERVER_FUZZER_H + +#define FUZZ_PROJECT_NAME "abilitymgrpreloaduiextstateobserver_fuzzer" + +#endif diff --git a/test/fuzztest/abilitymgrpreloaduiextstateobserver_fuzzer/corpus/init b/test/fuzztest/abilitymgrpreloaduiextstateobserver_fuzzer/corpus/init new file mode 100644 index 0000000000..6198079a28 --- /dev/null +++ b/test/fuzztest/abilitymgrpreloaduiextstateobserver_fuzzer/corpus/init @@ -0,0 +1,16 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +FUZZ \ No newline at end of file diff --git a/test/fuzztest/abilitymgrpreloaduiextstateobserver_fuzzer/project.xml b/test/fuzztest/abilitymgrpreloaduiextstateobserver_fuzzer/project.xml new file mode 100644 index 0000000000..7133b2b924 --- /dev/null +++ b/test/fuzztest/abilitymgrpreloaduiextstateobserver_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/test/fuzztest/assertfaultproxy_fuzzer/BUILD.gn b/test/fuzztest/assertfaultproxy_fuzzer/BUILD.gn new file mode 100644 index 0000000000..bf1c3cca6e --- /dev/null +++ b/test/fuzztest/assertfaultproxy_fuzzer/BUILD.gn @@ -0,0 +1,88 @@ +# Copyright (c) 2024 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +#####################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("AssertFaultProxyFuzzTest") { + module_out_path = module_output_path + + fuzz_config_file = + "${ability_runtime_test_path}/fuzztest/assertfaultproxy_fuzzer" + include_dirs = [ + "${ability_runtime_innerkits_path}/ability_manager/include", + "${ability_runtime_services_path}/abilitymgr/include", + ] + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + sources = [ + "${ability_runtime_services_path}/abilitymgr/src/assert_fault_proxy.cpp", + "${ability_runtime_services_path}/common/src/ffrt_task_handler_wrap.cpp", + "${ability_runtime_services_path}/common/src/queue_task_handler_wrap.cpp", + "${ability_runtime_services_path}/common/src/task_handler_wrap.cpp", + "assertfaultproxy_fuzzer.cpp", + ] + + configs = [ "${ability_runtime_innerkits_path}/ability_manager:ability_manager_public_config" ] + cflags = [] + if (target_cpu == "arm") { + cflags += [ "-DBINDER_IPC_32BIT" ] + } + deps = [ + "${ability_runtime_innerkits_path}/ability_manager:ability_manager", + "${ability_runtime_innerkits_path}/ability_manager:ability_start_options", + "${ability_runtime_native_path}/ability/native:abilitykit_native", + "${ability_runtime_services_path}/abilitymgr:abilityms", + ] + + external_deps = [ + "ability_base:want", + "ability_base:zuri", + "bundle_framework:appexecfwk_base", + "bundle_framework:appexecfwk_core", + "c_utils:utils", + "common_event_service:cesfwk_innerkits", + "ffrt:libffrt", + "hilog:libhilog", + "hitrace:hitrace_meter", + "ipc:ipc_core", + "napi:ace_napi", + "safwk:system_ability_fwk", + "samgr:samgr_proxy", + "window_manager:libwsutils", + ] + + if (ability_runtime_graphics) { + external_deps += [ "input:libmmi-client" ] + } +} + +############################################################################### +group("fuzztest") { + testonly = true + deps = [] + deps += [ + # deps file + ":AssertFaultProxyFuzzTest", + ] +} +############################################################################### diff --git a/test/fuzztest/assertfaultproxy_fuzzer/assertfaultproxy_fuzzer.cpp b/test/fuzztest/assertfaultproxy_fuzzer/assertfaultproxy_fuzzer.cpp new file mode 100644 index 0000000000..6d077cf889 --- /dev/null +++ b/test/fuzztest/assertfaultproxy_fuzzer/assertfaultproxy_fuzzer.cpp @@ -0,0 +1,117 @@ +/* + * Copyright (c) 2022 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 "assertfaultproxy_fuzzer.h" + +#include +#include + +#define private public +#include "assert_fault_proxy.h" +#undef private +#include "ability_record.h" + +using namespace OHOS::AAFwk; +using namespace OHOS::AppExecFwk; + +namespace OHOS { +namespace { +constexpr int INPUT_ZERO = 0; +constexpr int INPUT_ONE = 1; +constexpr int INPUT_THREE = 3; +constexpr size_t FOO_MAX_LEN = 1024; +constexpr size_t U32_AT_SIZE = 4; +constexpr uint8_t ENABLE = 2; +constexpr size_t OFFSET_ZERO = 24; +constexpr size_t OFFSET_ONE = 16; +constexpr size_t OFFSET_TWO = 8; +} +uint32_t GetU32Data(const char* ptr) +{ + // convert fuzz input data to an integer + return (ptr[INPUT_ZERO] << OFFSET_ZERO) | (ptr[INPUT_ONE] << OFFSET_ONE) | (ptr[ENABLE] << OFFSET_TWO) | + ptr[INPUT_THREE]; +} + +bool DoSomethingInterestingWithMyAPI(const char* data, size_t size) +{ + AAFwk::UserStatus status = AAFwk::ASSERT_TERMINATE; + wptr remote; + sptr impl; + auto assertFaultProxy = std::make_shared(impl); + assertFaultProxy->NotifyDebugAssertResult(status); + + AbilityRuntime::AssertFaultRemoteDeathRecipient::RemoteDiedHandler handler; + auto assertFaultRemoteDeathRecipient = + std::make_shared(handler); + assertFaultRemoteDeathRecipient->OnRemoteDied(remote); + + auto modalSystemAssertUIExtension = std::make_shared(); + Want want; + modalSystemAssertUIExtension->CreateModalUIExtension(want); + + auto assertDialogConnection = + std::make_shared(); + assertDialogConnection->SetReqeustAssertDialogWant(want); + AppExecFwk::ElementName element; + sptr remoteObject; + int intParam = static_cast(GetU32Data(data)); + assertDialogConnection->OnAbilityConnectDone(element, remoteObject, intParam); + assertDialogConnection->OnAbilityDisconnectDone(element, intParam); + modalSystemAssertUIExtension->DisconnectSystemUI(); + modalSystemAssertUIExtension->TryNotifyOneWaitingThread(); + modalSystemAssertUIExtension->TryNotifyOneWaitingThreadInner(); + modalSystemAssertUIExtension->GetConnection(); + modalSystemAssertUIExtension->dialogConnectionCallback_ = nullptr; + modalSystemAssertUIExtension->GetConnection(); + + return true; +} +} // namespace OHOS + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data */ + if (data == nullptr) { + std::cout << "invalid data" << std::endl; + return 0; + } + + /* Validate the length of size */ + if (size > OHOS::FOO_MAX_LEN || size < OHOS::U32_AT_SIZE) { + return 0; + } + + char* ch = (char*)malloc(size + 1); + if (ch == nullptr) { + std::cout << "malloc failed." << std::endl; + return 0; + } + + (void)memset_s(ch, size + 1, 0x00, size + 1); + if (memcpy_s(ch, size + 1, data, size) != EOK) { + std::cout << "copy failed." << std::endl; + free(ch); + ch = nullptr; + return 0; + } + + OHOS::DoSomethingInterestingWithMyAPI(ch, size); + free(ch); + ch = nullptr; + return 0; +} + diff --git a/test/fuzztest/assertfaultproxy_fuzzer/assertfaultproxy_fuzzer.h b/test/fuzztest/assertfaultproxy_fuzzer/assertfaultproxy_fuzzer.h new file mode 100644 index 0000000000..72b1cc7082 --- /dev/null +++ b/test/fuzztest/assertfaultproxy_fuzzer/assertfaultproxy_fuzzer.h @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef FUZZTEST_OHOS_ABILITY_RUNTIME_ASSER_TFAULT_PROXY_FUZZER_H +#define FUZZTEST_OHOS_ABILITY_RUNTIME_ASSER_TFAULT_PROXY_FUZZER_H + +#define FUZZ_PROJECT_NAME "assertfaultproxy_fuzzer" + +#endif diff --git a/test/fuzztest/assertfaultproxy_fuzzer/corpus/init b/test/fuzztest/assertfaultproxy_fuzzer/corpus/init new file mode 100644 index 0000000000..6198079a28 --- /dev/null +++ b/test/fuzztest/assertfaultproxy_fuzzer/corpus/init @@ -0,0 +1,16 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +FUZZ \ No newline at end of file diff --git a/test/fuzztest/assertfaultproxy_fuzzer/project.xml b/test/fuzztest/assertfaultproxy_fuzzer/project.xml new file mode 100644 index 0000000000..7133b2b924 --- /dev/null +++ b/test/fuzztest/assertfaultproxy_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/test/fuzztest/autostartupinfo_fuzzer/BUILD.gn b/test/fuzztest/autostartupinfo_fuzzer/BUILD.gn new file mode 100644 index 0000000000..e5ad593681 --- /dev/null +++ b/test/fuzztest/autostartupinfo_fuzzer/BUILD.gn @@ -0,0 +1,85 @@ +# Copyright (c) 2024 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +#####################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("AutoStartupInfoFuzzTest") { + module_out_path = module_output_path + + fuzz_config_file = + "${ability_runtime_test_path}/fuzztest/autostartupinfo_fuzzer" + include_dirs = [ + "${ability_runtime_innerkits_path}/ability_manager/include", + "${ability_runtime_services_path}/abilitymgr/include", + ] + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + sources = [ + "${ability_runtime_services_path}/abilitymgr/src/auto_startup_info.cpp", + "autostartupinfo_fuzzer.cpp", + ] + + configs = [ "${ability_runtime_innerkits_path}/ability_manager:ability_manager_public_config" ] + cflags = [] + if (target_cpu == "arm") { + cflags += [ "-DBINDER_IPC_32BIT" ] + } + deps = [ + "${ability_runtime_innerkits_path}/ability_manager:ability_manager", + "${ability_runtime_innerkits_path}/ability_manager:ability_start_options", + "${ability_runtime_native_path}/ability/native:abilitykit_native", + "${ability_runtime_services_path}/abilitymgr:abilityms", + ] + + external_deps = [ + "ability_base:want", + "ability_base:zuri", + "bundle_framework:appexecfwk_base", + "bundle_framework:appexecfwk_core", + "c_utils:utils", + "common_event_service:cesfwk_innerkits", + "ffrt:libffrt", + "hilog:libhilog", + "hitrace:hitrace_meter", + "ipc:ipc_core", + "napi:ace_napi", + "safwk:system_ability_fwk", + "samgr:samgr_proxy", + "window_manager:libwsutils", + ] + + if (ability_runtime_graphics) { + external_deps += [ "input:libmmi-client" ] + } +} + +############################################################################### +group("fuzztest") { + testonly = true + deps = [] + deps += [ + # deps file + ":AutoStartupInfoFuzzTest", + ] +} +############################################################################### diff --git a/test/fuzztest/autostartupinfo_fuzzer/autostartupinfo_fuzzer.cpp b/test/fuzztest/autostartupinfo_fuzzer/autostartupinfo_fuzzer.cpp new file mode 100644 index 0000000000..a41bb3e202 --- /dev/null +++ b/test/fuzztest/autostartupinfo_fuzzer/autostartupinfo_fuzzer.cpp @@ -0,0 +1,92 @@ +/* + * Copyright (c) 2022 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 "autostartupinfo_fuzzer.h" + +#include +#include +#include + +#include "auto_startup_info.h" +#include "ability_record.h" +#include "securec.h" + +using namespace OHOS::AAFwk; +using namespace OHOS::AppExecFwk; +using namespace OHOS::AbilityRuntime; + +namespace OHOS { +namespace { +constexpr int INPUT_ZERO = 0; +constexpr int INPUT_ONE = 1; +constexpr int INPUT_THREE = 3; +constexpr size_t FOO_MAX_LEN = 1024; +constexpr size_t U32_AT_SIZE = 4; +constexpr uint8_t ENABLE = 2; +constexpr size_t OFFSET_ZERO = 24; +constexpr size_t OFFSET_ONE = 16; +constexpr size_t OFFSET_TWO = 8; +} +uint32_t GetU32Data(const char* ptr) +{ + // convert fuzz input data to an integer + return (ptr[INPUT_ZERO] << OFFSET_ZERO) | (ptr[INPUT_ONE] << OFFSET_ONE) | (ptr[ENABLE] << OFFSET_TWO) | + ptr[INPUT_THREE]; +} + +bool DoSomethingInterestingWithMyAPI(const char* data, size_t size) +{ + Parcel parcel; + auto autoStartupInfo = std::make_shared(); + autoStartupInfo->ReadFromParcel(parcel); + autoStartupInfo->Marshalling(parcel); + return true; +} +} // namespace OHOS + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data */ + if (data == nullptr) { + std::cout << "invalid data" << std::endl; + return 0; + } + + /* Validate the length of size */ + if (size > OHOS::FOO_MAX_LEN || size < OHOS::U32_AT_SIZE) { + return 0; + } + + char* ch = (char*)malloc(size + 1); + if (ch == nullptr) { + std::cout << "malloc failed." << std::endl; + return 0; + } + + (void)memset_s(ch, size + 1, 0x00, size + 1); + if (memcpy_s(ch, size + 1, data, size) != EOK) { + std::cout << "copy failed." << std::endl; + free(ch); + ch = nullptr; + return 0; + } + + OHOS::DoSomethingInterestingWithMyAPI(ch, size); + free(ch); + ch = nullptr; + return 0; +} + diff --git a/test/fuzztest/autostartupinfo_fuzzer/autostartupinfo_fuzzer.h b/test/fuzztest/autostartupinfo_fuzzer/autostartupinfo_fuzzer.h new file mode 100644 index 0000000000..e346aea5a3 --- /dev/null +++ b/test/fuzztest/autostartupinfo_fuzzer/autostartupinfo_fuzzer.h @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef FUZZTEST_OHOS_ABILITY_RUNTIME_AUTOSTARTUPINFO_FUZZER_H +#define FUZZTEST_OHOS_ABILITY_RUNTIME_AUTOSTARTUPINFO_FUZZER_H + +#define FUZZ_PROJECT_NAME "autostartupinfo_fuzzer" + +#endif diff --git a/test/fuzztest/autostartupinfo_fuzzer/corpus/init b/test/fuzztest/autostartupinfo_fuzzer/corpus/init new file mode 100644 index 0000000000..6198079a28 --- /dev/null +++ b/test/fuzztest/autostartupinfo_fuzzer/corpus/init @@ -0,0 +1,16 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +FUZZ \ No newline at end of file diff --git a/test/fuzztest/autostartupinfo_fuzzer/project.xml b/test/fuzztest/autostartupinfo_fuzzer/project.xml new file mode 100644 index 0000000000..7133b2b924 --- /dev/null +++ b/test/fuzztest/autostartupinfo_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/test/fuzztest/dialogsessioninfo_fuzzer/BUILD.gn b/test/fuzztest/dialogsessioninfo_fuzzer/BUILD.gn new file mode 100644 index 0000000000..2bcc724651 --- /dev/null +++ b/test/fuzztest/dialogsessioninfo_fuzzer/BUILD.gn @@ -0,0 +1,82 @@ +# Copyright (c) 2024 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +#####################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("DialogSessionInfoFuzzTest") { + module_out_path = module_output_path + + fuzz_config_file = + "${ability_runtime_test_path}/fuzztest/dialogsessioninfo_fuzzer" + include_dirs = [ + "${ability_runtime_innerkits_path}/ability_manager/include", + "${ability_runtime_services_path}/abilitymgr/include", + ] + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + sources = [ "dialogsessioninfo_fuzzer.cpp" ] + + configs = [ "${ability_runtime_innerkits_path}/ability_manager:ability_manager_public_config" ] + cflags = [] + if (target_cpu == "arm") { + cflags += [ "-DBINDER_IPC_32BIT" ] + } + deps = [ + "${ability_runtime_innerkits_path}/ability_manager:ability_manager", + "${ability_runtime_innerkits_path}/ability_manager:ability_start_options", + "${ability_runtime_native_path}/ability/native:abilitykit_native", + "${ability_runtime_services_path}/abilitymgr:abilityms", + ] + + external_deps = [ + "ability_base:want", + "ability_base:zuri", + "bundle_framework:appexecfwk_base", + "bundle_framework:appexecfwk_core", + "c_utils:utils", + "common_event_service:cesfwk_innerkits", + "ffrt:libffrt", + "hilog:libhilog", + "hitrace:hitrace_meter", + "ipc:ipc_core", + "napi:ace_napi", + "safwk:system_ability_fwk", + "samgr:samgr_proxy", + "window_manager:libwsutils", + ] + + if (ability_runtime_graphics) { + external_deps += [ "input:libmmi-client" ] + } +} + +############################################################################### +group("fuzztest") { + testonly = true + deps = [] + deps += [ + # deps file + ":DialogSessionInfoFuzzTest", + ] +} +############################################################################### diff --git a/test/fuzztest/dialogsessioninfo_fuzzer/corpus/init b/test/fuzztest/dialogsessioninfo_fuzzer/corpus/init new file mode 100644 index 0000000000..6198079a28 --- /dev/null +++ b/test/fuzztest/dialogsessioninfo_fuzzer/corpus/init @@ -0,0 +1,16 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +FUZZ \ No newline at end of file diff --git a/test/fuzztest/dialogsessioninfo_fuzzer/dialogsessioninfo_fuzzer.cpp b/test/fuzztest/dialogsessioninfo_fuzzer/dialogsessioninfo_fuzzer.cpp new file mode 100644 index 0000000000..7b8f60e9f7 --- /dev/null +++ b/test/fuzztest/dialogsessioninfo_fuzzer/dialogsessioninfo_fuzzer.cpp @@ -0,0 +1,91 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "dialogsessioninfo_fuzzer.h" + +#include +#include + +#include "dialog_session_info.h" + +#include "ability_record.h" + +using namespace OHOS::AAFwk; +using namespace OHOS::AppExecFwk; + +namespace OHOS { +namespace { +constexpr int INPUT_ZERO = 0; +constexpr int INPUT_ONE = 1; +constexpr int INPUT_TWO = 2; +constexpr int INPUT_THREE = 3; +constexpr size_t FOO_MAX_LEN = 1024; +constexpr size_t U32_AT_SIZE = 4; +constexpr size_t OFFSET_ZERO = 24; +constexpr size_t OFFSET_ONE = 16; +constexpr size_t OFFSET_TWO = 8; +constexpr uint8_t ENABLE = 2; +} // namespace + +uint32_t GetU32Data(const char* ptr) +{ + // convert fuzz input data to an integer + return (ptr[INPUT_ZERO] << OFFSET_ZERO) | (ptr[INPUT_ONE] << OFFSET_ONE) | (ptr[INPUT_TWO] << OFFSET_TWO) | + ptr[INPUT_THREE]; +} + +bool DoSomethingInterestingWithMyAPI(const char *data, size_t size) +{ + Parcel parcel; + auto dialogSessionInfo = std::make_shared(); + dialogSessionInfo->ReadFromParcel(parcel); + dialogSessionInfo->Marshalling(parcel); + return true; +} +} // namespace OHOS + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) +{ + /* Run your code on data */ + if (data == nullptr) { + std::cout << "invalid data" << std::endl; + return 0; + } + + /* Validate the length of size */ + if (size > OHOS::FOO_MAX_LEN || size < OHOS::U32_AT_SIZE) { + return 0; + } + + char *ch = (char *)malloc(size + 1); + if (ch == nullptr) { + std::cout << "malloc failed." << std::endl; + return 0; + } + + (void)memset_s(ch, size + 1, 0x00, size + 1); + if (memcpy_s(ch, size + 1 data, size) != EOK) { + std::cout << "copy failed." << std::endl; + free(ch); + ch = nullptr; + return 0; + } + + OHOS::DoSomethingInterestingWithMyAPI(ch, size); + free(ch); + ch = nullptr; + return 0; +} \ No newline at end of file diff --git a/test/fuzztest/dialogsessioninfo_fuzzer/dialogsessioninfo_fuzzer.h b/test/fuzztest/dialogsessioninfo_fuzzer/dialogsessioninfo_fuzzer.h new file mode 100644 index 0000000000..095195dded --- /dev/null +++ b/test/fuzztest/dialogsessioninfo_fuzzer/dialogsessioninfo_fuzzer.h @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef FUZZTEST_OHOS_ABILITY_RUNTIME_DIALOG_SESSION_INFO_FUZZER_H +#define FUZZTEST_OHOS_ABILITY_RUNTIME_DIALOG_SESSION_INFO_FUZZER_H + +#define FUZZ_PROJECT_NAME "dialogsessioninfo_fuzzer" + +#endif \ No newline at end of file diff --git a/test/fuzztest/dialogsessioninfo_fuzzer/project.xml b/test/fuzztest/dialogsessioninfo_fuzzer/project.xml new file mode 100644 index 0000000000..6d3e765c7d --- /dev/null +++ b/test/fuzztest/dialogsessioninfo_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + \ No newline at end of file diff --git a/test/fuzztest/extensionconfig_fuzzer/BUILD.gn b/test/fuzztest/extensionconfig_fuzzer/BUILD.gn new file mode 100644 index 0000000000..04b2d733f6 --- /dev/null +++ b/test/fuzztest/extensionconfig_fuzzer/BUILD.gn @@ -0,0 +1,86 @@ +# Copyright (c) 2024 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +#####################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("ExtensionConfigFuzzTest") { + module_out_path = module_output_path + + fuzz_config_file = + "${ability_runtime_test_path}/fuzztest/extensionconfig_fuzzer" + include_dirs = [ + "${ability_runtime_innerkits_path}/ability_manager/include", + "${ability_runtime_services_path}/abilitymgr/include", + ] + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + sources = [ + "${ability_runtime_services_path}/abilitymgr/src/extension_config.cpp", + "extensionconfig_fuzzer.cpp", + ] + + configs = [ "${ability_runtime_innerkits_path}/ability_manager:ability_manager_public_config" ] + cflags = [] + if (target_cpu == "arm") { + cflags += [ "-DBINDER_IPC_32BIT" ] + } + deps = [ + "${ability_runtime_innerkits_path}/ability_manager:ability_manager", + "${ability_runtime_innerkits_path}/ability_manager:ability_start_options", + "${ability_runtime_native_path}/ability/native:abilitykit_native", + "${ability_runtime_services_path}/abilitymgr:abilityms", + ] + + external_deps = [ + "ability_base:want", + "ability_base:zuri", + "bundle_framework:appexecfwk_base", + "bundle_framework:appexecfwk_core", + "c_utils:utils", + "common_event_service:cesfwk_innerkits", + "config_policy:configpolicy_util", + "ffrt:libffrt", + "hilog:libhilog", + "hitrace:hitrace_meter", + "ipc:ipc_core", + "napi:ace_napi", + "safwk:system_ability_fwk", + "samgr:samgr_proxy", + "window_manager:libwsutils", + ] + + if (ability_runtime_graphics) { + external_deps += [ "input:libmmi-client" ] + } +} + +############################################################################### +group("fuzztest") { + testonly = true + deps = [] + deps += [ + # deps file + ":ExtensionConfigFuzzTest", + ] +} +############################################################################### diff --git a/test/fuzztest/extensionconfig_fuzzer/corpus/init b/test/fuzztest/extensionconfig_fuzzer/corpus/init new file mode 100644 index 0000000000..6198079a28 --- /dev/null +++ b/test/fuzztest/extensionconfig_fuzzer/corpus/init @@ -0,0 +1,16 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +FUZZ \ No newline at end of file diff --git a/test/fuzztest/extensionconfig_fuzzer/extensionconfig_fuzzer.cpp b/test/fuzztest/extensionconfig_fuzzer/extensionconfig_fuzzer.cpp new file mode 100644 index 0000000000..0bc1d83a35 --- /dev/null +++ b/test/fuzztest/extensionconfig_fuzzer/extensionconfig_fuzzer.cpp @@ -0,0 +1,102 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "extensionconfig_fuzzer.h" + +#include +#include + +#include "ability_record.h" +#define private public +#include "extension_config.h" +#define private public + +using namespace OHOS::AAFwk; +using namespace OHOS::AppExecFwk; + +namespace OHOS { +namespace { +constexpr int INPUT_ZERO = 0; +constexpr int INPUT_ONE = 1; +constexpr int INPUT_TWO = 2; +constexpr int INPUT_THREE = 3; +constexpr size_t FOO_MAX_LEN = 1024; +constexpr size_t U32_AT_SIZE = 4; +constexpr size_t OFFSET_ZERO = 24; +constexpr size_t OFFSET_ONE = 16; +constexpr size_t OFFSET_TWO = 8; +constexpr uint8_t ENABLE = 2; +} // namespace + +uint32_t GetU32Data(const char* ptr) +{ + // convert fuzz input data to an integer + return (ptr[INPUT_ZERO] << OFFSET_ZERO) | (ptr[INPUT_ONE] << OFFSET_ONE) | (ptr[INPUT_TWO] << OFFSET_TWO) | + ptr[INPUT_THREE]; +} + +bool DoSomethingInterestingWithMyAPI(const char *data, size_t size) +{ + std::string strParam(data, size); + auto extensionConfig = std::make_shared(); + extensionConfig->LoadExtensionConfiguration(); + extensionConfig->GetExtensionAutoDisconnectTime(strParam); + extensionConfig->IsExtensionStartThirdPartyAppEnable(strParam); + extensionConfig->IsExtensionStartServiceEnable(strParam, strParam); + nlohmann::json object; + extensionConfig->LoadExtensionConfig(object); + extensionConfig->ReadFileInfoJson(strParam, object); + extensionConfig->GetExtensionConfigPath(); + extensionConfig->LoadExtensionAutoDisconnectTime(object, strParam); + extensionConfig->LoadExtensionThirdPartyAppBlockedList(object, strParam); + extensionConfig->LoadExtensionServiceBlockedList(object, strParam); + extensionConfig->CheckServiceExtensionUriValid(strParam); + return true; +} +} // namespace OHOS + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) +{ + /* Run your code on data */ + if (data == nullptr) { + std::cout << "invalid data" << std::endl; + return 0; + } + + /* Validate the length of size */ + if (size > OHOS::FOO_MAX_LEN || size < OHOS::U32_AT_SIZE) { + return 0; + } + + char *ch = (char *)malloc(size + 1); + if (ch == nullptr) { + std::cout << "malloc failed." << std::endl; + return 0; + } + + (void)memset_s(ch, size + 1, 0x00, size + 1); + if (memcpy_s(ch, size + 1, data, size) != EOK) { + std::cout << "copy failed." << std::endl; + free(ch); + ch = nullptr; + return 0; + } + + OHOS::DoSomethingInterestingWithMyAPI(ch, size); + free(ch); + ch = nullptr; + return 0; +} \ No newline at end of file diff --git a/test/fuzztest/extensionconfig_fuzzer/extensionconfig_fuzzer.h b/test/fuzztest/extensionconfig_fuzzer/extensionconfig_fuzzer.h new file mode 100644 index 0000000000..660360cf42 --- /dev/null +++ b/test/fuzztest/extensionconfig_fuzzer/extensionconfig_fuzzer.h @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef FUZZTEST_OHOS_ABILITY_RUNTIME_EXTENSION_CONFIG_FUZZER_H +#define FUZZTEST_OHOS_ABILITY_RUNTIME_EXTENSION_CONFIG_FUZZER_H + +#define FUZZ_PROJECT_NAME "extensionconfig_fuzzer" + +#endif \ No newline at end of file diff --git a/test/fuzztest/extensionconfig_fuzzer/project.xml b/test/fuzztest/extensionconfig_fuzzer/project.xml new file mode 100644 index 0000000000..6d3e765c7d --- /dev/null +++ b/test/fuzztest/extensionconfig_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + \ No newline at end of file diff --git a/test/fuzztest/toolstestobserver_fuzzer/BUILD.gn b/test/fuzztest/toolstestobserver_fuzzer/BUILD.gn new file mode 100644 index 0000000000..2c66524181 --- /dev/null +++ b/test/fuzztest/toolstestobserver_fuzzer/BUILD.gn @@ -0,0 +1,54 @@ +# Copyright (c) 2024 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +#####################hydra-fuzz################### +import("//build/test.gni") +import("//foundation/ability/ability_runtime/ability_runtime.gni") +module_output_path = "ability_runtime/abilitymgr" + +##############################fuzztest########################################## +ohos_fuzztest("ToolsTestObserverFuzzTest") { + module_out_path = module_output_path + fuzz_config_file = + "${ability_runtime_test_path}/fuzztest/toolstestobserver_fuzzer" + include_dirs = [] + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + configs = [] + sources = [ "toolstestobserver_fuzzer.cpp" ] + deps = [ + "${ability_runtime_path}/tools/aa:tools_aa_source_set", + "${ability_runtime_services_path}/abilitymgr:abilityms", + ] + external_deps = [ + "ability_base:configuration", + "bundle_framework:appexecfwk_base", + "hilog:libhilog", + "ipc:ipc_core", + ] +} + +############################################################################### +group("fuzztest") { + testonly = true + deps = [] + deps += [ + # deps file + ":ToolsTestObserverFuzzTest", + ] +} +############################################################################### diff --git a/test/fuzztest/toolstestobserver_fuzzer/corpus/init b/test/fuzztest/toolstestobserver_fuzzer/corpus/init new file mode 100644 index 0000000000..6198079a28 --- /dev/null +++ b/test/fuzztest/toolstestobserver_fuzzer/corpus/init @@ -0,0 +1,16 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +FUZZ \ No newline at end of file diff --git a/test/fuzztest/toolstestobserver_fuzzer/project.xml b/test/fuzztest/toolstestobserver_fuzzer/project.xml new file mode 100644 index 0000000000..7133b2b924 --- /dev/null +++ b/test/fuzztest/toolstestobserver_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/test/fuzztest/toolstestobserver_fuzzer/toolstestobserver_fuzzer.cpp b/test/fuzztest/toolstestobserver_fuzzer/toolstestobserver_fuzzer.cpp new file mode 100644 index 0000000000..156f4dc7bb --- /dev/null +++ b/test/fuzztest/toolstestobserver_fuzzer/toolstestobserver_fuzzer.cpp @@ -0,0 +1,98 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "toolstestobserver_fuzzer.h" + +#include +#include +#include "securec.h" +#include +#define private public +#include "test_observer.h" +#undef private + +using namespace OHOS::AAFwk; + +namespace OHOS { +namespace { +constexpr int INPUT_ZERO = 0; +constexpr int INPUT_ONE = 1; +constexpr int INPUT_TWO = 2; +constexpr int INPUT_THREE = 3; +constexpr size_t FOO_MAX_LEN = 1024; +constexpr size_t U32_AT_SIZE = 4; +constexpr size_t OFFSET_ZERO = 24; +constexpr size_t OFFSET_ONE = 16; +constexpr size_t OFFSET_TWO = 8; +} // namespace + +uint32_t GetU32Data(const char* ptr) +{ + // convert fuzz input data to an integer + return (ptr[INPUT_ZERO] << OFFSET_ZERO) | (ptr[INPUT_ONE] << OFFSET_ONE) | (ptr[INPUT_TWO] << OFFSET_TWO) | + ptr[INPUT_THREE]; +} + +bool DoSomethingInterestingWithMyAPI(const char *data, size_t size) +{ + std::shared_ptr testObserver = std::make_shared(); + std::string stringParam(data, size); + std::string cmd(data, size); + int64_t resultCode = static_cast(GetU32Data(data)); + int64_t timeoutSec = static_cast(GetU32Data(data)); + int64_t timeoutMs = static_cast(GetU32Data(data)); + + testObserver-> TestStatus(stringParam, resultCode); + testObserver-> ExecuteShellCommand(cmd, timeoutSec); + testObserver->TestFinished(stringParam, resultCode); + testObserver-> WaitForFinish(timeoutMs); + + return true; +} +} // namespace OHOS + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) +{ + /* Run your code on data */ + if (data == nullptr) { + std::cout << "invalid data" << std::endl; + return 0; + } + + /* Validate the length of size */ + if (size > OHOS::FOO_MAX_LEN || size < OHOS::U32_AT_SIZE) { + return 0; + } + + char *ch = (char *)malloc(size + 1); + if (ch == nullptr) { + std::cout << "malloc failed." << std::endl; + return 0; + } + + (void)memset_s(ch, size + 1, 0x00, size + 1); + if (memcpy_s(ch, size + 1, data, size) != EOK) { + std::cout << "copy failed." << std::endl; + free(ch); + ch = nullptr; + return 0; + } + + OHOS::DoSomethingInterestingWithMyAPI(ch, size); + free(ch); + ch = nullptr; + return 0; +} \ No newline at end of file diff --git a/test/fuzztest/toolstestobserver_fuzzer/toolstestobserver_fuzzer.h b/test/fuzztest/toolstestobserver_fuzzer/toolstestobserver_fuzzer.h new file mode 100644 index 0000000000..b4c41771a0 --- /dev/null +++ b/test/fuzztest/toolstestobserver_fuzzer/toolstestobserver_fuzzer.h @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef FUZZTEST_OHOS_ABILITY_RUNTIME_TOOLSTESTOBSERVER_FUZZER_H +#define FUZZTEST_OHOS_ABILITY_RUNTIME_TOOLSTESTOBSERVER_FUZZER_H + +#define FUZZ_PROJECT_NAME "toolstestobserver_fuzzer" + +#endif