From 5eebb9352bc26cffa87d2bfddba1797f53414441 Mon Sep 17 00:00:00 2001 From: zhoushicheng Date: Mon, 24 Oct 2022 03:03:49 +0000 Subject: [PATCH] Issue:#I5X9TN Signed-off-by: zhoushicheng Change-Id: I1f345fd6ad2138fba1582cd56e028b33a9e42ff0 --- test/fuzztest/BUILD.gn | 7 ++ .../killprocessesbybundlename_fuzzer/BUILD.gn | 78 ++++++++++++++ .../corpus/init | 16 +++ .../killprocessesbybundlename_fuzzer.cpp | 79 ++++++++++++++ .../killprocessesbybundlename_fuzzer.h | 21 ++++ .../project.xml | 25 +++++ .../releasedataability_fuzzer/BUILD.gn | 80 ++++++++++++++ .../releasedataability_fuzzer/corpus/init | 16 +++ .../releasedataability_fuzzer/project.xml | 25 +++++ .../releasedataability_fuzzer.cpp | 101 ++++++++++++++++++ .../releasedataability_fuzzer.h | 21 ++++ .../BUILD.gn | 76 +++++++++++++ .../corpus/init | 16 +++ .../project.xml | 25 +++++ .../schedulecommandabilitydone_fuzzer.cpp | 100 +++++++++++++++++ .../schedulecommandabilitydone_fuzzer.h | 21 ++++ .../BUILD.gn | 76 +++++++++++++ .../corpus/init | 16 +++ .../project.xml | 25 +++++ .../scheduleconnectabilitydone_fuzzer.cpp | 101 ++++++++++++++++++ .../scheduleconnectabilitydone_fuzzer.h | 21 ++++ .../BUILD.gn | 75 +++++++++++++ .../corpus/init | 16 +++ .../project.xml | 25 +++++ .../scheduledisconnectabilitydone_fuzzer.cpp | 100 +++++++++++++++++ .../scheduledisconnectabilitydone_fuzzer.h | 21 ++++ .../sendresulttoability_fuzzer/BUILD.gn | 76 +++++++++++++ .../sendresulttoability_fuzzer/corpus/init | 16 +++ .../sendresulttoability_fuzzer/project.xml | 25 +++++ .../sendresulttoability_fuzzer.cpp | 89 +++++++++++++++ .../sendresulttoability_fuzzer.h | 21 ++++ .../terminateabilityresult_fuzzer/BUILD.gn | 76 +++++++++++++ .../terminateabilityresult_fuzzer/corpus/init | 16 +++ .../terminateabilityresult_fuzzer/project.xml | 25 +++++ .../terminateabilityresult_fuzzer.cpp | 101 ++++++++++++++++++ .../terminateabilityresult_fuzzer.h | 21 ++++ 36 files changed, 1649 insertions(+) create mode 100644 test/fuzztest/killprocessesbybundlename_fuzzer/BUILD.gn create mode 100644 test/fuzztest/killprocessesbybundlename_fuzzer/corpus/init create mode 100644 test/fuzztest/killprocessesbybundlename_fuzzer/killprocessesbybundlename_fuzzer.cpp create mode 100644 test/fuzztest/killprocessesbybundlename_fuzzer/killprocessesbybundlename_fuzzer.h create mode 100644 test/fuzztest/killprocessesbybundlename_fuzzer/project.xml create mode 100644 test/fuzztest/releasedataability_fuzzer/BUILD.gn create mode 100644 test/fuzztest/releasedataability_fuzzer/corpus/init create mode 100644 test/fuzztest/releasedataability_fuzzer/project.xml create mode 100644 test/fuzztest/releasedataability_fuzzer/releasedataability_fuzzer.cpp create mode 100644 test/fuzztest/releasedataability_fuzzer/releasedataability_fuzzer.h create mode 100644 test/fuzztest/schedulecommandabilitydone_fuzzer/BUILD.gn create mode 100644 test/fuzztest/schedulecommandabilitydone_fuzzer/corpus/init create mode 100644 test/fuzztest/schedulecommandabilitydone_fuzzer/project.xml create mode 100644 test/fuzztest/schedulecommandabilitydone_fuzzer/schedulecommandabilitydone_fuzzer.cpp create mode 100644 test/fuzztest/schedulecommandabilitydone_fuzzer/schedulecommandabilitydone_fuzzer.h create mode 100644 test/fuzztest/scheduleconnectabilitydone_fuzzer/BUILD.gn create mode 100644 test/fuzztest/scheduleconnectabilitydone_fuzzer/corpus/init create mode 100644 test/fuzztest/scheduleconnectabilitydone_fuzzer/project.xml create mode 100644 test/fuzztest/scheduleconnectabilitydone_fuzzer/scheduleconnectabilitydone_fuzzer.cpp create mode 100644 test/fuzztest/scheduleconnectabilitydone_fuzzer/scheduleconnectabilitydone_fuzzer.h create mode 100644 test/fuzztest/scheduledisconnectabilitydone_fuzzer/BUILD.gn create mode 100644 test/fuzztest/scheduledisconnectabilitydone_fuzzer/corpus/init create mode 100644 test/fuzztest/scheduledisconnectabilitydone_fuzzer/project.xml create mode 100644 test/fuzztest/scheduledisconnectabilitydone_fuzzer/scheduledisconnectabilitydone_fuzzer.cpp create mode 100644 test/fuzztest/scheduledisconnectabilitydone_fuzzer/scheduledisconnectabilitydone_fuzzer.h create mode 100644 test/fuzztest/sendresulttoability_fuzzer/BUILD.gn create mode 100644 test/fuzztest/sendresulttoability_fuzzer/corpus/init create mode 100644 test/fuzztest/sendresulttoability_fuzzer/project.xml create mode 100644 test/fuzztest/sendresulttoability_fuzzer/sendresulttoability_fuzzer.cpp create mode 100644 test/fuzztest/sendresulttoability_fuzzer/sendresulttoability_fuzzer.h create mode 100644 test/fuzztest/terminateabilityresult_fuzzer/BUILD.gn create mode 100644 test/fuzztest/terminateabilityresult_fuzzer/corpus/init create mode 100644 test/fuzztest/terminateabilityresult_fuzzer/project.xml create mode 100644 test/fuzztest/terminateabilityresult_fuzzer/terminateabilityresult_fuzzer.cpp create mode 100644 test/fuzztest/terminateabilityresult_fuzzer/terminateabilityresult_fuzzer.h diff --git a/test/fuzztest/BUILD.gn b/test/fuzztest/BUILD.gn index 85047f8b23..c98720864d 100644 --- a/test/fuzztest/BUILD.gn +++ b/test/fuzztest/BUILD.gn @@ -30,12 +30,18 @@ group("fuzztest") { "getextensionrunninginfos_fuzzer:fuzztest", "gettopability_fuzzer:fuzztest", "getwantsender_fuzzer:fuzztest", + "killprocessesbybundlename_fuzzer:fuzztest", "killprocesswithaccount_fuzzer:fuzztest", "missionlistenerstub_fuzzer:fuzztest", "registerabilitylifecyclecallback_fuzzer:fuzztest", "registerapplicationstateobserver_fuzzer:fuzztest", "registerenvironmentcallback_fuzzer:fuzztest", + "releasedataability_fuzzer:fuzztest", "remotemissionlistenerstub_fuzzer:fuzztest", + "schedulecommandabilitydone_fuzzer:fuzztest", + "scheduleconnectabilitydone_fuzzer:fuzztest", + "scheduledisconnectabilitydone_fuzzer:fuzztest", + "sendresulttoability_fuzzer:fuzztest", "setmissionicon_fuzzer:fuzztest", "setmissionlabel_fuzzer:fuzztest", "startability_fuzzer:fuzztest", @@ -47,6 +53,7 @@ group("fuzztest") { "stopusercallbackstub_fuzzer:fuzztest", "systemabilitytokencallbackstub_fuzzer:fuzztest", "terminateability_fuzzer:fuzztest", + "terminateabilityresult_fuzzer:fuzztest", "unregisterabilitylifecyclecallback_fuzzer:fuzztest", "unregisterapplicationstateobserver_fuzzer:fuzztest", "unregisterenvironmentcallback_fuzzer:fuzztest", diff --git a/test/fuzztest/killprocessesbybundlename_fuzzer/BUILD.gn b/test/fuzztest/killprocessesbybundlename_fuzzer/BUILD.gn new file mode 100644 index 0000000000..9d8b89493e --- /dev/null +++ b/test/fuzztest/killprocessesbybundlename_fuzzer/BUILD.gn @@ -0,0 +1,78 @@ +# 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. + +#####################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("KillProcessesByBundleNameFuzzTest") { + module_out_path = module_output_path + + fuzz_config_file = + "${ability_runtime_test_path}/fuzztest/killprocessesbybundlename_fuzzer" + include_dirs = [ "${ability_runtime_innerkits_path}/ability_manager/include" ] + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + sources = [ "killprocessesbybundlename_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", + "//third_party/jsoncpp:jsoncpp", + ] + + external_deps = [ + "ability_base:want", + "ability_base:zuri", + "ability_runtime:app_manager", + "c_utils:utils", + "eventhandler:libeventhandler", + "hitrace_native:hitrace_meter", + "hiviewdfx_hilog_native:libhilog", + "ipc:ipc_core", + "relational_store:native_dataability", + "relational_store:native_rdb", + "samgr:samgr_proxy", + ] + + if (ability_runtime_graphics) { + deps += [] + external_deps += [ + "i18n:intl_util", + "window_manager:libwm", + ] + } +} + +############################################################################### +group("fuzztest") { + testonly = true + deps = [] + deps += [ + # deps file + ":KillProcessesByBundleNameFuzzTest", + ] +} +############################################################################### diff --git a/test/fuzztest/killprocessesbybundlename_fuzzer/corpus/init b/test/fuzztest/killprocessesbybundlename_fuzzer/corpus/init new file mode 100644 index 0000000000..6d6bd4a361 --- /dev/null +++ b/test/fuzztest/killprocessesbybundlename_fuzzer/corpus/init @@ -0,0 +1,16 @@ +/* + * 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. + */ + +FUZZ \ No newline at end of file diff --git a/test/fuzztest/killprocessesbybundlename_fuzzer/killprocessesbybundlename_fuzzer.cpp b/test/fuzztest/killprocessesbybundlename_fuzzer/killprocessesbybundlename_fuzzer.cpp new file mode 100644 index 0000000000..799d366ff0 --- /dev/null +++ b/test/fuzztest/killprocessesbybundlename_fuzzer/killprocessesbybundlename_fuzzer.cpp @@ -0,0 +1,79 @@ +/* + * 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 "killprocessesbybundlename_fuzzer.h" + +#include +#include + +#include "ability_manager_client.h" +#include "securec.h" + +using namespace OHOS::AAFwk; +using namespace OHOS::AppExecFwk; + +namespace OHOS { +constexpr size_t FOO_MAX_LEN = 1024; +bool DoSomethingInterestingWithMyAPI(const char* data, size_t size) +{ + auto abilitymgr = AbilityManagerClient::GetInstance(); + if (!abilitymgr) { + return false; + } + + std::string bundleName(data, size); + if (abilitymgr->KillProcess(bundleName) != 0) { + return false; + } + + return true; +} +} + +/* 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 == 0 || size > OHOS::FOO_MAX_LEN) { + std::cout << "invalid size" << std::endl; + 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, 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/killprocessesbybundlename_fuzzer/killprocessesbybundlename_fuzzer.h b/test/fuzztest/killprocessesbybundlename_fuzzer/killprocessesbybundlename_fuzzer.h new file mode 100644 index 0000000000..b27a77d495 --- /dev/null +++ b/test/fuzztest/killprocessesbybundlename_fuzzer/killprocessesbybundlename_fuzzer.h @@ -0,0 +1,21 @@ +/* + * 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. + */ + +#ifndef FUZZTEST_OHOS_ABILITY_RUNTIME_KILLPROCESSESBYBUNDLENAME_FUZZER_H +#define FUZZTEST_OHOS_ABILITY_RUNTIME_KILLPROCESSESBYBUNDLENAME_FUZZER_H + +#define FUZZ_PROJECT_NAME "killprocessesbybundlename_fuzzer" + +#endif diff --git a/test/fuzztest/killprocessesbybundlename_fuzzer/project.xml b/test/fuzztest/killprocessesbybundlename_fuzzer/project.xml new file mode 100644 index 0000000000..1020c7b430 --- /dev/null +++ b/test/fuzztest/killprocessesbybundlename_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/test/fuzztest/releasedataability_fuzzer/BUILD.gn b/test/fuzztest/releasedataability_fuzzer/BUILD.gn new file mode 100644 index 0000000000..c78bc57796 --- /dev/null +++ b/test/fuzztest/releasedataability_fuzzer/BUILD.gn @@ -0,0 +1,80 @@ +# 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. + +#####################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("ReleaseDataAbilityFuzzTest") { + module_out_path = module_output_path + + fuzz_config_file = + "${ability_runtime_test_path}/fuzztest/releasedataability_fuzzer" + include_dirs = [ "${ability_runtime_innerkits_path}/ability_manager/include" ] + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + sources = [ "releasedataability_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_innerkits_path}/uri_permission:uri_permission_mgr", + "${ability_runtime_native_path}/ability/native:abilitykit_native", + "${ability_runtime_services_path}/abilitymgr:abilityms", + "//third_party/jsoncpp:jsoncpp", + ] + + external_deps = [ + "ability_base:want", + "ability_base:zuri", + "ability_runtime:app_manager", + "bundle_framework:appexecfwk_base", + "c_utils:utils", + "eventhandler:libeventhandler", + "ipc:ipc_core", + "relational_store:native_dataability", + "relational_store:native_rdb", + "samgr:samgr_proxy", + ] + + if (ability_runtime_graphics) { + deps += [] + external_deps += [ + "i18n:intl_util", + "window_manager:libwm", + ] + } +} + +############################################################################### +group("fuzztest") { + testonly = true + deps = [] + deps += [ + # deps file + ":ReleaseDataAbilityFuzzTest", + ] +} +############################################################################### diff --git a/test/fuzztest/releasedataability_fuzzer/corpus/init b/test/fuzztest/releasedataability_fuzzer/corpus/init new file mode 100644 index 0000000000..6d6bd4a361 --- /dev/null +++ b/test/fuzztest/releasedataability_fuzzer/corpus/init @@ -0,0 +1,16 @@ +/* + * 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. + */ + +FUZZ \ No newline at end of file diff --git a/test/fuzztest/releasedataability_fuzzer/project.xml b/test/fuzztest/releasedataability_fuzzer/project.xml new file mode 100644 index 0000000000..1020c7b430 --- /dev/null +++ b/test/fuzztest/releasedataability_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/test/fuzztest/releasedataability_fuzzer/releasedataability_fuzzer.cpp b/test/fuzztest/releasedataability_fuzzer/releasedataability_fuzzer.cpp new file mode 100644 index 0000000000..71b5e18aaf --- /dev/null +++ b/test/fuzztest/releasedataability_fuzzer/releasedataability_fuzzer.cpp @@ -0,0 +1,101 @@ +/* + * 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 "releasedataability_fuzzer.h" + +#include +#include + +#include "ability_manager_client.h" +#include "ability_record.h" + +using namespace OHOS::AAFwk; +using namespace OHOS::AppExecFwk; + +namespace OHOS { +constexpr size_t FOO_MAX_LEN = 1024; +sptr GetFuzzAbilityToken() +{ + sptr token = nullptr; + + AbilityRequest abilityRequest; + abilityRequest.appInfo.bundleName = "com.example.fuzzTest"; + abilityRequest.abilityInfo.name = "MainAbility"; + abilityRequest.abilityInfo.type = AbilityType::DATA; + std::shared_ptr abilityRecord = AbilityRecord::CreateAbilityRecord(abilityRequest); + if (abilityRecord) { + token = abilityRecord->GetToken(); + } + + return token; +} +bool DoSomethingInterestingWithMyAPI(const char* data, size_t size) +{ + auto abilitymgr = AbilityManagerClient::GetInstance(); + sptr scheduler; + if (!abilitymgr) { + return false; + } + + // get token + sptr token = GetFuzzAbilityToken(); + if (!token) { + std::cout << "Get ability token failed." << std::endl; + return false; + } + + if (abilitymgr->ReleaseDataAbility(scheduler, token) != 0) { + return false; + } + + return true; +} +} + +/* 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 == 0 || size > OHOS::FOO_MAX_LEN) { + std::cout << "invalid size" << std::endl; + 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, 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/releasedataability_fuzzer/releasedataability_fuzzer.h b/test/fuzztest/releasedataability_fuzzer/releasedataability_fuzzer.h new file mode 100644 index 0000000000..24f48fa44c --- /dev/null +++ b/test/fuzztest/releasedataability_fuzzer/releasedataability_fuzzer.h @@ -0,0 +1,21 @@ +/* + * 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. + */ + +#ifndef FUZZTEST_OHOS_ABILITY_RUNTIME_RELEASEDATAABILITY_FUZZER_H +#define FUZZTEST_OHOS_ABILITY_RUNTIME_RELEASEDATAABILITY_FUZZER_H + +#define FUZZ_PROJECT_NAME "releasedataability_fuzzer" + +#endif diff --git a/test/fuzztest/schedulecommandabilitydone_fuzzer/BUILD.gn b/test/fuzztest/schedulecommandabilitydone_fuzzer/BUILD.gn new file mode 100644 index 0000000000..df3db062fd --- /dev/null +++ b/test/fuzztest/schedulecommandabilitydone_fuzzer/BUILD.gn @@ -0,0 +1,76 @@ +# 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. + +#####################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("ScheduleCommandAbilityDoneFuzzTest") { + module_out_path = module_output_path + + fuzz_config_file = + "${ability_runtime_test_path}/fuzztest/schedulecommandabilitydone_fuzzer" + include_dirs = [ "${ability_runtime_innerkits_path}/ability_manager/include" ] + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + sources = [ "schedulecommandabilitydone_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_innerkits_path}/uri_permission:uri_permission_mgr", + "${ability_runtime_native_path}/ability/native:abilitykit_native", + "${ability_runtime_services_path}/abilitymgr:abilityms", + "//third_party/jsoncpp:jsoncpp", + ] + + external_deps = [ + "ability_base:want", + "ability_base:zuri", + "bundle_framework:appexecfwk_base", + "c_utils:utils", + "ipc:ipc_core", + "samgr:samgr_proxy", + ] + + if (ability_runtime_graphics) { + deps += [] + external_deps += [ + "i18n:intl_util", + "window_manager:libwm", + ] + } +} + +############################################################################### +group("fuzztest") { + testonly = true + deps = [] + deps += [ + # deps file + ":ScheduleCommandAbilityDoneFuzzTest", + ] +} +############################################################################### diff --git a/test/fuzztest/schedulecommandabilitydone_fuzzer/corpus/init b/test/fuzztest/schedulecommandabilitydone_fuzzer/corpus/init new file mode 100644 index 0000000000..6d6bd4a361 --- /dev/null +++ b/test/fuzztest/schedulecommandabilitydone_fuzzer/corpus/init @@ -0,0 +1,16 @@ +/* + * 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. + */ + +FUZZ \ No newline at end of file diff --git a/test/fuzztest/schedulecommandabilitydone_fuzzer/project.xml b/test/fuzztest/schedulecommandabilitydone_fuzzer/project.xml new file mode 100644 index 0000000000..1020c7b430 --- /dev/null +++ b/test/fuzztest/schedulecommandabilitydone_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/test/fuzztest/schedulecommandabilitydone_fuzzer/schedulecommandabilitydone_fuzzer.cpp b/test/fuzztest/schedulecommandabilitydone_fuzzer/schedulecommandabilitydone_fuzzer.cpp new file mode 100644 index 0000000000..6ec06197e6 --- /dev/null +++ b/test/fuzztest/schedulecommandabilitydone_fuzzer/schedulecommandabilitydone_fuzzer.cpp @@ -0,0 +1,100 @@ +/* + * 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 "schedulecommandabilitydone_fuzzer.h" + +#include +#include + +#include "ability_manager_client.h" +#include "ability_record.h" + +using namespace OHOS::AAFwk; +using namespace OHOS::AppExecFwk; + +namespace OHOS { +constexpr size_t FOO_MAX_LEN = 1024; +sptr GetFuzzAbilityToken() +{ + sptr token = nullptr; + + AbilityRequest abilityRequest; + abilityRequest.appInfo.bundleName = "com.example.fuzzTest"; + abilityRequest.abilityInfo.name = "MainAbility"; + abilityRequest.abilityInfo.type = AbilityType::DATA; + std::shared_ptr abilityRecord = AbilityRecord::CreateAbilityRecord(abilityRequest); + if (abilityRecord) { + token = abilityRecord->GetToken(); + } + + return token; +} +bool DoSomethingInterestingWithMyAPI(const char* data, size_t size) +{ + auto abilitymgr = AbilityManagerClient::GetInstance(); + if (!abilitymgr) { + return false; + } + + // get token + sptr token = GetFuzzAbilityToken(); + if (!token) { + std::cout << "Get ability token failed." << std::endl; + return false; + } + + if (abilitymgr->ScheduleCommandAbilityDone(token) != 0) { + return false; + } + + return true; +} +} + +/* 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 == 0 || size > OHOS::FOO_MAX_LEN) { + std::cout << "invalid size" << std::endl; + 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, 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/schedulecommandabilitydone_fuzzer/schedulecommandabilitydone_fuzzer.h b/test/fuzztest/schedulecommandabilitydone_fuzzer/schedulecommandabilitydone_fuzzer.h new file mode 100644 index 0000000000..33ced9ff02 --- /dev/null +++ b/test/fuzztest/schedulecommandabilitydone_fuzzer/schedulecommandabilitydone_fuzzer.h @@ -0,0 +1,21 @@ +/* + * 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. + */ + +#ifndef FUZZTEST_OHOS_ABILITY_RUNTIME_SCHEDULECOMMANDABILITYDONE_FUZZER_H +#define FUZZTEST_OHOS_ABILITY_RUNTIME_SCHEDULECOMMANDABILITYDONE_FUZZER_H + +#define FUZZ_PROJECT_NAME "schedulecommandabilitydone_fuzzer" + +#endif diff --git a/test/fuzztest/scheduleconnectabilitydone_fuzzer/BUILD.gn b/test/fuzztest/scheduleconnectabilitydone_fuzzer/BUILD.gn new file mode 100644 index 0000000000..44de70fd95 --- /dev/null +++ b/test/fuzztest/scheduleconnectabilitydone_fuzzer/BUILD.gn @@ -0,0 +1,76 @@ +# 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. + +#####################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("ScheduleConnectAbilityDoneFuzzTest") { + module_out_path = module_output_path + + fuzz_config_file = + "${ability_runtime_test_path}/fuzztest/scheduleconnectabilitydone_fuzzer" + include_dirs = [ "${ability_runtime_innerkits_path}/ability_manager/include" ] + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + sources = [ "scheduleconnectabilitydone_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_innerkits_path}/uri_permission:uri_permission_mgr", + "${ability_runtime_native_path}/ability/native:abilitykit_native", + "${ability_runtime_services_path}/abilitymgr:abilityms", + "//third_party/jsoncpp:jsoncpp", + ] + + external_deps = [ + "ability_base:want", + "ability_base:zuri", + "bundle_framework:appexecfwk_base", + "c_utils:utils", + "ipc:ipc_core", + "samgr:samgr_proxy", + ] + + if (ability_runtime_graphics) { + deps += [] + external_deps += [ + "i18n:intl_util", + "window_manager:libwm", + ] + } +} + +############################################################################### +group("fuzztest") { + testonly = true + deps = [] + deps += [ + # deps file + ":ScheduleConnectAbilityDoneFuzzTest", + ] +} +############################################################################### diff --git a/test/fuzztest/scheduleconnectabilitydone_fuzzer/corpus/init b/test/fuzztest/scheduleconnectabilitydone_fuzzer/corpus/init new file mode 100644 index 0000000000..6d6bd4a361 --- /dev/null +++ b/test/fuzztest/scheduleconnectabilitydone_fuzzer/corpus/init @@ -0,0 +1,16 @@ +/* + * 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. + */ + +FUZZ \ No newline at end of file diff --git a/test/fuzztest/scheduleconnectabilitydone_fuzzer/project.xml b/test/fuzztest/scheduleconnectabilitydone_fuzzer/project.xml new file mode 100644 index 0000000000..1020c7b430 --- /dev/null +++ b/test/fuzztest/scheduleconnectabilitydone_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/test/fuzztest/scheduleconnectabilitydone_fuzzer/scheduleconnectabilitydone_fuzzer.cpp b/test/fuzztest/scheduleconnectabilitydone_fuzzer/scheduleconnectabilitydone_fuzzer.cpp new file mode 100644 index 0000000000..18098f6c26 --- /dev/null +++ b/test/fuzztest/scheduleconnectabilitydone_fuzzer/scheduleconnectabilitydone_fuzzer.cpp @@ -0,0 +1,101 @@ +/* + * 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 "scheduleconnectabilitydone_fuzzer.h" + +#include +#include + +#include "ability_manager_client.h" +#include "ability_record.h" + +using namespace OHOS::AAFwk; +using namespace OHOS::AppExecFwk; + +namespace OHOS { +constexpr size_t FOO_MAX_LEN = 1024; +sptr GetFuzzAbilityToken() +{ + sptr token = nullptr; + + AbilityRequest abilityRequest; + abilityRequest.appInfo.bundleName = "com.example.fuzzTest"; + abilityRequest.abilityInfo.name = "MainAbility"; + abilityRequest.abilityInfo.type = AbilityType::DATA; + std::shared_ptr abilityRecord = AbilityRecord::CreateAbilityRecord(abilityRequest); + if (abilityRecord) { + token = abilityRecord->GetToken(); + } + + return token; +} +bool DoSomethingInterestingWithMyAPI(const char* data, size_t size) +{ + auto abilitymgr = AbilityManagerClient::GetInstance(); + sptr remoteObject; + if (!abilitymgr) { + return false; + } + + // get token + sptr token = GetFuzzAbilityToken(); + if (!token) { + std::cout << "Get ability token failed." << std::endl; + return false; + } + + if (abilitymgr->ScheduleConnectAbilityDone(token, remoteObject) != 0) { + return false; + } + + return true; +} +} + +/* 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 == 0 || size > OHOS::FOO_MAX_LEN) { + std::cout << "invalid size" << std::endl; + 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, 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/scheduleconnectabilitydone_fuzzer/scheduleconnectabilitydone_fuzzer.h b/test/fuzztest/scheduleconnectabilitydone_fuzzer/scheduleconnectabilitydone_fuzzer.h new file mode 100644 index 0000000000..afb8d148b2 --- /dev/null +++ b/test/fuzztest/scheduleconnectabilitydone_fuzzer/scheduleconnectabilitydone_fuzzer.h @@ -0,0 +1,21 @@ +/* + * 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. + */ + +#ifndef FUZZTEST_OHOS_ABILITY_RUNTIME_SCHEDULECONNECTABILITYDONE_FUZZER_H +#define FUZZTEST_OHOS_ABILITY_RUNTIME_SCHEDULECONNECTABILITYDONE_FUZZER_H + +#define FUZZ_PROJECT_NAME "scheduleconnectabilitydone_fuzzer" + +#endif diff --git a/test/fuzztest/scheduledisconnectabilitydone_fuzzer/BUILD.gn b/test/fuzztest/scheduledisconnectabilitydone_fuzzer/BUILD.gn new file mode 100644 index 0000000000..09d8676e4f --- /dev/null +++ b/test/fuzztest/scheduledisconnectabilitydone_fuzzer/BUILD.gn @@ -0,0 +1,75 @@ +# 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. + +#####################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("ScheduleDisconnectAbilityDoneFuzzTest") { + module_out_path = module_output_path + + fuzz_config_file = "${ability_runtime_test_path}/fuzztest/scheduledisconnectabilitydone_fuzzer" + include_dirs = [ "${ability_runtime_innerkits_path}/ability_manager/include" ] + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + sources = [ "scheduledisconnectabilitydone_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_innerkits_path}/uri_permission:uri_permission_mgr", + "${ability_runtime_native_path}/ability/native:abilitykit_native", + "${ability_runtime_services_path}/abilitymgr:abilityms", + "//third_party/jsoncpp:jsoncpp", + ] + + external_deps = [ + "ability_base:want", + "ability_base:zuri", + "bundle_framework:appexecfwk_base", + "c_utils:utils", + "ipc:ipc_core", + "samgr:samgr_proxy", + ] + + if (ability_runtime_graphics) { + deps += [] + external_deps += [ + "i18n:intl_util", + "window_manager:libwm", + ] + } +} + +############################################################################### +group("fuzztest") { + testonly = true + deps = [] + deps += [ + # deps file + ":ScheduleDisconnectAbilityDoneFuzzTest", + ] +} +############################################################################### diff --git a/test/fuzztest/scheduledisconnectabilitydone_fuzzer/corpus/init b/test/fuzztest/scheduledisconnectabilitydone_fuzzer/corpus/init new file mode 100644 index 0000000000..6d6bd4a361 --- /dev/null +++ b/test/fuzztest/scheduledisconnectabilitydone_fuzzer/corpus/init @@ -0,0 +1,16 @@ +/* + * 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. + */ + +FUZZ \ No newline at end of file diff --git a/test/fuzztest/scheduledisconnectabilitydone_fuzzer/project.xml b/test/fuzztest/scheduledisconnectabilitydone_fuzzer/project.xml new file mode 100644 index 0000000000..1020c7b430 --- /dev/null +++ b/test/fuzztest/scheduledisconnectabilitydone_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/test/fuzztest/scheduledisconnectabilitydone_fuzzer/scheduledisconnectabilitydone_fuzzer.cpp b/test/fuzztest/scheduledisconnectabilitydone_fuzzer/scheduledisconnectabilitydone_fuzzer.cpp new file mode 100644 index 0000000000..423d5e2394 --- /dev/null +++ b/test/fuzztest/scheduledisconnectabilitydone_fuzzer/scheduledisconnectabilitydone_fuzzer.cpp @@ -0,0 +1,100 @@ +/* + * 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 "scheduledisconnectabilitydone_fuzzer.h" + +#include +#include + +#include "ability_manager_client.h" +#include "ability_record.h" + +using namespace OHOS::AAFwk; +using namespace OHOS::AppExecFwk; + +namespace OHOS { +constexpr size_t FOO_MAX_LEN = 1024; +sptr GetFuzzAbilityToken() +{ + sptr token = nullptr; + + AbilityRequest abilityRequest; + abilityRequest.appInfo.bundleName = "com.example.fuzzTest"; + abilityRequest.abilityInfo.name = "MainAbility"; + abilityRequest.abilityInfo.type = AbilityType::DATA; + std::shared_ptr abilityRecord = AbilityRecord::CreateAbilityRecord(abilityRequest); + if (abilityRecord) { + token = abilityRecord->GetToken(); + } + + return token; +} +bool DoSomethingInterestingWithMyAPI(const char* data, size_t size) +{ + auto abilitymgr = AbilityManagerClient::GetInstance(); + if (!abilitymgr) { + return false; + } + + // get token + sptr token = GetFuzzAbilityToken(); + if (!token) { + std::cout << "Get ability token failed." << std::endl; + return false; + } + + if (abilitymgr->ScheduleDisconnectAbilityDone(token) != 0) { + return false; + } + + return true; +} +} + +/* 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 == 0 || size > OHOS::FOO_MAX_LEN) { + std::cout << "invalid size" << std::endl; + 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, 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/scheduledisconnectabilitydone_fuzzer/scheduledisconnectabilitydone_fuzzer.h b/test/fuzztest/scheduledisconnectabilitydone_fuzzer/scheduledisconnectabilitydone_fuzzer.h new file mode 100644 index 0000000000..d09d0e1795 --- /dev/null +++ b/test/fuzztest/scheduledisconnectabilitydone_fuzzer/scheduledisconnectabilitydone_fuzzer.h @@ -0,0 +1,21 @@ +/* + * 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. + */ + +#ifndef FUZZTEST_OHOS_ABILITY_RUNTIME_SCHEDULEDISCONNECTABILITYDONE_FUZZER_H +#define FUZZTEST_OHOS_ABILITY_RUNTIME_SCHEDULEDISCONNECTABILITYDONE_FUZZER_H + +#define FUZZ_PROJECT_NAME "scheduledisconnectabilitydone_fuzzer" + +#endif diff --git a/test/fuzztest/sendresulttoability_fuzzer/BUILD.gn b/test/fuzztest/sendresulttoability_fuzzer/BUILD.gn new file mode 100644 index 0000000000..99c6aef1ff --- /dev/null +++ b/test/fuzztest/sendresulttoability_fuzzer/BUILD.gn @@ -0,0 +1,76 @@ +# 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. + +#####################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("SendResultToAbilityFuzzTest") { + module_out_path = module_output_path + + fuzz_config_file = + "${ability_runtime_test_path}/fuzztest/sendresulttoability_fuzzer" + include_dirs = [ "${ability_runtime_innerkits_path}/ability_manager/include" ] + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + sources = [ "sendresulttoability_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_innerkits_path}/uri_permission:uri_permission_mgr", + "${ability_runtime_native_path}/ability/native:abilitykit_native", + "${ability_runtime_services_path}/abilitymgr:abilityms", + "//third_party/jsoncpp:jsoncpp", + ] + + external_deps = [ + "ability_base:want", + "ability_base:zuri", + "bundle_framework:appexecfwk_base", + "c_utils:utils", + "ipc:ipc_core", + "samgr:samgr_proxy", + ] + + if (ability_runtime_graphics) { + deps += [] + external_deps += [ + "i18n:intl_util", + "window_manager:libwm", + ] + } +} + +############################################################################### +group("fuzztest") { + testonly = true + deps = [] + deps += [ + # deps file + ":SendResultToAbilityFuzzTest", + ] +} +############################################################################### diff --git a/test/fuzztest/sendresulttoability_fuzzer/corpus/init b/test/fuzztest/sendresulttoability_fuzzer/corpus/init new file mode 100644 index 0000000000..6d6bd4a361 --- /dev/null +++ b/test/fuzztest/sendresulttoability_fuzzer/corpus/init @@ -0,0 +1,16 @@ +/* + * 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. + */ + +FUZZ \ No newline at end of file diff --git a/test/fuzztest/sendresulttoability_fuzzer/project.xml b/test/fuzztest/sendresulttoability_fuzzer/project.xml new file mode 100644 index 0000000000..1020c7b430 --- /dev/null +++ b/test/fuzztest/sendresulttoability_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/test/fuzztest/sendresulttoability_fuzzer/sendresulttoability_fuzzer.cpp b/test/fuzztest/sendresulttoability_fuzzer/sendresulttoability_fuzzer.cpp new file mode 100644 index 0000000000..985710402f --- /dev/null +++ b/test/fuzztest/sendresulttoability_fuzzer/sendresulttoability_fuzzer.cpp @@ -0,0 +1,89 @@ +/* + * 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 "sendresulttoability_fuzzer.h" + +#include +#include + +#include "ability_manager_client.h" +#include "ability_record.h" + +using namespace OHOS::AAFwk; +using namespace OHOS::AppExecFwk; + +namespace OHOS { +constexpr size_t FOO_MAX_LEN = 1024; +bool DoSomethingInterestingWithMyAPI(const char* data, size_t size) +{ + auto abilitymgr = AbilityManagerClient::GetInstance(); + int requestCode = 0; + int resultCode = 0; + if (!abilitymgr) { + return false; + } + + // fuzz for want + Parcel wantParcel; + Want *resultWant = nullptr; + if (wantParcel.WriteBuffer(data, size)) { + resultWant = Want::Unmarshalling(wantParcel); + if (resultWant) { + ErrCode result = abilitymgr->SendResultToAbility(requestCode, resultCode, *resultWant); + if (result != 0) { + return false; + } + } + } + + return true; +} +} + +/* 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 == 0 || size > OHOS::FOO_MAX_LEN) { + std::cout << "invalid size" << std::endl; + 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, 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/sendresulttoability_fuzzer/sendresulttoability_fuzzer.h b/test/fuzztest/sendresulttoability_fuzzer/sendresulttoability_fuzzer.h new file mode 100644 index 0000000000..496118ebd6 --- /dev/null +++ b/test/fuzztest/sendresulttoability_fuzzer/sendresulttoability_fuzzer.h @@ -0,0 +1,21 @@ +/* + * 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. + */ + +#ifndef FUZZTEST_OHOS_ABILITY_RUNTIME_SENDRESULTTOABILITY_FUZZER_H +#define FUZZTEST_OHOS_ABILITY_RUNTIME_SENDRESULTTOABILITY_FUZZER_H + +#define FUZZ_PROJECT_NAME "sendresulttoability_fuzzer" + +#endif diff --git a/test/fuzztest/terminateabilityresult_fuzzer/BUILD.gn b/test/fuzztest/terminateabilityresult_fuzzer/BUILD.gn new file mode 100644 index 0000000000..6436b17358 --- /dev/null +++ b/test/fuzztest/terminateabilityresult_fuzzer/BUILD.gn @@ -0,0 +1,76 @@ +# 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. + +#####################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("TerminateAbilityResultFuzzTest") { + module_out_path = module_output_path + + fuzz_config_file = + "${ability_runtime_test_path}/fuzztest/terminateabilityresult_fuzzer" + include_dirs = [ "${ability_runtime_innerkits_path}/ability_manager/include" ] + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + sources = [ "terminateabilityresult_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_innerkits_path}/uri_permission:uri_permission_mgr", + "${ability_runtime_native_path}/ability/native:abilitykit_native", + "${ability_runtime_services_path}/abilitymgr:abilityms", + "//third_party/jsoncpp:jsoncpp", + ] + + external_deps = [ + "ability_base:want", + "ability_base:zuri", + "bundle_framework:appexecfwk_base", + "c_utils:utils", + "ipc:ipc_core", + "samgr:samgr_proxy", + ] + + if (ability_runtime_graphics) { + deps += [] + external_deps += [ + "i18n:intl_util", + "window_manager:libwm", + ] + } +} + +############################################################################### +group("fuzztest") { + testonly = true + deps = [] + deps += [ + # deps file + ":TerminateAbilityResultFuzzTest", + ] +} +############################################################################### diff --git a/test/fuzztest/terminateabilityresult_fuzzer/corpus/init b/test/fuzztest/terminateabilityresult_fuzzer/corpus/init new file mode 100644 index 0000000000..6d6bd4a361 --- /dev/null +++ b/test/fuzztest/terminateabilityresult_fuzzer/corpus/init @@ -0,0 +1,16 @@ +/* + * 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. + */ + +FUZZ \ No newline at end of file diff --git a/test/fuzztest/terminateabilityresult_fuzzer/project.xml b/test/fuzztest/terminateabilityresult_fuzzer/project.xml new file mode 100644 index 0000000000..1020c7b430 --- /dev/null +++ b/test/fuzztest/terminateabilityresult_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/test/fuzztest/terminateabilityresult_fuzzer/terminateabilityresult_fuzzer.cpp b/test/fuzztest/terminateabilityresult_fuzzer/terminateabilityresult_fuzzer.cpp new file mode 100644 index 0000000000..79d4a9aa27 --- /dev/null +++ b/test/fuzztest/terminateabilityresult_fuzzer/terminateabilityresult_fuzzer.cpp @@ -0,0 +1,101 @@ +/* + * 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 "terminateabilityresult_fuzzer.h" + +#include +#include + +#include "ability_manager_client.h" +#include "ability_record.h" + +using namespace OHOS::AAFwk; +using namespace OHOS::AppExecFwk; + +namespace OHOS { +constexpr size_t FOO_MAX_LEN = 1024; +sptr GetFuzzAbilityToken() +{ + sptr token = nullptr; + + AbilityRequest abilityRequest; + abilityRequest.appInfo.bundleName = "com.example.fuzzTest"; + abilityRequest.abilityInfo.name = "MainAbility"; + abilityRequest.abilityInfo.type = AbilityType::DATA; + std::shared_ptr abilityRecord = AbilityRecord::CreateAbilityRecord(abilityRequest); + if (abilityRecord) { + token = abilityRecord->GetToken(); + } + + return token; +} +bool DoSomethingInterestingWithMyAPI(const char* data, size_t size) +{ + auto abilitymgr = AbilityManagerClient::GetInstance(); + int startId = 0; + if (!abilitymgr) { + return false; + } + + // get token + sptr token = GetFuzzAbilityToken(); + if (!token) { + std::cout << "Get ability token failed." << std::endl; + return false; + } + + if (abilitymgr->TerminateAbilityResult(token, startId) != 0) { + return false; + } + + return true; +} +} + +/* 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 == 0 || size > OHOS::FOO_MAX_LEN) { + std::cout << "invalid size" << std::endl; + 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, 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/terminateabilityresult_fuzzer/terminateabilityresult_fuzzer.h b/test/fuzztest/terminateabilityresult_fuzzer/terminateabilityresult_fuzzer.h new file mode 100644 index 0000000000..417b92a3f3 --- /dev/null +++ b/test/fuzztest/terminateabilityresult_fuzzer/terminateabilityresult_fuzzer.h @@ -0,0 +1,21 @@ +/* + * 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. + */ + +#ifndef FUZZTEST_OHOS_ABILITY_RUNTIME_TERMINATEABILITYRESULT_FUZZER_H +#define FUZZTEST_OHOS_ABILITY_RUNTIME_TERMINATEABILITYRESULT_FUZZER_H + +#define FUZZ_PROJECT_NAME "terminateabilityresult_fuzzer" + +#endif