From 189c8b15ca63e33da114c167f69e39abb8e4e9fa Mon Sep 17 00:00:00 2001 From: huangshiwei Date: Wed, 18 Jun 2025 11:37:53 +0800 Subject: [PATCH] huangshiwei4@huawei.com Signed-off-by: huangshiwei --- test/fuzztest/BUILD.gn | 8 ++ .../abilityapppreloaderfirst_fuzzer/BUILD.gn | 73 +++++++++++++++ .../abilityapppreloaderfirst_fuzzer.cpp | 66 +++++++++++++ .../abilityapppreloaderfirst_fuzzer.h | 21 +++++ .../corpus/init | 16 ++++ .../project.xml | 25 +++++ .../abilityapppreloadersecond_fuzzer/BUILD.gn | 73 +++++++++++++++ .../abilityapppreloadersecond_fuzzer.cpp | 64 +++++++++++++ .../abilityapppreloadersecond_fuzzer.h | 21 +++++ .../corpus/init | 16 ++++ .../project.xml | 25 +++++ .../BUILD.gn | 92 ++++++++++++++++++ .../abilityautostartupclientfirst_fuzzer.cpp | 63 +++++++++++++ .../abilityautostartupclientfirst_fuzzer.h | 21 +++++ .../corpus/init | 16 ++++ .../project.xml | 25 +++++ .../BUILD.gn | 92 ++++++++++++++++++ .../abilityautostartupclientsecond_fuzzer.cpp | 63 +++++++++++++ .../abilityautostartupclientsecond_fuzzer.h | 21 +++++ .../corpus/init | 16 ++++ .../project.xml | 25 +++++ .../BUILD.gn | 92 ++++++++++++++++++ .../abilityautostartupclientthird_fuzzer.cpp | 71 ++++++++++++++ .../abilityautostartupclientthird_fuzzer.h | 21 +++++ .../corpus/init | 16 ++++ .../project.xml | 25 +++++ .../BUILD.gn | 93 +++++++++++++++++++ ...lityautostartupdatamanagerfifth_fuzzer.cpp | 73 +++++++++++++++ ...bilityautostartupdatamanagerfifth_fuzzer.h | 21 +++++ .../corpus/init | 16 ++++ .../project.xml | 25 +++++ .../BUILD.gn | 93 +++++++++++++++++++ ...ityautostartupdatamanagerfourth_fuzzer.cpp | 72 ++++++++++++++ ...ilityautostartupdatamanagerfourth_fuzzer.h | 21 +++++ .../corpus/init | 16 ++++ .../project.xml | 25 +++++ .../BUILD.gn | 93 +++++++++++++++++++ ...lityautostartupdatamanagerthird_fuzzer.cpp | 62 +++++++++++++ ...bilityautostartupdatamanagerthird_fuzzer.h | 21 +++++ .../corpus/init | 16 ++++ .../project.xml | 25 +++++ 41 files changed, 1739 insertions(+) create mode 100644 test/fuzztest/abilityapppreloaderfirst_fuzzer/BUILD.gn create mode 100644 test/fuzztest/abilityapppreloaderfirst_fuzzer/abilityapppreloaderfirst_fuzzer.cpp create mode 100644 test/fuzztest/abilityapppreloaderfirst_fuzzer/abilityapppreloaderfirst_fuzzer.h create mode 100644 test/fuzztest/abilityapppreloaderfirst_fuzzer/corpus/init create mode 100644 test/fuzztest/abilityapppreloaderfirst_fuzzer/project.xml create mode 100644 test/fuzztest/abilityapppreloadersecond_fuzzer/BUILD.gn create mode 100644 test/fuzztest/abilityapppreloadersecond_fuzzer/abilityapppreloadersecond_fuzzer.cpp create mode 100644 test/fuzztest/abilityapppreloadersecond_fuzzer/abilityapppreloadersecond_fuzzer.h create mode 100644 test/fuzztest/abilityapppreloadersecond_fuzzer/corpus/init create mode 100644 test/fuzztest/abilityapppreloadersecond_fuzzer/project.xml create mode 100644 test/fuzztest/abilityautostartupclientfirst_fuzzer/BUILD.gn create mode 100644 test/fuzztest/abilityautostartupclientfirst_fuzzer/abilityautostartupclientfirst_fuzzer.cpp create mode 100644 test/fuzztest/abilityautostartupclientfirst_fuzzer/abilityautostartupclientfirst_fuzzer.h create mode 100644 test/fuzztest/abilityautostartupclientfirst_fuzzer/corpus/init create mode 100644 test/fuzztest/abilityautostartupclientfirst_fuzzer/project.xml create mode 100644 test/fuzztest/abilityautostartupclientsecond_fuzzer/BUILD.gn create mode 100644 test/fuzztest/abilityautostartupclientsecond_fuzzer/abilityautostartupclientsecond_fuzzer.cpp create mode 100644 test/fuzztest/abilityautostartupclientsecond_fuzzer/abilityautostartupclientsecond_fuzzer.h create mode 100644 test/fuzztest/abilityautostartupclientsecond_fuzzer/corpus/init create mode 100644 test/fuzztest/abilityautostartupclientsecond_fuzzer/project.xml create mode 100644 test/fuzztest/abilityautostartupclientthird_fuzzer/BUILD.gn create mode 100644 test/fuzztest/abilityautostartupclientthird_fuzzer/abilityautostartupclientthird_fuzzer.cpp create mode 100644 test/fuzztest/abilityautostartupclientthird_fuzzer/abilityautostartupclientthird_fuzzer.h create mode 100644 test/fuzztest/abilityautostartupclientthird_fuzzer/corpus/init create mode 100644 test/fuzztest/abilityautostartupclientthird_fuzzer/project.xml create mode 100644 test/fuzztest/abilityautostartupdatamanagerfifth_fuzzer/BUILD.gn create mode 100644 test/fuzztest/abilityautostartupdatamanagerfifth_fuzzer/abilityautostartupdatamanagerfifth_fuzzer.cpp create mode 100644 test/fuzztest/abilityautostartupdatamanagerfifth_fuzzer/abilityautostartupdatamanagerfifth_fuzzer.h create mode 100644 test/fuzztest/abilityautostartupdatamanagerfifth_fuzzer/corpus/init create mode 100644 test/fuzztest/abilityautostartupdatamanagerfifth_fuzzer/project.xml create mode 100644 test/fuzztest/abilityautostartupdatamanagerfourth_fuzzer/BUILD.gn create mode 100644 test/fuzztest/abilityautostartupdatamanagerfourth_fuzzer/abilityautostartupdatamanagerfourth_fuzzer.cpp create mode 100644 test/fuzztest/abilityautostartupdatamanagerfourth_fuzzer/abilityautostartupdatamanagerfourth_fuzzer.h create mode 100644 test/fuzztest/abilityautostartupdatamanagerfourth_fuzzer/corpus/init create mode 100644 test/fuzztest/abilityautostartupdatamanagerfourth_fuzzer/project.xml create mode 100644 test/fuzztest/abilityautostartupdatamanagerthird_fuzzer/BUILD.gn create mode 100644 test/fuzztest/abilityautostartupdatamanagerthird_fuzzer/abilityautostartupdatamanagerthird_fuzzer.cpp create mode 100644 test/fuzztest/abilityautostartupdatamanagerthird_fuzzer/abilityautostartupdatamanagerthird_fuzzer.h create mode 100644 test/fuzztest/abilityautostartupdatamanagerthird_fuzzer/corpus/init create mode 100644 test/fuzztest/abilityautostartupdatamanagerthird_fuzzer/project.xml diff --git a/test/fuzztest/BUILD.gn b/test/fuzztest/BUILD.gn index fb6a770967..b4a525f03d 100644 --- a/test/fuzztest/BUILD.gn +++ b/test/fuzztest/BUILD.gn @@ -46,10 +46,18 @@ group("fuzztest") { "abilityappmgrrenderstatedata_fuzzer:fuzztest", "abilityappmgrrunningmultiinfo_fuzzer:fuzztest", "abilityapppreloader_fuzzer:fuzztest", + "abilityapppreloaderfirst_fuzzer:fuzztest", + "abilityapppreloadersecond_fuzzer:fuzztest", "abilityattachtimeout_fuzzer:fuzztest", + "abilityautostartupclientfirst_fuzzer:fuzztest", + "abilityautostartupclientsecond_fuzzer:fuzztest", + "abilityautostartupclientthird_fuzzer:fuzztest", "abilityautostartupdatamanager_fuzzer:fuzztest", "abilityautostartupdatamanagera_fuzzer:fuzztest", "abilityautostartupdatamanagerb_fuzzer:fuzztest", + "abilityautostartupdatamanagerfifth_fuzzer:fuzztest", + "abilityautostartupdatamanagerfourth_fuzzer:fuzztest", + "abilityautostartupdatamanagerthird_fuzzer:fuzztest", "abilityautostartupservicea_fuzzer:fuzztest", "abilityautostartupserviceb_fuzzer:fuzztest", "abilitybackgroundconnection_fuzzer:fuzztest", diff --git a/test/fuzztest/abilityapppreloaderfirst_fuzzer/BUILD.gn b/test/fuzztest/abilityapppreloaderfirst_fuzzer/BUILD.gn new file mode 100644 index 0000000000..1b9c996b29 --- /dev/null +++ b/test/fuzztest/abilityapppreloaderfirst_fuzzer/BUILD.gn @@ -0,0 +1,73 @@ +# 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") +##############################fuzztest########################################## +module_output_path = "ability_runtime/appmgrservice" +ohos_fuzztest("AbilityAppPreloaderFirstFuzzTest") { + module_out_path = module_output_path + fuzz_config_file = + "${ability_runtime_test_path}/fuzztest/abilityapppreloaderfirst_fuzzer" + include_dirs = [ + "${ability_runtime_services_path}/appmgr/include", + "${ability_runtime_path}/interfaces/kits/native/appkit/ability_bundle_manager_helper", + ] + + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + sources = [ + "${ability_runtime_services_path}/appmgr/src/app_preloader.cpp", + "abilityapppreloaderfirst_fuzzer.cpp", + ] + + deps = [ + "${ability_runtime_innerkits_path}/app_manager:app_manager", + "${ability_runtime_native_path}/appkit:appkit_manager_helper", + "${ability_runtime_path}/utils/server/startup:startup_util", + "${ability_runtime_services_path}/appmgr:libappms", + "${ability_runtime_services_path}/common:task_handler_wrap", + ] + + external_deps = [ + "ability_base:want", + "appspawn:appspawn_client", + "bundle_framework:appexecfwk_base", + "bundle_framework:appexecfwk_core", + "c_utils:utils", + "ffrt:libffrt", + "hilog:libhilog", + "hitrace:hitrace_meter", + "init:libbegetutil", + "ipc:ipc_core", + "resource_schedule_service:ressched_client", + "samgr:samgr_proxy", + "window_manager:libwm", + ] +} + +############################################################################### +group("fuzztest") { + testonly = true + deps = [] + deps += [ + # deps file + ":AbilityAppPreloaderFirstFuzzTest", + ] +} +############################################################################### diff --git a/test/fuzztest/abilityapppreloaderfirst_fuzzer/abilityapppreloaderfirst_fuzzer.cpp b/test/fuzztest/abilityapppreloaderfirst_fuzzer/abilityapppreloaderfirst_fuzzer.cpp new file mode 100644 index 0000000000..6c79019a24 --- /dev/null +++ b/test/fuzztest/abilityapppreloaderfirst_fuzzer/abilityapppreloaderfirst_fuzzer.cpp @@ -0,0 +1,66 @@ +/* + * 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 "abilityapppreloaderfirst_fuzzer.h" + +#include +#include +#include + +#define private public +#define protected public +#include "app_preloader.h" +#include "bundle_mgr_helper.h" +#undef protected +#undef private +#include "parcel.h" +#include +#include "securec.h" +#include "configuration.h" + +using namespace OHOS::AppExecFwk; + +namespace OHOS { +namespace { +constexpr size_t U32_AT_SIZE = 4; +constexpr size_t STRING_MAX_LENGTH = 128; +} + +bool DoSomethingInterestingWithMyAPI(const uint8_t* data, size_t size) +{ + std::shared_ptr remoteClientManager = std::make_shared(); + auto bundleMgrHelper = std::make_shared(); + remoteClientManager->SetBundleManagerHelper(bundleMgrHelper); + auto appPreloader = std::make_shared(remoteClientManager); + std::string bundleName; + int32_t userId; + int32_t appIndex; + PreloadRequest request; + FuzzedDataProvider fdp(data, size); + bundleName = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH); + userId = fdp.ConsumeIntegralInRange(0, U32_AT_SIZE); + appIndex = fdp.ConsumeIntegralInRange(0, U32_AT_SIZE); + appPreloader->GeneratePreloadRequest(bundleName, userId, appIndex, request); + return true; +} +} + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + // Run your code on data. + OHOS::DoSomethingInterestingWithMyAPI(data, size); + return 0; +} \ No newline at end of file diff --git a/test/fuzztest/abilityapppreloaderfirst_fuzzer/abilityapppreloaderfirst_fuzzer.h b/test/fuzztest/abilityapppreloaderfirst_fuzzer/abilityapppreloaderfirst_fuzzer.h new file mode 100644 index 0000000000..54f1e9c7a5 --- /dev/null +++ b/test/fuzztest/abilityapppreloaderfirst_fuzzer/abilityapppreloaderfirst_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_ABILITYAPPPRELOADER_FIRST_FUZZER_H +#define FUZZTEST_OHOS_ABILITY_RUNTIME_ABILITYAPPPRELOADER_FIRST_FUZZER_H + +#define FUZZ_PROJECT_NAME "abilityapppreloaderfirst_fuzzer" + +#endif // FUZZTEST_OHOS_ABILITY_RUNTIME_ABILITYAPPPRELOADER_FIRST_FUZZER_H diff --git a/test/fuzztest/abilityapppreloaderfirst_fuzzer/corpus/init b/test/fuzztest/abilityapppreloaderfirst_fuzzer/corpus/init new file mode 100644 index 0000000000..8eb5a7d6eb --- /dev/null +++ b/test/fuzztest/abilityapppreloaderfirst_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/abilityapppreloaderfirst_fuzzer/project.xml b/test/fuzztest/abilityapppreloaderfirst_fuzzer/project.xml new file mode 100644 index 0000000000..6e8ad2cfde --- /dev/null +++ b/test/fuzztest/abilityapppreloaderfirst_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/test/fuzztest/abilityapppreloadersecond_fuzzer/BUILD.gn b/test/fuzztest/abilityapppreloadersecond_fuzzer/BUILD.gn new file mode 100644 index 0000000000..220a6f6b03 --- /dev/null +++ b/test/fuzztest/abilityapppreloadersecond_fuzzer/BUILD.gn @@ -0,0 +1,73 @@ +# 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") +##############################fuzztest########################################## +module_output_path = "ability_runtime/appmgrservice" +ohos_fuzztest("AbilityAppPreloaderSecondFuzzTest") { + module_out_path = module_output_path + fuzz_config_file = + "${ability_runtime_test_path}/fuzztest/abilityapppreloadersecond_fuzzer" + include_dirs = [ + "${ability_runtime_services_path}/appmgr/include", + "${ability_runtime_path}/interfaces/kits/native/appkit/ability_bundle_manager_helper", + ] + + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + sources = [ + "${ability_runtime_services_path}/appmgr/src/app_preloader.cpp", + "abilityapppreloadersecond_fuzzer.cpp", + ] + + deps = [ + "${ability_runtime_innerkits_path}/app_manager:app_manager", + "${ability_runtime_native_path}/appkit:appkit_manager_helper", + "${ability_runtime_path}/utils/server/startup:startup_util", + "${ability_runtime_services_path}/appmgr:libappms", + "${ability_runtime_services_path}/common:task_handler_wrap", + ] + + external_deps = [ + "ability_base:want", + "appspawn:appspawn_client", + "bundle_framework:appexecfwk_base", + "bundle_framework:appexecfwk_core", + "c_utils:utils", + "ffrt:libffrt", + "hilog:libhilog", + "hitrace:hitrace_meter", + "init:libbegetutil", + "ipc:ipc_core", + "resource_schedule_service:ressched_client", + "samgr:samgr_proxy", + "window_manager:libwm", + ] +} + +############################################################################### +group("fuzztest") { + testonly = true + deps = [] + deps += [ + # deps file + ":AbilityAppPreloaderSecondFuzzTest", + ] +} +############################################################################### diff --git a/test/fuzztest/abilityapppreloadersecond_fuzzer/abilityapppreloadersecond_fuzzer.cpp b/test/fuzztest/abilityapppreloadersecond_fuzzer/abilityapppreloadersecond_fuzzer.cpp new file mode 100644 index 0000000000..9e0c7d3e16 --- /dev/null +++ b/test/fuzztest/abilityapppreloadersecond_fuzzer/abilityapppreloadersecond_fuzzer.cpp @@ -0,0 +1,64 @@ +/* + * 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 "abilityapppreloadersecond_fuzzer.h" + +#include +#include +#include + +#define private public +#define protected public +#include "app_preloader.h" +#include "bundle_mgr_helper.h" +#undef protected +#undef private +#include "parcel.h" +#include +#include "securec.h" +#include "configuration.h" + +using namespace OHOS::AppExecFwk; + +namespace OHOS { +namespace { +constexpr size_t U32_AT_SIZE = 4; +constexpr size_t STRING_MAX_LENGTH = 128; +} + +bool DoSomethingInterestingWithMyAPI(const uint8_t* data, size_t size) +{ + std::shared_ptr remoteClientManager = std::make_shared(); + auto bundleMgrHelper = std::make_shared(); + remoteClientManager->SetBundleManagerHelper(bundleMgrHelper); + auto appPreloader = std::make_shared(remoteClientManager); + std::string bundleName; + int32_t userId; + AAFwk::Want launchWant; + FuzzedDataProvider fdp(data, size); + bundleName = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH); + userId = fdp.ConsumeIntegralInRange(0, U32_AT_SIZE); + appPreloader->GetLaunchWant(bundleName, userId, launchWant); + return true; +} +} + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + // Run your code on data. + OHOS::DoSomethingInterestingWithMyAPI(data, size); + return 0; +} \ No newline at end of file diff --git a/test/fuzztest/abilityapppreloadersecond_fuzzer/abilityapppreloadersecond_fuzzer.h b/test/fuzztest/abilityapppreloadersecond_fuzzer/abilityapppreloadersecond_fuzzer.h new file mode 100644 index 0000000000..9ac9d6c32d --- /dev/null +++ b/test/fuzztest/abilityapppreloadersecond_fuzzer/abilityapppreloadersecond_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_ABILITYAPPPRELOADER_SECOND_FUZZER_H +#define FUZZTEST_OHOS_ABILITY_RUNTIME_ABILITYAPPPRELOADER_SECOND_FUZZER_H + +#define FUZZ_PROJECT_NAME "abilityapppreloadersecond_fuzzer" + +#endif // FUZZTEST_OHOS_ABILITY_RUNTIME_ABILITYAPPPRELOADER_SECOND_FUZZER_H diff --git a/test/fuzztest/abilityapppreloadersecond_fuzzer/corpus/init b/test/fuzztest/abilityapppreloadersecond_fuzzer/corpus/init new file mode 100644 index 0000000000..8eb5a7d6eb --- /dev/null +++ b/test/fuzztest/abilityapppreloadersecond_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/abilityapppreloadersecond_fuzzer/project.xml b/test/fuzztest/abilityapppreloadersecond_fuzzer/project.xml new file mode 100644 index 0000000000..6e8ad2cfde --- /dev/null +++ b/test/fuzztest/abilityapppreloadersecond_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/test/fuzztest/abilityautostartupclientfirst_fuzzer/BUILD.gn b/test/fuzztest/abilityautostartupclientfirst_fuzzer/BUILD.gn new file mode 100644 index 0000000000..81af2fa30e --- /dev/null +++ b/test/fuzztest/abilityautostartupclientfirst_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("AbilityAutoStartupClientFirstFuzzTest") { + module_out_path = module_output_path + + fuzz_config_file = + "${ability_runtime_test_path}/fuzztest/abilityautostartupclientfirst_fuzzer" + include_dirs = [ + "${ability_runtime_innerkits_path}/ability_manager/include", + "${ability_runtime_services_path}/abilitymgr/include/utils", + "${ability_runtime_services_path}/abilitymgr/include", + ] + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + sources = [ + "${ability_runtime_services_path}/abilitymgr/src/ability_auto_startup_client.cpp", + "${ability_runtime_services_path}/common/src/app_utils.cpp", + "${ability_runtime_services_path}/common/src/json_utils.cpp", + "abilityautostartupclientfirst_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", + "access_token:libaccesstoken_sdk", + "access_token:libtokenid_sdk", + "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", + "kv_store:distributeddata_inner", + "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 + ":AbilityAutoStartupClientFirstFuzzTest", + ] +} +############################################################################### diff --git a/test/fuzztest/abilityautostartupclientfirst_fuzzer/abilityautostartupclientfirst_fuzzer.cpp b/test/fuzztest/abilityautostartupclientfirst_fuzzer/abilityautostartupclientfirst_fuzzer.cpp new file mode 100644 index 0000000000..3fdb026720 --- /dev/null +++ b/test/fuzztest/abilityautostartupclientfirst_fuzzer/abilityautostartupclientfirst_fuzzer.cpp @@ -0,0 +1,63 @@ +/* + * 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 "abilityautostartupclientfirst_fuzzer.h" + +#include +#include +#include + +#define private public +#include "ability_auto_startup_client.h" +#undef private + +#include "securec.h" + +using namespace OHOS::AAFwk; +using namespace OHOS::AppExecFwk; + +namespace OHOS { +namespace { +constexpr size_t U32_AT_SIZE = 4; +constexpr size_t STRING_MAX_LENGTH = 128; +} + +bool DoSomethingInterestingWithMyAPI(const uint8_t* data, size_t size) +{ + auto abilityAutoStartupClient = AbilityAutoStartupClient::GetInstance(); + abilityAutoStartupClient->Connect(); + AutoStartupInfo info; + FuzzedDataProvider fdp(data, size); + info.appCloneIndex = fdp.ConsumeIntegralInRange(0, U32_AT_SIZE); + info.userId = fdp.ConsumeIntegralInRange(0, U32_AT_SIZE); + info.retryCount = fdp.ConsumeIntegralInRange(0, U32_AT_SIZE); + info.bundleName = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH); + info.abilityName = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH); + info.moduleName = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH); + info.abilityTypeName = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH); + info.accessTokenId = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH); + bool boolParam = fdp.ConsumeBool(); + abilityAutoStartupClient->SetApplicationAutoStartupByEDM(info, boolParam); + return true; +} +} + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + // Run your code on data. + OHOS::DoSomethingInterestingWithMyAPI(data, size); + return 0; +} \ No newline at end of file diff --git a/test/fuzztest/abilityautostartupclientfirst_fuzzer/abilityautostartupclientfirst_fuzzer.h b/test/fuzztest/abilityautostartupclientfirst_fuzzer/abilityautostartupclientfirst_fuzzer.h new file mode 100644 index 0000000000..6e6da9d636 --- /dev/null +++ b/test/fuzztest/abilityautostartupclientfirst_fuzzer/abilityautostartupclientfirst_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_ABILITY_AUTO_STARTUP_CLIENT_FIRST_FUZZER_H +#define FUZZTEST_OHOS_ABILITY_RUNTIME_ABILITY_AUTO_STARTUP_CLIENT_FIRST_FUZZER_H + +#define FUZZ_PROJECT_NAME "abilityautostartupclientfirst_fuzzer" + +#endif // FUZZTEST_OHOS_ABILITY_RUNTIME_ABILITY_AUTO_STARTUP_CLIENT_FIRST_FUZZER_H diff --git a/test/fuzztest/abilityautostartupclientfirst_fuzzer/corpus/init b/test/fuzztest/abilityautostartupclientfirst_fuzzer/corpus/init new file mode 100644 index 0000000000..6198079a28 --- /dev/null +++ b/test/fuzztest/abilityautostartupclientfirst_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/abilityautostartupclientfirst_fuzzer/project.xml b/test/fuzztest/abilityautostartupclientfirst_fuzzer/project.xml new file mode 100644 index 0000000000..7133b2b924 --- /dev/null +++ b/test/fuzztest/abilityautostartupclientfirst_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/test/fuzztest/abilityautostartupclientsecond_fuzzer/BUILD.gn b/test/fuzztest/abilityautostartupclientsecond_fuzzer/BUILD.gn new file mode 100644 index 0000000000..0ee5fb2ad6 --- /dev/null +++ b/test/fuzztest/abilityautostartupclientsecond_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("AbilityAutoStartupClientSecondFuzzTest") { + module_out_path = module_output_path + + fuzz_config_file = + "${ability_runtime_test_path}/fuzztest/abilityautostartupclientsecond_fuzzer" + include_dirs = [ + "${ability_runtime_innerkits_path}/ability_manager/include", + "${ability_runtime_services_path}/abilitymgr/include/utils", + "${ability_runtime_services_path}/abilitymgr/include", + ] + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + sources = [ + "${ability_runtime_services_path}/abilitymgr/src/ability_auto_startup_client.cpp", + "${ability_runtime_services_path}/common/src/app_utils.cpp", + "${ability_runtime_services_path}/common/src/json_utils.cpp", + "abilityautostartupclientsecond_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", + "access_token:libaccesstoken_sdk", + "access_token:libtokenid_sdk", + "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", + "kv_store:distributeddata_inner", + "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 + ":AbilityAutoStartupClientSecondFuzzTest", + ] +} +############################################################################### diff --git a/test/fuzztest/abilityautostartupclientsecond_fuzzer/abilityautostartupclientsecond_fuzzer.cpp b/test/fuzztest/abilityautostartupclientsecond_fuzzer/abilityautostartupclientsecond_fuzzer.cpp new file mode 100644 index 0000000000..9d573d89fc --- /dev/null +++ b/test/fuzztest/abilityautostartupclientsecond_fuzzer/abilityautostartupclientsecond_fuzzer.cpp @@ -0,0 +1,63 @@ +/* + * 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 "abilityautostartupclientsecond_fuzzer.h" + +#include +#include +#include + +#define private public +#include "ability_auto_startup_client.h" +#undef private + +#include "securec.h" + +using namespace OHOS::AAFwk; +using namespace OHOS::AppExecFwk; + +namespace OHOS { +namespace { +constexpr size_t U32_AT_SIZE = 4; +constexpr size_t STRING_MAX_LENGTH = 128; +} + +bool DoSomethingInterestingWithMyAPI(const uint8_t* data, size_t size) +{ + auto abilityAutoStartupClient = AbilityAutoStartupClient::GetInstance(); + abilityAutoStartupClient->Connect(); + AutoStartupInfo info; + FuzzedDataProvider fdp(data, size); + info.appCloneIndex = fdp.ConsumeIntegralInRange(0, U32_AT_SIZE); + info.userId = fdp.ConsumeIntegralInRange(0, U32_AT_SIZE); + info.retryCount = fdp.ConsumeIntegralInRange(0, U32_AT_SIZE); + info.bundleName = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH); + info.abilityName = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH); + info.moduleName = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH); + info.abilityTypeName = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH); + info.accessTokenId = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH); + bool boolParam = fdp.ConsumeBool(); + abilityAutoStartupClient->CancelApplicationAutoStartupByEDM(info, boolParam); + return true; +} +} + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + // Run your code on data. + OHOS::DoSomethingInterestingWithMyAPI(data, size); + return 0; +} \ No newline at end of file diff --git a/test/fuzztest/abilityautostartupclientsecond_fuzzer/abilityautostartupclientsecond_fuzzer.h b/test/fuzztest/abilityautostartupclientsecond_fuzzer/abilityautostartupclientsecond_fuzzer.h new file mode 100644 index 0000000000..afdf86b837 --- /dev/null +++ b/test/fuzztest/abilityautostartupclientsecond_fuzzer/abilityautostartupclientsecond_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_ABILITY_AUTO_STARTUP_CLIENT_SECOND_FUZZER_H +#define FUZZTEST_OHOS_ABILITY_RUNTIME_ABILITY_AUTO_STARTUP_CLIENT_SECOND_FUZZER_H + +#define FUZZ_PROJECT_NAME "abilityautostartupclientsecond_fuzzer" + +#endif // FUZZTEST_OHOS_ABILITY_RUNTIME_ABILITY_AUTO_STARTUP_CLIENT_SECOND_FUZZER_H diff --git a/test/fuzztest/abilityautostartupclientsecond_fuzzer/corpus/init b/test/fuzztest/abilityautostartupclientsecond_fuzzer/corpus/init new file mode 100644 index 0000000000..6198079a28 --- /dev/null +++ b/test/fuzztest/abilityautostartupclientsecond_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/abilityautostartupclientsecond_fuzzer/project.xml b/test/fuzztest/abilityautostartupclientsecond_fuzzer/project.xml new file mode 100644 index 0000000000..7133b2b924 --- /dev/null +++ b/test/fuzztest/abilityautostartupclientsecond_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/test/fuzztest/abilityautostartupclientthird_fuzzer/BUILD.gn b/test/fuzztest/abilityautostartupclientthird_fuzzer/BUILD.gn new file mode 100644 index 0000000000..13330018b3 --- /dev/null +++ b/test/fuzztest/abilityautostartupclientthird_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("AbilityAutoStartupClientThirdFuzzTest") { + module_out_path = module_output_path + + fuzz_config_file = + "${ability_runtime_test_path}/fuzztest/abilityautostartupclientthird_fuzzer" + include_dirs = [ + "${ability_runtime_innerkits_path}/ability_manager/include", + "${ability_runtime_services_path}/abilitymgr/include/utils", + "${ability_runtime_services_path}/abilitymgr/include", + ] + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + sources = [ + "${ability_runtime_services_path}/abilitymgr/src/ability_auto_startup_client.cpp", + "${ability_runtime_services_path}/common/src/app_utils.cpp", + "${ability_runtime_services_path}/common/src/json_utils.cpp", + "abilityautostartupclientthird_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", + "access_token:libaccesstoken_sdk", + "access_token:libtokenid_sdk", + "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", + "kv_store:distributeddata_inner", + "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 + ":AbilityAutoStartupClientThirdFuzzTest", + ] +} +############################################################################### diff --git a/test/fuzztest/abilityautostartupclientthird_fuzzer/abilityautostartupclientthird_fuzzer.cpp b/test/fuzztest/abilityautostartupclientthird_fuzzer/abilityautostartupclientthird_fuzzer.cpp new file mode 100644 index 0000000000..be4c3a599c --- /dev/null +++ b/test/fuzztest/abilityautostartupclientthird_fuzzer/abilityautostartupclientthird_fuzzer.cpp @@ -0,0 +1,71 @@ +/* + * 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 "abilityautostartupclientthird_fuzzer.h" + +#include +#include +#include + +#define private public +#include "ability_auto_startup_client.h" +#undef private + +#include "securec.h" + +using namespace OHOS::AAFwk; +using namespace OHOS::AppExecFwk; + +namespace OHOS { +namespace { +constexpr size_t U32_AT_SIZE = 4; +constexpr size_t STRING_MAX_LENGTH = 128; +void GetRandomAutoStartupInfo(FuzzedDataProvider& fdp, AutoStartupInfo& info) +{ + info.appCloneIndex = fdp.ConsumeIntegralInRange(0, U32_AT_SIZE); + info.userId = fdp.ConsumeIntegralInRange(0, U32_AT_SIZE); + info.retryCount = fdp.ConsumeIntegralInRange(0, U32_AT_SIZE); + info.bundleName = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH); + info.abilityName = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH); + info.moduleName = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH); + info.abilityTypeName = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH); + info.accessTokenId = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH); +} +} + +bool DoSomethingInterestingWithMyAPI(const uint8_t* data, size_t size) +{ + auto abilityAutoStartupClient = AbilityAutoStartupClient::GetInstance(); + abilityAutoStartupClient->Connect(); + AutoStartupInfo info; + std::vector infoList; + FuzzedDataProvider fdp(data, size); + size_t arraySize = fdp.ConsumeIntegralInRange(0, U32_AT_SIZE); + for (size_t i = 0; i < arraySize; ++i) { + GetRandomAutoStartupInfo(fdp, info); + infoList.emplace_back(info); + } + abilityAutoStartupClient->QueryAllAutoStartupApplications(infoList); + return true; +} +} + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + // Run your code on data. + OHOS::DoSomethingInterestingWithMyAPI(data, size); + return 0; +} \ No newline at end of file diff --git a/test/fuzztest/abilityautostartupclientthird_fuzzer/abilityautostartupclientthird_fuzzer.h b/test/fuzztest/abilityautostartupclientthird_fuzzer/abilityautostartupclientthird_fuzzer.h new file mode 100644 index 0000000000..1b189e5e03 --- /dev/null +++ b/test/fuzztest/abilityautostartupclientthird_fuzzer/abilityautostartupclientthird_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_ABILITY_AUTO_STARTUP_CLIENT_THIRD_FUZZER_H +#define FUZZTEST_OHOS_ABILITY_RUNTIME_ABILITY_AUTO_STARTUP_CLIENT_THIRD_FUZZER_H + +#define FUZZ_PROJECT_NAME "abilityautostartupclientthird_fuzzer" + +#endif // FUZZTEST_OHOS_ABILITY_RUNTIME_ABILITY_AUTO_STARTUP_CLIENT_THIRD_FUZZER_H diff --git a/test/fuzztest/abilityautostartupclientthird_fuzzer/corpus/init b/test/fuzztest/abilityautostartupclientthird_fuzzer/corpus/init new file mode 100644 index 0000000000..6198079a28 --- /dev/null +++ b/test/fuzztest/abilityautostartupclientthird_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/abilityautostartupclientthird_fuzzer/project.xml b/test/fuzztest/abilityautostartupclientthird_fuzzer/project.xml new file mode 100644 index 0000000000..7133b2b924 --- /dev/null +++ b/test/fuzztest/abilityautostartupclientthird_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/test/fuzztest/abilityautostartupdatamanagerfifth_fuzzer/BUILD.gn b/test/fuzztest/abilityautostartupdatamanagerfifth_fuzzer/BUILD.gn new file mode 100644 index 0000000000..0fb1603274 --- /dev/null +++ b/test/fuzztest/abilityautostartupdatamanagerfifth_fuzzer/BUILD.gn @@ -0,0 +1,93 @@ +# 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("AbilityAutoStartupDataManagerFifthFuzzTest") { + module_out_path = module_output_path + + fuzz_config_file = "${ability_runtime_test_path}/fuzztest/abilityautostartupdatamanagerfifth_fuzzer" + include_dirs = [ + "${ability_runtime_innerkits_path}/ability_manager/include", + "${ability_runtime_services_path}/abilitymgr/include/utils", + "${ability_runtime_services_path}/abilitymgr/include", + ] + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + sources = [ + "${ability_runtime_innerkits_path}/deps_wrapper/src/os_account_manager_wrapper.cpp", + "${ability_runtime_services_path}/abilitymgr/src/ability_auto_startup_data_manager.cpp", + "${ability_runtime_services_path}/common/src/app_utils.cpp", + "${ability_runtime_services_path}/common/src/json_utils.cpp", + "abilityautostartupdatamanagerfifth_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", + "access_token:libaccesstoken_sdk", + "access_token:libtokenid_sdk", + "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", + "init:libbegetutil", + "ipc:ipc_core", + "kv_store:distributeddata_inner", + "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 + ":AbilityAutoStartupDataManagerFifthFuzzTest", + ] +} +############################################################################### diff --git a/test/fuzztest/abilityautostartupdatamanagerfifth_fuzzer/abilityautostartupdatamanagerfifth_fuzzer.cpp b/test/fuzztest/abilityautostartupdatamanagerfifth_fuzzer/abilityautostartupdatamanagerfifth_fuzzer.cpp new file mode 100644 index 0000000000..f5d0678cfa --- /dev/null +++ b/test/fuzztest/abilityautostartupdatamanagerfifth_fuzzer/abilityautostartupdatamanagerfifth_fuzzer.cpp @@ -0,0 +1,73 @@ +/* + * 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 "abilityautostartupdatamanagerfifth_fuzzer.h" + +#include +#include +#include +#include + +#define private public +#include "ability_auto_startup_data_manager.h" +#undef private + +#include "ability_record.h" + +using namespace OHOS::AAFwk; +using namespace OHOS::AppExecFwk; + +namespace OHOS { +namespace { +constexpr size_t U32_AT_SIZE = 4; +constexpr size_t STRING_MAX_LENGTH = 128; +void GetRandomAutoStartupInfo(FuzzedDataProvider& fdp, AutoStartupInfo& info) +{ + info.appCloneIndex = fdp.ConsumeIntegralInRange(0, U32_AT_SIZE); + info.userId = fdp.ConsumeIntegralInRange(0, U32_AT_SIZE); + info.retryCount = fdp.ConsumeIntegralInRange(0, U32_AT_SIZE); + info.bundleName = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH); + info.abilityName = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH); + info.moduleName = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH); + info.abilityTypeName = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH); + info.accessTokenId = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH); +} +} + +bool DoSomethingInterestingWithMyAPI(const uint8_t* data, size_t size) +{ + auto abilityAutoStartupDataManager = std::make_shared(); + AutoStartupInfo info; + std::vector infoList; + std::string strParam; + FuzzedDataProvider fdp(data, size); + strParam = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH); + size_t arraySize = fdp.ConsumeIntegralInRange(0, U32_AT_SIZE); + for (size_t i = 0; i < arraySize; ++i) { + GetRandomAutoStartupInfo(fdp, info); + infoList.emplace_back(info); + } + abilityAutoStartupDataManager->GetCurrentAppAutoStartupData(strParam, infoList, strParam); + return true; +} +} + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + // Run your code on data. + OHOS::DoSomethingInterestingWithMyAPI(data, size); + return 0; +} \ No newline at end of file diff --git a/test/fuzztest/abilityautostartupdatamanagerfifth_fuzzer/abilityautostartupdatamanagerfifth_fuzzer.h b/test/fuzztest/abilityautostartupdatamanagerfifth_fuzzer/abilityautostartupdatamanagerfifth_fuzzer.h new file mode 100644 index 0000000000..13c0e70c2f --- /dev/null +++ b/test/fuzztest/abilityautostartupdatamanagerfifth_fuzzer/abilityautostartupdatamanagerfifth_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_ABILITY_AUTO_STARTUP_DATA_MANAGER_FIFTH_FUZZER_H +#define FUZZTEST_OHOS_ABILITY_RUNTIME_ABILITY_AUTO_STARTUP_DATA_MANAGER_FIFTH_FUZZER_H + +#define FUZZ_PROJECT_NAME "abilityautostartupdatamanagerfifth_fuzzer" + +#endif // FUZZTEST_OHOS_ABILITY_RUNTIME_ABILITY_AUTO_STARTUP_DATA_MANAGER_FIFTH_FUZZER_H diff --git a/test/fuzztest/abilityautostartupdatamanagerfifth_fuzzer/corpus/init b/test/fuzztest/abilityautostartupdatamanagerfifth_fuzzer/corpus/init new file mode 100644 index 0000000000..6198079a28 --- /dev/null +++ b/test/fuzztest/abilityautostartupdatamanagerfifth_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/abilityautostartupdatamanagerfifth_fuzzer/project.xml b/test/fuzztest/abilityautostartupdatamanagerfifth_fuzzer/project.xml new file mode 100644 index 0000000000..7133b2b924 --- /dev/null +++ b/test/fuzztest/abilityautostartupdatamanagerfifth_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/test/fuzztest/abilityautostartupdatamanagerfourth_fuzzer/BUILD.gn b/test/fuzztest/abilityautostartupdatamanagerfourth_fuzzer/BUILD.gn new file mode 100644 index 0000000000..a9d2d9155c --- /dev/null +++ b/test/fuzztest/abilityautostartupdatamanagerfourth_fuzzer/BUILD.gn @@ -0,0 +1,93 @@ +# 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("AbilityAutoStartupDataManagerFourthFuzzTest") { + module_out_path = module_output_path + + fuzz_config_file = "${ability_runtime_test_path}/fuzztest/abilityautostartupdatamanagerfourth_fuzzer" + include_dirs = [ + "${ability_runtime_innerkits_path}/ability_manager/include", + "${ability_runtime_services_path}/abilitymgr/include/utils", + "${ability_runtime_services_path}/abilitymgr/include", + ] + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + sources = [ + "${ability_runtime_innerkits_path}/deps_wrapper/src/os_account_manager_wrapper.cpp", + "${ability_runtime_services_path}/abilitymgr/src/ability_auto_startup_data_manager.cpp", + "${ability_runtime_services_path}/common/src/app_utils.cpp", + "${ability_runtime_services_path}/common/src/json_utils.cpp", + "abilityautostartupdatamanagerfourth_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", + "access_token:libaccesstoken_sdk", + "access_token:libtokenid_sdk", + "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", + "init:libbegetutil", + "ipc:ipc_core", + "kv_store:distributeddata_inner", + "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 + ":AbilityAutoStartupDataManagerFourthFuzzTest", + ] +} +############################################################################### diff --git a/test/fuzztest/abilityautostartupdatamanagerfourth_fuzzer/abilityautostartupdatamanagerfourth_fuzzer.cpp b/test/fuzztest/abilityautostartupdatamanagerfourth_fuzzer/abilityautostartupdatamanagerfourth_fuzzer.cpp new file mode 100644 index 0000000000..893f1f58dd --- /dev/null +++ b/test/fuzztest/abilityautostartupdatamanagerfourth_fuzzer/abilityautostartupdatamanagerfourth_fuzzer.cpp @@ -0,0 +1,72 @@ +/* + * 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 "abilityautostartupdatamanagerfourth_fuzzer.h" + +#include +#include +#include +#include + +#define private public +#include "ability_auto_startup_data_manager.h" +#undef private + +#include "ability_record.h" + +using namespace OHOS::AAFwk; +using namespace OHOS::AppExecFwk; + +namespace OHOS { +namespace { +constexpr size_t U32_AT_SIZE = 4; +constexpr size_t STRING_MAX_LENGTH = 128; +void GetRandomAutoStartupInfo(FuzzedDataProvider& fdp, AutoStartupInfo& info) +{ + info.appCloneIndex = fdp.ConsumeIntegralInRange(0, U32_AT_SIZE); + info.userId = fdp.ConsumeIntegralInRange(0, U32_AT_SIZE); + info.retryCount = fdp.ConsumeIntegralInRange(0, U32_AT_SIZE); + info.bundleName = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH); + info.abilityName = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH); + info.moduleName = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH); + info.abilityTypeName = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH); + info.accessTokenId = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH); +} +} + +bool DoSomethingInterestingWithMyAPI(const uint8_t* data, size_t size) +{ + auto abilityAutoStartupDataManager = std::make_shared(); + FuzzedDataProvider fdp(data, size); + AutoStartupInfo info; + std::vector infoList; + int32_t in32Param = fdp.ConsumeIntegralInRange(0, U32_AT_SIZE); + size_t arraySize = fdp.ConsumeIntegralInRange(0, U32_AT_SIZE); + for (size_t i = 0; i < arraySize; ++i) { + GetRandomAutoStartupInfo(fdp, info); + infoList.emplace_back(info); + } + abilityAutoStartupDataManager->QueryAllAutoStartupApplications(infoList, in32Param); + return true; +} +} + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + // Run your code on data. + OHOS::DoSomethingInterestingWithMyAPI(data, size); + return 0; +} \ No newline at end of file diff --git a/test/fuzztest/abilityautostartupdatamanagerfourth_fuzzer/abilityautostartupdatamanagerfourth_fuzzer.h b/test/fuzztest/abilityautostartupdatamanagerfourth_fuzzer/abilityautostartupdatamanagerfourth_fuzzer.h new file mode 100644 index 0000000000..6d0f72d8c4 --- /dev/null +++ b/test/fuzztest/abilityautostartupdatamanagerfourth_fuzzer/abilityautostartupdatamanagerfourth_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_ABILITY_AUTO_STARTUP_DATA_MANAGER_FOURTH_FUZZER_H +#define FUZZTEST_OHOS_ABILITY_RUNTIME_ABILITY_AUTO_STARTUP_DATA_MANAGER_FOURTH_FUZZER_H + +#define FUZZ_PROJECT_NAME "abilityautostartupdatamanagerfourth_fuzzer" + +#endif // FUZZTEST_OHOS_ABILITY_RUNTIME_ABILITY_AUTO_STARTUP_DATA_MANAGER_FOURTH_FUZZER_H diff --git a/test/fuzztest/abilityautostartupdatamanagerfourth_fuzzer/corpus/init b/test/fuzztest/abilityautostartupdatamanagerfourth_fuzzer/corpus/init new file mode 100644 index 0000000000..6198079a28 --- /dev/null +++ b/test/fuzztest/abilityautostartupdatamanagerfourth_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/abilityautostartupdatamanagerfourth_fuzzer/project.xml b/test/fuzztest/abilityautostartupdatamanagerfourth_fuzzer/project.xml new file mode 100644 index 0000000000..7133b2b924 --- /dev/null +++ b/test/fuzztest/abilityautostartupdatamanagerfourth_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/test/fuzztest/abilityautostartupdatamanagerthird_fuzzer/BUILD.gn b/test/fuzztest/abilityautostartupdatamanagerthird_fuzzer/BUILD.gn new file mode 100644 index 0000000000..067c26c149 --- /dev/null +++ b/test/fuzztest/abilityautostartupdatamanagerthird_fuzzer/BUILD.gn @@ -0,0 +1,93 @@ +# 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("AbilityAutoStartupDataManagerThirdFuzzTest") { + module_out_path = module_output_path + + fuzz_config_file = "${ability_runtime_test_path}/fuzztest/abilityautostartupdatamanagerthird_fuzzer" + include_dirs = [ + "${ability_runtime_innerkits_path}/ability_manager/include", + "${ability_runtime_services_path}/abilitymgr/include/utils", + "${ability_runtime_services_path}/abilitymgr/include", + ] + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + sources = [ + "${ability_runtime_innerkits_path}/deps_wrapper/src/os_account_manager_wrapper.cpp", + "${ability_runtime_services_path}/abilitymgr/src/ability_auto_startup_data_manager.cpp", + "${ability_runtime_services_path}/common/src/app_utils.cpp", + "${ability_runtime_services_path}/common/src/json_utils.cpp", + "abilityautostartupdatamanagerthird_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", + "access_token:libaccesstoken_sdk", + "access_token:libtokenid_sdk", + "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", + "init:libbegetutil", + "ipc:ipc_core", + "kv_store:distributeddata_inner", + "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 + ":AbilityAutoStartupDataManagerThirdFuzzTest", + ] +} +############################################################################### diff --git a/test/fuzztest/abilityautostartupdatamanagerthird_fuzzer/abilityautostartupdatamanagerthird_fuzzer.cpp b/test/fuzztest/abilityautostartupdatamanagerthird_fuzzer/abilityautostartupdatamanagerthird_fuzzer.cpp new file mode 100644 index 0000000000..768851aebf --- /dev/null +++ b/test/fuzztest/abilityautostartupdatamanagerthird_fuzzer/abilityautostartupdatamanagerthird_fuzzer.cpp @@ -0,0 +1,62 @@ +/* + * 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 "abilityautostartupdatamanagerthird_fuzzer.h" + +#include +#include +#include +#include + +#define private public +#include "ability_auto_startup_data_manager.h" +#undef private + +#include "ability_record.h" + +using namespace OHOS::AAFwk; +using namespace OHOS::AppExecFwk; + +namespace OHOS { +namespace { +constexpr size_t U32_AT_SIZE = 4; +constexpr size_t STRING_MAX_LENGTH = 128; +} + +bool DoSomethingInterestingWithMyAPI(const uint8_t* data, size_t size) +{ + auto abilityAutoStartupDataManager = std::make_shared(); + AutoStartupInfo info; + FuzzedDataProvider fdp(data, size); + info.appCloneIndex = fdp.ConsumeIntegralInRange(0, U32_AT_SIZE); + info.userId = fdp.ConsumeIntegralInRange(0, U32_AT_SIZE); + info.retryCount = fdp.ConsumeIntegralInRange(0, U32_AT_SIZE); + info.bundleName = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH); + info.abilityName = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH); + info.moduleName = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH); + info.abilityTypeName = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH); + info.accessTokenId = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH); + abilityAutoStartupDataManager->QueryAutoStartupData(info); + return true; +} +} + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + // Run your code on data. + OHOS::DoSomethingInterestingWithMyAPI(data, size); + return 0; +} \ No newline at end of file diff --git a/test/fuzztest/abilityautostartupdatamanagerthird_fuzzer/abilityautostartupdatamanagerthird_fuzzer.h b/test/fuzztest/abilityautostartupdatamanagerthird_fuzzer/abilityautostartupdatamanagerthird_fuzzer.h new file mode 100644 index 0000000000..95840b8818 --- /dev/null +++ b/test/fuzztest/abilityautostartupdatamanagerthird_fuzzer/abilityautostartupdatamanagerthird_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_ABILITY_AUTO_STARTUP_DATA_MANAGER_THIRD_FUZZER_H +#define FUZZTEST_OHOS_ABILITY_RUNTIME_ABILITY_AUTO_STARTUP_DATA_MANAGER_THIRD_FUZZER_H + +#define FUZZ_PROJECT_NAME "abilityautostartupdatamanagerthird_fuzzer" + +#endif // FUZZTEST_OHOS_ABILITY_RUNTIME_ABILITY_AUTO_STARTUP_DATA_MANAGER_THIRD_FUZZER_H diff --git a/test/fuzztest/abilityautostartupdatamanagerthird_fuzzer/corpus/init b/test/fuzztest/abilityautostartupdatamanagerthird_fuzzer/corpus/init new file mode 100644 index 0000000000..6198079a28 --- /dev/null +++ b/test/fuzztest/abilityautostartupdatamanagerthird_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/abilityautostartupdatamanagerthird_fuzzer/project.xml b/test/fuzztest/abilityautostartupdatamanagerthird_fuzzer/project.xml new file mode 100644 index 0000000000..7133b2b924 --- /dev/null +++ b/test/fuzztest/abilityautostartupdatamanagerthird_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + +