From edc012a27eccbf16653e09532b19f5d39b5023df Mon Sep 17 00:00:00 2001 From: lyq Date: Wed, 25 Jun 2025 15:56:36 +0800 Subject: [PATCH] add fuzz Signed-off-by: lyq Change-Id: I6ec78af2b0af718428f2133ea74137089592a455 --- test/fuzztest/fuzztest_bundlemanager/BUILD.gn | 5 + .../BUILD.gn | 84 +++++++++ .../bmsaddfirstinstallbundleinfo_fuzzer.cpp | 49 +++++ .../bmsaddfirstinstallbundleinfo_fuzzer.h | 21 +++ .../corpus/init | 1 + .../project.xml | 25 +++ .../BUILD.gn | 173 ++++++++++++++++++ .../bmscheckabilityenableinstall_fuzzer.cpp | 61 ++++++ .../bmscheckabilityenableinstall_fuzzer.h | 21 +++ .../corpus/init | 1 + .../project.xml | 25 +++ .../BUILD.gn | 84 +++++++++ ...bmsdeletefirstinstallbundleinfo_fuzzer.cpp | 46 +++++ .../bmsdeletefirstinstallbundleinfo_fuzzer.h | 21 +++ .../corpus/init | 1 + .../project.xml | 25 +++ .../BUILD.gn | 84 +++++++++ .../bmsaddfirstinstallbundleinfo_fuzzer.h | 21 +++ .../bmsgetfirstinstallbundleinfo_fuzzer.cpp | 49 +++++ .../corpus/init | 1 + .../project.xml | 25 +++ .../bmsonqueryrpcidfinished_fuzzer/BUILD.gn | 173 ++++++++++++++++++ .../bmsonqueryrpcidfinished_fuzzer.cpp | 0 .../bmsonqueryrpcidfinished_fuzzer.h | 21 +++ .../corpus/init | 1 + .../project.xml | 25 +++ .../bmssendcallback_fuzzer.cpp | 2 + .../bmssendcallback_fuzzer/project.xml | 2 +- 28 files changed, 1046 insertions(+), 1 deletion(-) create mode 100644 test/fuzztest/fuzztest_bundlemanager/bmsaddfirstinstallbundleinfo_fuzzer/BUILD.gn create mode 100644 test/fuzztest/fuzztest_bundlemanager/bmsaddfirstinstallbundleinfo_fuzzer/bmsaddfirstinstallbundleinfo_fuzzer.cpp create mode 100644 test/fuzztest/fuzztest_bundlemanager/bmsaddfirstinstallbundleinfo_fuzzer/bmsaddfirstinstallbundleinfo_fuzzer.h create mode 100644 test/fuzztest/fuzztest_bundlemanager/bmsaddfirstinstallbundleinfo_fuzzer/corpus/init create mode 100644 test/fuzztest/fuzztest_bundlemanager/bmsaddfirstinstallbundleinfo_fuzzer/project.xml create mode 100644 test/fuzztest/fuzztest_bundlemanager/bmscheckabilityenableinstall_fuzzer/BUILD.gn create mode 100644 test/fuzztest/fuzztest_bundlemanager/bmscheckabilityenableinstall_fuzzer/bmscheckabilityenableinstall_fuzzer.cpp create mode 100644 test/fuzztest/fuzztest_bundlemanager/bmscheckabilityenableinstall_fuzzer/bmscheckabilityenableinstall_fuzzer.h create mode 100644 test/fuzztest/fuzztest_bundlemanager/bmscheckabilityenableinstall_fuzzer/corpus/init create mode 100644 test/fuzztest/fuzztest_bundlemanager/bmscheckabilityenableinstall_fuzzer/project.xml create mode 100644 test/fuzztest/fuzztest_bundlemanager/bmsdeletefirstinstallbundleinfo_fuzzer/BUILD.gn create mode 100644 test/fuzztest/fuzztest_bundlemanager/bmsdeletefirstinstallbundleinfo_fuzzer/bmsdeletefirstinstallbundleinfo_fuzzer.cpp create mode 100644 test/fuzztest/fuzztest_bundlemanager/bmsdeletefirstinstallbundleinfo_fuzzer/bmsdeletefirstinstallbundleinfo_fuzzer.h create mode 100644 test/fuzztest/fuzztest_bundlemanager/bmsdeletefirstinstallbundleinfo_fuzzer/corpus/init create mode 100644 test/fuzztest/fuzztest_bundlemanager/bmsdeletefirstinstallbundleinfo_fuzzer/project.xml create mode 100644 test/fuzztest/fuzztest_bundlemanager/bmsgetfirstinstallbundleinfo_fuzzer/BUILD.gn create mode 100644 test/fuzztest/fuzztest_bundlemanager/bmsgetfirstinstallbundleinfo_fuzzer/bmsaddfirstinstallbundleinfo_fuzzer.h create mode 100644 test/fuzztest/fuzztest_bundlemanager/bmsgetfirstinstallbundleinfo_fuzzer/bmsgetfirstinstallbundleinfo_fuzzer.cpp create mode 100644 test/fuzztest/fuzztest_bundlemanager/bmsgetfirstinstallbundleinfo_fuzzer/corpus/init create mode 100644 test/fuzztest/fuzztest_bundlemanager/bmsgetfirstinstallbundleinfo_fuzzer/project.xml create mode 100644 test/fuzztest/fuzztest_bundlemanager/bmsonqueryrpcidfinished_fuzzer/BUILD.gn create mode 100644 test/fuzztest/fuzztest_bundlemanager/bmsonqueryrpcidfinished_fuzzer/bmsonqueryrpcidfinished_fuzzer.cpp create mode 100644 test/fuzztest/fuzztest_bundlemanager/bmsonqueryrpcidfinished_fuzzer/bmsonqueryrpcidfinished_fuzzer.h create mode 100644 test/fuzztest/fuzztest_bundlemanager/bmsonqueryrpcidfinished_fuzzer/corpus/init create mode 100644 test/fuzztest/fuzztest_bundlemanager/bmsonqueryrpcidfinished_fuzzer/project.xml diff --git a/test/fuzztest/fuzztest_bundlemanager/BUILD.gn b/test/fuzztest/fuzztest_bundlemanager/BUILD.gn index d4747fc0ee..36cf714763 100644 --- a/test/fuzztest/fuzztest_bundlemanager/BUILD.gn +++ b/test/fuzztest/fuzztest_bundlemanager/BUILD.gn @@ -23,6 +23,7 @@ group("bundlemanagerfuzztest") { "bmsabilityinfomarshalling_fuzzer:BMSAbilityInfoMarshallingFuzzTest", "bmsabilityinfounmarshalling_fuzzer:BMSAbilityInfoUnmarshallingFuzzTest", "bmsaccounthelper_fuzzer:BMSAccountHelperFuzzTest", + "bmsaddfirstinstallbundleinfo_fuzzer:BMSAddFirstInstallBundleInfoFuzzTest", "bmsaginghandlerchain_fuzzer:BMSAgingHandlerChainFuzzTest", "bmsagingrequest_fuzzer:BMSAgingRequestFuzzTest", "bmsagingutil_fuzzer:BMSAgingUtilFuzzTest", @@ -58,9 +59,11 @@ group("bundlemanagerfuzztest") { "bmscleanbundlecachefiles_fuzzer:BMSCleanBundleCacheFilesFuzzTest", "bmscleanbundledatafiles_fuzzer:BMSCleanBundleDataFilesFuzzTest", "bmscleancachecallbackproxy_fuzzer:BMSCleanCacheCallbackProxyFuzzTest", + "bmscheckabilityenableinstall_fuzzer:BMSCheckAbilityEnableInstallFuzzTest", "bmscompatibleabilityinfo_fuzzer:BMSCompatibleAbilityInfoFuzzTest", "bmscompatibleapplicationinfo_fuzzer:BMSCompatibleApplicationInfoFuzzTest", "bmsconverttargetabilityinfo_fuzzer:BMSConvertTargetAbilityInfoFuzzTest", + "bmsdeletefirstinstallbundleinfo_fuzzer:BMSDeleteFirstInstallBundleInfoFuzzTest", "bmsextensionabilityinfo_fuzzer:BMSExtensionAbilityInfoFuzzTest", "bmsforminfo_fuzzer:BMSFormInfoFuzzTest", "bmsgetabilitylabel_fuzzer:BMSGetAbilityLabelFuzzTest", @@ -78,6 +81,7 @@ group("bundlemanagerfuzztest") { "bmsgetbundlesforuid_fuzzer:BMSGetBundlesForUidFuzzTest", "bmsgetdefaultapplication_fuzzer:BMSGetDefaultApplicationFuzzTest", "bmsgetdisposedstatus_fuzzer:BMSGetDisposedStatusFuzzTest", + "bmsgetfirstinstallbundleinfo_fuzzer:BMSAddFirstInstallBundleInfoFuzzTest", "bmsgethapmoduleinfo_fuzzer:BMSGetHapModuleInfoFuzzTest", "bmsgetlaunchwantforbundle_fuzzer:BMSGetLaunchWantForBundleFuzzTest", "bmsgetnameforuid_fuzzer:BMSGetNameForUidFuzzTest", @@ -85,6 +89,7 @@ group("bundlemanagerfuzztest") { "bmshapmoduleinfo_fuzzer:BMSHapModuleInfoFuzzTest", "bmsinstallparam_fuzzer:BMSInstallParamFuzzTest", "bmsisexistfirstinstallbundleinfo_fuzzer:BMSIsExistFirstInstallBundleInfoFuzzTest", + "bmsonqueryrpcidfinished_fuzzer:BMSOnQueryRpcIdFinishedFuzzTest", "bmsqueryabilityinfobyuri_fuzzer:BMSQueryAbilityInfoByUriFuzzTest", "bmsqueryabilityinfos_fuzzer:BMSQueryAbilityInfosFuzzTest", "bmsqueryabilityinfosbyuri_fuzzer:BMSQueryAbilityInfosByUriFuzzTest", diff --git a/test/fuzztest/fuzztest_bundlemanager/bmsaddfirstinstallbundleinfo_fuzzer/BUILD.gn b/test/fuzztest/fuzztest_bundlemanager/bmsaddfirstinstallbundleinfo_fuzzer/BUILD.gn new file mode 100644 index 0000000000..6f01bf7483 --- /dev/null +++ b/test/fuzztest/fuzztest_bundlemanager/bmsaddfirstinstallbundleinfo_fuzzer/BUILD.gn @@ -0,0 +1,84 @@ +# Copyright (c) 2025 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +#####################hydra-fuzz################### +import("//build/config/features.gni") +import("//build/ohos.gni") +import("//build/test.gni") +import("../../../../appexecfwk.gni") +import("../../../../services/bundlemgr/appexecfwk_bundlemgr.gni") +module_output_path = fuzz_test_path + +##############################fuzztest########################################## +ohos_fuzztest("BMSGetFirstInstallBundleInfoFuzzTest") { + module_out_path = module_output_path + fuzz_config_file = + "../../../fuzztest/fuzztest_bundlemanager/bmsaddfirstinstallbundleinfo_fuzzer" + + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + + sources = [ + "${services_path}/bundlemgr/src/rdb/bms_rdb_open_callback.cpp", + "${services_path}/bundlemgr/src/rdb/rdb_data_manager.cpp", + "${services_path}/bundlemgr/src/bundle_data_storage_rdb.cpp", + "${services_path}/bundlemgr/src/preinstall_data_storage_rdb.cpp", + "bmsaddfirstinstallbundleinfo_fuzzer.cpp", + ] + sources += bundle_install_sources + sources += bundle_mgr_source + + deps = [ + "${base_path}:appexecfwk_base", + "${common_path}:libappexecfwk_common", + "${core_path}:appexecfwk_core", + "${services_path}/bundlemgr:libbms", + ] + deps += bundle_install_deps + + include_dirs = [ + "${services_path}/bundlemgr/include/first_install_data_mgr", + "${services_path}/bundlemgr/include/rdb", + "${services_path}/bundlemgr/include/common", + "${services_path}/bundlemgr/include/inner_bundle_info.h", + "${test_path}/fuzztest", + ] + + external_deps = [ + "ability_base:want", + "c_utils:utils", + "ipc:ipc_core", + "hilog:libhilog", + "ability_runtime:app_manager", + "access_token:el5_filekey_manager_sdk", + "access_token:libaccesstoken_sdk", + "access_token:libprivacy_sdk", + "access_token:libtokenid_sdk", + "appverify:libhapverify", + "common_event_service:cesfwk_innerkits", + "eventhandler:libeventhandler", + "hitrace:hitrace_meter", + "init:libbegetutil", + "kv_store:distributeddata_inner", + "relational_store:native_rdb", + "safwk:system_ability_fwk", + "samgr:samgr_proxy", + "selinux_adapter:librestorecon", + "syscap_codec:syscap_interface_shared", + ] + external_deps += bundle_install_external_deps +} \ No newline at end of file diff --git a/test/fuzztest/fuzztest_bundlemanager/bmsaddfirstinstallbundleinfo_fuzzer/bmsaddfirstinstallbundleinfo_fuzzer.cpp b/test/fuzztest/fuzztest_bundlemanager/bmsaddfirstinstallbundleinfo_fuzzer/bmsaddfirstinstallbundleinfo_fuzzer.cpp new file mode 100644 index 0000000000..7145a2645a --- /dev/null +++ b/test/fuzztest/fuzztest_bundlemanager/bmsaddfirstinstallbundleinfo_fuzzer/bmsaddfirstinstallbundleinfo_fuzzer.cpp @@ -0,0 +1,49 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include + +#include "first_install_data_mgr/first_install_data_mgr_storage_rdb.h" +#include "bmsaddfirstinstallbundleinfo_fuzzer.h" +#include "bms_fuzztest_util.h" + +using namespace OHOS::AppExecFwk; +using namespace OHOS::AppExecFwk::BMSFuzzTestUtil; +namespace OHOS { +bool FuzzFirstInstallBundleInfo(const uint8_t *data, size_t size) +{ + auto firstInstallDataMgr = std::make_shared(); + if (firstInstallDataMgr == nullptr) { + return false; + } + FuzzedDataProvider fdp(data, size); + std::string bundleName = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH); + int32_t userId = GenerateRandomUser(fdp); + FirstInstallBundleInfo firstInstallBundleInfo; + firstInstallBundleInfo.firstInstallTime = fdp.ConsumeIntegral(); + firstInstallDataMgr->AddFirstInstallBundleInfo(bundleName, userId, firstInstallBundleInfo); + return true; +} +} + +// Fuzzer entry point. +extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) +{ + // Run your code on data. + OHOS::FuzzFirstInstallBundleInfo(data, size); + return 0; +} \ No newline at end of file diff --git a/test/fuzztest/fuzztest_bundlemanager/bmsaddfirstinstallbundleinfo_fuzzer/bmsaddfirstinstallbundleinfo_fuzzer.h b/test/fuzztest/fuzztest_bundlemanager/bmsaddfirstinstallbundleinfo_fuzzer/bmsaddfirstinstallbundleinfo_fuzzer.h new file mode 100644 index 0000000000..dcacc73da6 --- /dev/null +++ b/test/fuzztest/fuzztest_bundlemanager/bmsaddfirstinstallbundleinfo_fuzzer/bmsaddfirstinstallbundleinfo_fuzzer.h @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef TEST_FUZZTEST_ADD_FIRST_INSTALL_BUNDLE_INFO_FUZZER_H +#define TEST_FUZZTEST_ADD_FIRST_INSTALL_BUNDLE_INFO_FUZZER_H + +#define FUZZ_PROJECT_NAME "bmsaddfirstinstallbundleinfo_fuzzer" + +#endif \ No newline at end of file diff --git a/test/fuzztest/fuzztest_bundlemanager/bmsaddfirstinstallbundleinfo_fuzzer/corpus/init b/test/fuzztest/fuzztest_bundlemanager/bmsaddfirstinstallbundleinfo_fuzzer/corpus/init new file mode 100644 index 0000000000..6b7212c8a6 --- /dev/null +++ b/test/fuzztest/fuzztest_bundlemanager/bmsaddfirstinstallbundleinfo_fuzzer/corpus/init @@ -0,0 +1 @@ +FUZZ \ No newline at end of file diff --git a/test/fuzztest/fuzztest_bundlemanager/bmsaddfirstinstallbundleinfo_fuzzer/project.xml b/test/fuzztest/fuzztest_bundlemanager/bmsaddfirstinstallbundleinfo_fuzzer/project.xml new file mode 100644 index 0000000000..500f6f4144 --- /dev/null +++ b/test/fuzztest/fuzztest_bundlemanager/bmsaddfirstinstallbundleinfo_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + \ No newline at end of file diff --git a/test/fuzztest/fuzztest_bundlemanager/bmscheckabilityenableinstall_fuzzer/BUILD.gn b/test/fuzztest/fuzztest_bundlemanager/bmscheckabilityenableinstall_fuzzer/BUILD.gn new file mode 100644 index 0000000000..7370294932 --- /dev/null +++ b/test/fuzztest/fuzztest_bundlemanager/bmscheckabilityenableinstall_fuzzer/BUILD.gn @@ -0,0 +1,173 @@ +# Copyright (c) 2025 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import("//build/test.gni") +import("../../../../appexecfwk.gni") +import("../../../../services/bundlemgr/appexecfwk_bundlemgr.gni") + +module_output_path = fuzz_test_path + +ohos_fuzztest("BMSCheckAbilityEnableInstallFuzzTest") { + use_exceptions = true + module_out_path = module_output_path + fuzz_config_file = + "../../../fuzztest/fuzztest_bundlemanager/bmscheckabilityenableinstall_fuzzer" + include_dirs = [ "${test_path}/fuzztest" ] + sources = bundle_mgr_source + sources += [ + "${services_path}/bundlemgr/src/aot/aot_executor.cpp", + "${services_path}/bundlemgr/src/installd/installd_host_impl.cpp", + "${services_path}/bundlemgr/src/installd/installd_operator.cpp", + "${services_path}/bundlemgr/src/installd/installd_permission_mgr.cpp", + "bmscheckabilityenableinstall_fuzzer.cpp", + ] + + sources += bundle_install_sources + + configs = [ + "${services_path}/bundlemgr/test:bundlemgr_test_config", + "${inner_api_path}/appexecfwk_base:appexecfwk_base_sdk_config", + ] + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + + deps = [ "${core_path}:appexecfwk_core" ] + + deps += bundle_install_deps + + external_deps = [ + "ability_base:want", + "ability_runtime:ability_manager", + "ability_runtime:app_manager", + "access_token:el5_filekey_manager_sdk", + "access_token:libprivacy_sdk", + "access_token:libtokenid_sdk", + "appspawn:hnpapi", + "appverify:libhapverify", + "bounds_checking_function:libsec_shared", + "common_event_service:cesfwk_innerkits", + "eventhandler:libeventhandler", + "hilog:libhilog", + "hitrace:hitrace_meter", + "init:libbegetutil", + "jsoncpp:jsoncpp", + "safwk:system_ability_fwk", + "samgr:samgr_proxy", + "selinux_adapter:librestorecon", + ] + external_deps += bundle_install_external_deps + if (bundle_framework_graphics) { + external_deps += [ "image_framework:image_native" ] + } + defines = [] + if (code_signature_enable) { + sources += [ + "${services_path}/bundlemgr/src/aot/aot_sign_data_cache_mgr.cpp", + "${services_path}/bundlemgr/src/code_sign_helper.cpp", + ] + include_dirs += [ "${services_path}/bundlemgr/include" ] + external_deps += [ + "bounds_checking_function:libsec_shared", + "code_signature:libcode_sign_utils", + "ets_runtime:libcompiler_service", + ] + defines += [ "CODE_SIGNATURE_ENABLE" ] + } + if (current_cpu == "arm64") { + defines += [ "USE_ARM64" ] + } + if (account_enable) { + external_deps += [ "os_account:os_account_innerkits" ] + defines += [ "ACCOUNT_ENABLE" ] + } + if (ability_runtime_enable) { + external_deps += [ "ability_runtime:ability_manager" ] + } + if (bundle_framework_free_install) { + sources += aging + sources += free_install + sources += distributed_manager + external_deps += [ + "ability_runtime:app_manager", + "battery_manager:batterysrv_client", + "device_usage_statistics:usagestatsinner", + "display_manager:displaymgr", + "power_manager:powermgr_client", + "syscap_codec:syscap_interface_shared", + ] + defines += [ "BUNDLE_FRAMEWORK_FREE_INSTALL" ] + } + if (global_resmgr_enable) { + defines += [ "GLOBAL_RESMGR_ENABLE" ] + external_deps += [ "resource_management:global_resmgr" ] + } + if (hicollie_enable) { + external_deps += [ "hicollie:libhicollie" ] + defines += [ "HICOLLIE_ENABLE" ] + } + + if (hisysevent_enable) { + sources += [ "${services_path}/bundlemgr/src/inner_event_report.cpp" ] + external_deps += [ "hisysevent:libhisysevent" ] + defines += [ "HISYSEVENT_ENABLE" ] + } + + if (storage_service_enable) { + external_deps += [ "storage_service:storage_manager_sa_proxy" ] + defines += [ "STORAGE_SERVICE_ENABLE" ] + } + + configs += [ "${services_path}/bundlemgr:rdb_config" ] + external_deps += [ "relational_store:native_rdb" ] + sources += [ + "${services_path}/bundlemgr/src/bundle_data_storage_rdb.cpp", + "${services_path}/bundlemgr/src/preinstall_data_storage_rdb.cpp", + "${services_path}/bundlemgr/src/rdb/bms_rdb_open_callback.cpp", + "${services_path}/bundlemgr/src/rdb/rdb_data_manager.cpp", + ] + if (bundle_framework_app_control) { + defines += [ "BUNDLE_FRAMEWORK_APP_CONTROL" ] + sources += [ + "${services_path}/bundlemgr/src/app_control/app_control_manager.cpp", + "${services_path}/bundlemgr/src/app_control/app_control_manager_host_impl.cpp", + "${services_path}/bundlemgr/src/app_control/app_control_manager_rdb.cpp", + "${services_path}/bundlemgr/src/app_control/app_jump_interceptor_event_subscriber.cpp", + "${services_path}/bundlemgr/src/app_control/app_jump_interceptor_manager_rdb.cpp", + ] + include_dirs += [ "${services_path}/bundlemgr/include/app_control" ] + external_deps += [ "c_utils:utils" ] + } + if (udmf_enabled) { + defines += [ "BUNDLE_FRAMEWORK_UDMF_ENABLED" ] + external_deps += [ "udmf:utd_client" ] + } + + if (user_auth_framework_impl_enabled) { + external_deps += [ "user_auth_framework:userauth_client" ] + defines += [ "BMS_USER_AUTH_FRAMEWORK_ENABLED" ] + include_dirs += [ "${services_path}/bundlemgr/include/user_auth" ] + sources += user_auth + } + + if (bms_device_info_manager_part_enabled) { + external_deps += [ + "device_info_manager:distributed_device_profile_common", + "device_info_manager:distributed_device_profile_sdk", + ] + defines += [ "BMS_DEVICE_INFO_MANAGER_ENABLE" ] + } +} \ No newline at end of file diff --git a/test/fuzztest/fuzztest_bundlemanager/bmscheckabilityenableinstall_fuzzer/bmscheckabilityenableinstall_fuzzer.cpp b/test/fuzztest/fuzztest_bundlemanager/bmscheckabilityenableinstall_fuzzer/bmscheckabilityenableinstall_fuzzer.cpp new file mode 100644 index 0000000000..5f8a86cc78 --- /dev/null +++ b/test/fuzztest/fuzztest_bundlemanager/bmscheckabilityenableinstall_fuzzer/bmscheckabilityenableinstall_fuzzer.cpp @@ -0,0 +1,61 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include +#include +#define private public +#include "bundle_distributed_manager.h" +#include "bmscheckabilityenableinstall_fuzzer.h" +#include "bms_fuzztest_util.h" + +using Want = OHOS::AAFwk::Want; +using namespace OHOS::AppExecFwk; +using namespace OHOS::AppExecFwk::BMSFuzzTestUtil; +namespace OHOS { +std::string DEVICE_ID_NORMAL = "deviceId"; +std::string BUNDLE_NAME_TEST = "com.example.bundlekit.test"; +std::string MODULE_NAME_MY_APPLICATION = "com.example.MyModuleName"; +std::string ABILITY_NAME_MY_APPLICATION = "com.example.MyApplication.MainAbility"; +bool DoSomethingInterestingWithMyAPI(const uint8_t* data, size_t size) +{ + std::shared_ptr BundleDistributedManager_ = + std::make_shared(); + if (BundleDistributedManager_ == nullptr) { + return false; + } + FuzzedDataProvider fdp(data, size); + Want want; + std::string deviceId = DEVICE_ID_NORMAL; + std::string bundleName = BUNDLE_NAME_TEST; + std::string moduleName = MODULE_NAME_MY_APPLICATION; + std::string abilityName = ABILITY_NAME_MY_APPLICATION; + want.SetElementName(deviceId, bundleName, moduleName, abilityName); + int32_t missionId = fdp.ConsumeIntegral(); + int32_t userId = GenerateRandomUser(fdp); + sptr callerToken = nullptr; + BundleDistributedManager_->CheckAbilityEnableInstall(want, missionId, userId, callerToken); + 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/fuzztest_bundlemanager/bmscheckabilityenableinstall_fuzzer/bmscheckabilityenableinstall_fuzzer.h b/test/fuzztest/fuzztest_bundlemanager/bmscheckabilityenableinstall_fuzzer/bmscheckabilityenableinstall_fuzzer.h new file mode 100644 index 0000000000..7bf36990b1 --- /dev/null +++ b/test/fuzztest/fuzztest_bundlemanager/bmscheckabilityenableinstall_fuzzer/bmscheckabilityenableinstall_fuzzer.h @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef TEST_FUZZTEST_CHECK_ABILITY_ENABLE_INSTALL_FUZZER_H +#define TEST_FUZZTEST_CHECK_ABILITY_ENABLE_INSTALL_FUZZER_H + +#define FUZZ_PROJECT_NAME "bmscheckabilityenableinstall_fuzzer" + +#endif \ No newline at end of file diff --git a/test/fuzztest/fuzztest_bundlemanager/bmscheckabilityenableinstall_fuzzer/corpus/init b/test/fuzztest/fuzztest_bundlemanager/bmscheckabilityenableinstall_fuzzer/corpus/init new file mode 100644 index 0000000000..6b7212c8a6 --- /dev/null +++ b/test/fuzztest/fuzztest_bundlemanager/bmscheckabilityenableinstall_fuzzer/corpus/init @@ -0,0 +1 @@ +FUZZ \ No newline at end of file diff --git a/test/fuzztest/fuzztest_bundlemanager/bmscheckabilityenableinstall_fuzzer/project.xml b/test/fuzztest/fuzztest_bundlemanager/bmscheckabilityenableinstall_fuzzer/project.xml new file mode 100644 index 0000000000..500f6f4144 --- /dev/null +++ b/test/fuzztest/fuzztest_bundlemanager/bmscheckabilityenableinstall_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + \ No newline at end of file diff --git a/test/fuzztest/fuzztest_bundlemanager/bmsdeletefirstinstallbundleinfo_fuzzer/BUILD.gn b/test/fuzztest/fuzztest_bundlemanager/bmsdeletefirstinstallbundleinfo_fuzzer/BUILD.gn new file mode 100644 index 0000000000..0bfcf2d068 --- /dev/null +++ b/test/fuzztest/fuzztest_bundlemanager/bmsdeletefirstinstallbundleinfo_fuzzer/BUILD.gn @@ -0,0 +1,84 @@ +# Copyright (c) 2025 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +#####################hydra-fuzz################### +import("//build/config/features.gni") +import("//build/ohos.gni") +import("//build/test.gni") +import("../../../../appexecfwk.gni") +import("../../../../services/bundlemgr/appexecfwk_bundlemgr.gni") +module_output_path = fuzz_test_path + +##############################fuzztest########################################## +ohos_fuzztest("BMSDeleteFirstInstallBundleInfoFuzzTest") { + module_out_path = module_output_path + fuzz_config_file = + "../../../fuzztest/fuzztest_bundlemanager/bmsdeletefirstinstallbundleinfo_fuzzer" + + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + + sources = [ + "${services_path}/bundlemgr/src/rdb/bms_rdb_open_callback.cpp", + "${services_path}/bundlemgr/src/rdb/rdb_data_manager.cpp", + "${services_path}/bundlemgr/src/bundle_data_storage_rdb.cpp", + "${services_path}/bundlemgr/src/preinstall_data_storage_rdb.cpp", + "bmsdeletefirstinstallbundleinfo_fuzzer.cpp", + ] + sources += bundle_install_sources + sources += bundle_mgr_source + + deps = [ + "${base_path}:appexecfwk_base", + "${common_path}:libappexecfwk_common", + "${core_path}:appexecfwk_core", + "${services_path}/bundlemgr:libbms", + ] + deps += bundle_install_deps + + include_dirs = [ + "${services_path}/bundlemgr/include/first_install_data_mgr", + "${services_path}/bundlemgr/include/rdb", + "${services_path}/bundlemgr/include/common", + "${services_path}/bundlemgr/include/inner_bundle_info.h", + "${test_path}/fuzztest", + ] + + external_deps = [ + "ability_base:want", + "c_utils:utils", + "ipc:ipc_core", + "hilog:libhilog", + "ability_runtime:app_manager", + "access_token:el5_filekey_manager_sdk", + "access_token:libaccesstoken_sdk", + "access_token:libprivacy_sdk", + "access_token:libtokenid_sdk", + "appverify:libhapverify", + "common_event_service:cesfwk_innerkits", + "eventhandler:libeventhandler", + "hitrace:hitrace_meter", + "init:libbegetutil", + "kv_store:distributeddata_inner", + "relational_store:native_rdb", + "safwk:system_ability_fwk", + "samgr:samgr_proxy", + "selinux_adapter:librestorecon", + "syscap_codec:syscap_interface_shared", + ] + external_deps += bundle_install_external_deps +} \ No newline at end of file diff --git a/test/fuzztest/fuzztest_bundlemanager/bmsdeletefirstinstallbundleinfo_fuzzer/bmsdeletefirstinstallbundleinfo_fuzzer.cpp b/test/fuzztest/fuzztest_bundlemanager/bmsdeletefirstinstallbundleinfo_fuzzer/bmsdeletefirstinstallbundleinfo_fuzzer.cpp new file mode 100644 index 0000000000..b2f682d8d1 --- /dev/null +++ b/test/fuzztest/fuzztest_bundlemanager/bmsdeletefirstinstallbundleinfo_fuzzer/bmsdeletefirstinstallbundleinfo_fuzzer.cpp @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include + +#include "first_install_data_mgr/first_install_data_mgr_storage_rdb.h" +#include "bmsdeletefirstinstallbundleinfo_fuzzer.h" +#include "bms_fuzztest_util.h" + +using namespace OHOS::AppExecFwk; +using namespace OHOS::AppExecFwk::BMSFuzzTestUtil; +namespace OHOS { +bool FuzzFirstInstallBundleInfo(const uint8_t *data, size_t size) +{ + auto firstInstallDataMgr = std::make_shared(); + if (firstInstallDataMgr == nullptr) { + return false; + } + FuzzedDataProvider fdp(data, size); + int32_t userId = GenerateRandomUser(fdp); + firstInstallDataMgr->DeleteFirstInstallBundleInfo(userId); + return true; +} +} + +// Fuzzer entry point. +extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) +{ + // Run your code on data. + OHOS::FuzzFirstInstallBundleInfo(data, size); + return 0; +} \ No newline at end of file diff --git a/test/fuzztest/fuzztest_bundlemanager/bmsdeletefirstinstallbundleinfo_fuzzer/bmsdeletefirstinstallbundleinfo_fuzzer.h b/test/fuzztest/fuzztest_bundlemanager/bmsdeletefirstinstallbundleinfo_fuzzer/bmsdeletefirstinstallbundleinfo_fuzzer.h new file mode 100644 index 0000000000..11aae3fddf --- /dev/null +++ b/test/fuzztest/fuzztest_bundlemanager/bmsdeletefirstinstallbundleinfo_fuzzer/bmsdeletefirstinstallbundleinfo_fuzzer.h @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef TEST_FUZZTEST_GET_FIRST_INSTALL_BUNDLE_INFO_FUZZER_H +#define TEST_FUZZTEST_GET_FIRST_INSTALL_BUNDLE_INFO_FUZZER_H + +#define FUZZ_PROJECT_NAME "bmsdeletefirstinstallbundleinfo_fuzzer" + +#endif \ No newline at end of file diff --git a/test/fuzztest/fuzztest_bundlemanager/bmsdeletefirstinstallbundleinfo_fuzzer/corpus/init b/test/fuzztest/fuzztest_bundlemanager/bmsdeletefirstinstallbundleinfo_fuzzer/corpus/init new file mode 100644 index 0000000000..6b7212c8a6 --- /dev/null +++ b/test/fuzztest/fuzztest_bundlemanager/bmsdeletefirstinstallbundleinfo_fuzzer/corpus/init @@ -0,0 +1 @@ +FUZZ \ No newline at end of file diff --git a/test/fuzztest/fuzztest_bundlemanager/bmsdeletefirstinstallbundleinfo_fuzzer/project.xml b/test/fuzztest/fuzztest_bundlemanager/bmsdeletefirstinstallbundleinfo_fuzzer/project.xml new file mode 100644 index 0000000000..500f6f4144 --- /dev/null +++ b/test/fuzztest/fuzztest_bundlemanager/bmsdeletefirstinstallbundleinfo_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + \ No newline at end of file diff --git a/test/fuzztest/fuzztest_bundlemanager/bmsgetfirstinstallbundleinfo_fuzzer/BUILD.gn b/test/fuzztest/fuzztest_bundlemanager/bmsgetfirstinstallbundleinfo_fuzzer/BUILD.gn new file mode 100644 index 0000000000..69cde02268 --- /dev/null +++ b/test/fuzztest/fuzztest_bundlemanager/bmsgetfirstinstallbundleinfo_fuzzer/BUILD.gn @@ -0,0 +1,84 @@ +# Copyright (c) 2025 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +#####################hydra-fuzz################### +import("//build/config/features.gni") +import("//build/ohos.gni") +import("//build/test.gni") +import("../../../../appexecfwk.gni") +import("../../../../services/bundlemgr/appexecfwk_bundlemgr.gni") +module_output_path = fuzz_test_path + +##############################fuzztest########################################## +ohos_fuzztest("BMSAddFirstInstallBundleInfoFuzzTest") { + module_out_path = module_output_path + fuzz_config_file = + "../../../fuzztest/fuzztest_bundlemanager/bmsgetfirstinstallbundleinfo_fuzzer" + + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + + sources = [ + "${services_path}/bundlemgr/src/rdb/bms_rdb_open_callback.cpp", + "${services_path}/bundlemgr/src/rdb/rdb_data_manager.cpp", + "${services_path}/bundlemgr/src/bundle_data_storage_rdb.cpp", + "${services_path}/bundlemgr/src/preinstall_data_storage_rdb.cpp", + "bmsgetfirstinstallbundleinfo_fuzzer.cpp", + ] + sources += bundle_install_sources + sources += bundle_mgr_source + + deps = [ + "${base_path}:appexecfwk_base", + "${common_path}:libappexecfwk_common", + "${core_path}:appexecfwk_core", + "${services_path}/bundlemgr:libbms", + ] + deps += bundle_install_deps + + include_dirs = [ + "${services_path}/bundlemgr/include/first_install_data_mgr", + "${services_path}/bundlemgr/include/rdb", + "${services_path}/bundlemgr/include/common", + "${services_path}/bundlemgr/include/inner_bundle_info.h", + "${test_path}/fuzztest", + ] + + external_deps = [ + "ability_base:want", + "c_utils:utils", + "ipc:ipc_core", + "hilog:libhilog", + "ability_runtime:app_manager", + "access_token:el5_filekey_manager_sdk", + "access_token:libaccesstoken_sdk", + "access_token:libprivacy_sdk", + "access_token:libtokenid_sdk", + "appverify:libhapverify", + "common_event_service:cesfwk_innerkits", + "eventhandler:libeventhandler", + "hitrace:hitrace_meter", + "init:libbegetutil", + "kv_store:distributeddata_inner", + "relational_store:native_rdb", + "safwk:system_ability_fwk", + "samgr:samgr_proxy", + "selinux_adapter:librestorecon", + "syscap_codec:syscap_interface_shared", + ] + external_deps += bundle_install_external_deps +} \ No newline at end of file diff --git a/test/fuzztest/fuzztest_bundlemanager/bmsgetfirstinstallbundleinfo_fuzzer/bmsaddfirstinstallbundleinfo_fuzzer.h b/test/fuzztest/fuzztest_bundlemanager/bmsgetfirstinstallbundleinfo_fuzzer/bmsaddfirstinstallbundleinfo_fuzzer.h new file mode 100644 index 0000000000..9762953c23 --- /dev/null +++ b/test/fuzztest/fuzztest_bundlemanager/bmsgetfirstinstallbundleinfo_fuzzer/bmsaddfirstinstallbundleinfo_fuzzer.h @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef TEST_FUZZTEST_GET_FIRST_INSTALL_BUNDLE_INFO_FUZZER_H +#define TEST_FUZZTEST_GET_FIRST_INSTALL_BUNDLE_INFO_FUZZER_H + +#define FUZZ_PROJECT_NAME "bmsgetfirstinstallbundleinfo_fuzzer" + +#endif \ No newline at end of file diff --git a/test/fuzztest/fuzztest_bundlemanager/bmsgetfirstinstallbundleinfo_fuzzer/bmsgetfirstinstallbundleinfo_fuzzer.cpp b/test/fuzztest/fuzztest_bundlemanager/bmsgetfirstinstallbundleinfo_fuzzer/bmsgetfirstinstallbundleinfo_fuzzer.cpp new file mode 100644 index 0000000000..a5420c15b0 --- /dev/null +++ b/test/fuzztest/fuzztest_bundlemanager/bmsgetfirstinstallbundleinfo_fuzzer/bmsgetfirstinstallbundleinfo_fuzzer.cpp @@ -0,0 +1,49 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include +#include +#include + +#include "first_install_data_mgr/first_install_data_mgr_storage_rdb.h" +#include "bmsgetfirstinstallbundleinfo_fuzzer.h" +#include "bms_fuzztest_util.h" + +using namespace OHOS::AppExecFwk; +using namespace OHOS::AppExecFwk::BMSFuzzTestUtil; +namespace OHOS { +bool FuzzFirstInstallBundleInfo(const uint8_t *data, size_t size) +{ + auto firstInstallDataMgr = std::make_shared(); + if (firstInstallDataMgr == nullptr) { + return false; + } + FuzzedDataProvider fdp(data, size); + std::string bundleName = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH); + int32_t userId = GenerateRandomUser(fdp); + FirstInstallBundleInfo firstInstallBundleInfo; + firstInstallBundleInfo.firstInstallTime = fdp.ConsumeIntegral(); + firstInstallDataMgr->GetFirstInstallBundleInfo(bundleName, userId, firstInstallBundleInfo); + return true; +} +} + +// Fuzzer entry point. +extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) +{ + // Run your code on data. + OHOS::FuzzFirstInstallBundleInfo(data, size); + return 0; +} \ No newline at end of file diff --git a/test/fuzztest/fuzztest_bundlemanager/bmsgetfirstinstallbundleinfo_fuzzer/corpus/init b/test/fuzztest/fuzztest_bundlemanager/bmsgetfirstinstallbundleinfo_fuzzer/corpus/init new file mode 100644 index 0000000000..6b7212c8a6 --- /dev/null +++ b/test/fuzztest/fuzztest_bundlemanager/bmsgetfirstinstallbundleinfo_fuzzer/corpus/init @@ -0,0 +1 @@ +FUZZ \ No newline at end of file diff --git a/test/fuzztest/fuzztest_bundlemanager/bmsgetfirstinstallbundleinfo_fuzzer/project.xml b/test/fuzztest/fuzztest_bundlemanager/bmsgetfirstinstallbundleinfo_fuzzer/project.xml new file mode 100644 index 0000000000..500f6f4144 --- /dev/null +++ b/test/fuzztest/fuzztest_bundlemanager/bmsgetfirstinstallbundleinfo_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + \ No newline at end of file diff --git a/test/fuzztest/fuzztest_bundlemanager/bmsonqueryrpcidfinished_fuzzer/BUILD.gn b/test/fuzztest/fuzztest_bundlemanager/bmsonqueryrpcidfinished_fuzzer/BUILD.gn new file mode 100644 index 0000000000..813e2ad894 --- /dev/null +++ b/test/fuzztest/fuzztest_bundlemanager/bmsonqueryrpcidfinished_fuzzer/BUILD.gn @@ -0,0 +1,173 @@ +# Copyright (c) 2025 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import("//build/test.gni") +import("../../../../appexecfwk.gni") +import("../../../../services/bundlemgr/appexecfwk_bundlemgr.gni") + +module_output_path = fuzz_test_path + +ohos_fuzztest("BMSOnQueryRpcIdFinishedFuzzTest") { + use_exceptions = true + module_out_path = module_output_path + fuzz_config_file = + "../../../fuzztest/fuzztest_bundlemanager/bmsonqueryrpcidfinished_fuzzer" + include_dirs = [ "${test_path}/fuzztest" ] + sources = bundle_mgr_source + sources += [ + "${services_path}/bundlemgr/src/aot/aot_executor.cpp", + "${services_path}/bundlemgr/src/installd/installd_host_impl.cpp", + "${services_path}/bundlemgr/src/installd/installd_operator.cpp", + "${services_path}/bundlemgr/src/installd/installd_permission_mgr.cpp", + "bmsonqueryrpcidfinished_fuzzer.cpp", + ] + + sources += bundle_install_sources + + configs = [ + "${services_path}/bundlemgr/test:bundlemgr_test_config", + "${inner_api_path}/appexecfwk_base:appexecfwk_base_sdk_config", + ] + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + + deps = [ "${core_path}:appexecfwk_core" ] + + deps += bundle_install_deps + + external_deps = [ + "ability_base:want", + "ability_runtime:ability_manager", + "ability_runtime:app_manager", + "access_token:el5_filekey_manager_sdk", + "access_token:libprivacy_sdk", + "access_token:libtokenid_sdk", + "appspawn:hnpapi", + "appverify:libhapverify", + "bounds_checking_function:libsec_shared", + "common_event_service:cesfwk_innerkits", + "eventhandler:libeventhandler", + "hilog:libhilog", + "hitrace:hitrace_meter", + "init:libbegetutil", + "jsoncpp:jsoncpp", + "safwk:system_ability_fwk", + "samgr:samgr_proxy", + "selinux_adapter:librestorecon", + ] + external_deps += bundle_install_external_deps + if (bundle_framework_graphics) { + external_deps += [ "image_framework:image_native" ] + } + defines = [] + if (code_signature_enable) { + sources += [ + "${services_path}/bundlemgr/src/aot/aot_sign_data_cache_mgr.cpp", + "${services_path}/bundlemgr/src/code_sign_helper.cpp", + ] + include_dirs += [ "${services_path}/bundlemgr/include" ] + external_deps += [ + "bounds_checking_function:libsec_shared", + "code_signature:libcode_sign_utils", + "ets_runtime:libcompiler_service", + ] + defines += [ "CODE_SIGNATURE_ENABLE" ] + } + if (current_cpu == "arm64") { + defines += [ "USE_ARM64" ] + } + if (account_enable) { + external_deps += [ "os_account:os_account_innerkits" ] + defines += [ "ACCOUNT_ENABLE" ] + } + if (ability_runtime_enable) { + external_deps += [ "ability_runtime:ability_manager" ] + } + if (bundle_framework_free_install) { + sources += aging + sources += free_install + sources += distributed_manager + external_deps += [ + "ability_runtime:app_manager", + "battery_manager:batterysrv_client", + "device_usage_statistics:usagestatsinner", + "display_manager:displaymgr", + "power_manager:powermgr_client", + "syscap_codec:syscap_interface_shared", + ] + defines += [ "BUNDLE_FRAMEWORK_FREE_INSTALL" ] + } + if (global_resmgr_enable) { + defines += [ "GLOBAL_RESMGR_ENABLE" ] + external_deps += [ "resource_management:global_resmgr" ] + } + if (hicollie_enable) { + external_deps += [ "hicollie:libhicollie" ] + defines += [ "HICOLLIE_ENABLE" ] + } + + if (hisysevent_enable) { + sources += [ "${services_path}/bundlemgr/src/inner_event_report.cpp" ] + external_deps += [ "hisysevent:libhisysevent" ] + defines += [ "HISYSEVENT_ENABLE" ] + } + + if (storage_service_enable) { + external_deps += [ "storage_service:storage_manager_sa_proxy" ] + defines += [ "STORAGE_SERVICE_ENABLE" ] + } + + configs += [ "${services_path}/bundlemgr:rdb_config" ] + external_deps += [ "relational_store:native_rdb" ] + sources += [ + "${services_path}/bundlemgr/src/bundle_data_storage_rdb.cpp", + "${services_path}/bundlemgr/src/preinstall_data_storage_rdb.cpp", + "${services_path}/bundlemgr/src/rdb/bms_rdb_open_callback.cpp", + "${services_path}/bundlemgr/src/rdb/rdb_data_manager.cpp", + ] + if (bundle_framework_app_control) { + defines += [ "BUNDLE_FRAMEWORK_APP_CONTROL" ] + sources += [ + "${services_path}/bundlemgr/src/app_control/app_control_manager.cpp", + "${services_path}/bundlemgr/src/app_control/app_control_manager_host_impl.cpp", + "${services_path}/bundlemgr/src/app_control/app_control_manager_rdb.cpp", + "${services_path}/bundlemgr/src/app_control/app_jump_interceptor_event_subscriber.cpp", + "${services_path}/bundlemgr/src/app_control/app_jump_interceptor_manager_rdb.cpp", + ] + include_dirs += [ "${services_path}/bundlemgr/include/app_control" ] + external_deps += [ "c_utils:utils" ] + } + if (udmf_enabled) { + defines += [ "BUNDLE_FRAMEWORK_UDMF_ENABLED" ] + external_deps += [ "udmf:utd_client" ] + } + + if (user_auth_framework_impl_enabled) { + external_deps += [ "user_auth_framework:userauth_client" ] + defines += [ "BMS_USER_AUTH_FRAMEWORK_ENABLED" ] + include_dirs += [ "${services_path}/bundlemgr/include/user_auth" ] + sources += user_auth + } + + if (bms_device_info_manager_part_enabled) { + external_deps += [ + "device_info_manager:distributed_device_profile_common", + "device_info_manager:distributed_device_profile_sdk", + ] + defines += [ "BMS_DEVICE_INFO_MANAGER_ENABLE" ] + } +} \ No newline at end of file diff --git a/test/fuzztest/fuzztest_bundlemanager/bmsonqueryrpcidfinished_fuzzer/bmsonqueryrpcidfinished_fuzzer.cpp b/test/fuzztest/fuzztest_bundlemanager/bmsonqueryrpcidfinished_fuzzer/bmsonqueryrpcidfinished_fuzzer.cpp new file mode 100644 index 0000000000..e69de29bb2 diff --git a/test/fuzztest/fuzztest_bundlemanager/bmsonqueryrpcidfinished_fuzzer/bmsonqueryrpcidfinished_fuzzer.h b/test/fuzztest/fuzztest_bundlemanager/bmsonqueryrpcidfinished_fuzzer/bmsonqueryrpcidfinished_fuzzer.h new file mode 100644 index 0000000000..f3f8e531e5 --- /dev/null +++ b/test/fuzztest/fuzztest_bundlemanager/bmsonqueryrpcidfinished_fuzzer/bmsonqueryrpcidfinished_fuzzer.h @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef TEST_FUZZTEST_BMS_ON_QUERY_RPC_ID_FINISHED_FUZZER_H +#define TEST_FUZZTEST_BMS_ON_QUERY_RPC_ID_FINISHED_FUZZER_H + +#define FUZZ_PROJECT_NAME "bmsonqueryrpcidfinished_fuzzer" + +#endif \ No newline at end of file diff --git a/test/fuzztest/fuzztest_bundlemanager/bmsonqueryrpcidfinished_fuzzer/corpus/init b/test/fuzztest/fuzztest_bundlemanager/bmsonqueryrpcidfinished_fuzzer/corpus/init new file mode 100644 index 0000000000..6b7212c8a6 --- /dev/null +++ b/test/fuzztest/fuzztest_bundlemanager/bmsonqueryrpcidfinished_fuzzer/corpus/init @@ -0,0 +1 @@ +FUZZ \ No newline at end of file diff --git a/test/fuzztest/fuzztest_bundlemanager/bmsonqueryrpcidfinished_fuzzer/project.xml b/test/fuzztest/fuzztest_bundlemanager/bmsonqueryrpcidfinished_fuzzer/project.xml new file mode 100644 index 0000000000..500f6f4144 --- /dev/null +++ b/test/fuzztest/fuzztest_bundlemanager/bmsonqueryrpcidfinished_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + \ No newline at end of file diff --git a/test/fuzztest/fuzztest_bundlemanager/bmssendcallback_fuzzer/bmssendcallback_fuzzer.cpp b/test/fuzztest/fuzztest_bundlemanager/bmssendcallback_fuzzer/bmssendcallback_fuzzer.cpp index 9b947e38ab..dbe0700199 100644 --- a/test/fuzztest/fuzztest_bundlemanager/bmssendcallback_fuzzer/bmssendcallback_fuzzer.cpp +++ b/test/fuzztest/fuzztest_bundlemanager/bmssendcallback_fuzzer/bmssendcallback_fuzzer.cpp @@ -40,7 +40,9 @@ bool DoSomethingInterestingWithMyAPI(const uint8_t* data, size_t size) BundleDistributedManager_->SendCallbackRequest(resultCode, transactId); QueryRpcIdParams param; int32_t resultCode2 = fdp.ConsumeIntegral(); + std::string transactId2 = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH); BundleDistributedManager_->SendCallback(resultCode2, param); + BundleDistributedManager_->OutTimeMonitor(transactId2); return true; } } diff --git a/test/fuzztest/fuzztest_bundlemanager/bmssendcallback_fuzzer/project.xml b/test/fuzztest/fuzztest_bundlemanager/bmssendcallback_fuzzer/project.xml index 500f6f4144..cae5a55e0c 100644 --- a/test/fuzztest/fuzztest_bundlemanager/bmssendcallback_fuzzer/project.xml +++ b/test/fuzztest/fuzztest_bundlemanager/bmssendcallback_fuzzer/project.xml @@ -2,7 +2,7 @@