From 8621f7d30ebcf3024f85130e78cc4b9f5f71c854 Mon Sep 17 00:00:00 2001 From: sunjiakun Date: Fri, 25 Oct 2024 15:30:22 +0800 Subject: [PATCH 1/2] =?UTF-8?q?6819=20fuzz=E6=96=B0=E5=A2=9E0829?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: sunjiakun --- test/fuzztest/BUILD.gn | 2 + .../bundleinstallerhost_fuzzer.cpp | 60 +++++-- .../bundleagingmgr_fuzzer.cpp | 6 + .../bundleconnectabilitymgr_fuzzer.cpp | 5 - .../hmpbundleinstaller_fuzzer/BUILD.gn | 147 ++++++++++++++++++ .../hmpbundleinstaller_fuzzer/corpus/init | 14 ++ .../hmpbundleinstaller_fuzzer.cpp | 84 ++++++++++ .../hmpbundleinstaller_fuzzer.h | 21 +++ .../hmpbundleinstaller_fuzzer/project.xml | 25 +++ .../innereventreport_fuzzer/BUILD.gn | 146 +++++++++++++++++ .../innereventreport_fuzzer/corpus/init | 14 ++ .../innereventreport_fuzzer.cpp | 72 +++++++++ .../innereventreport_fuzzer.h | 21 +++ .../innereventreport_fuzzer/project.xml | 25 +++ .../processaddextresource_fuzzer.cpp | 13 +- 15 files changed, 636 insertions(+), 19 deletions(-) create mode 100644 test/fuzztest/fuzztest_others/hmpbundleinstaller_fuzzer/BUILD.gn create mode 100644 test/fuzztest/fuzztest_others/hmpbundleinstaller_fuzzer/corpus/init create mode 100644 test/fuzztest/fuzztest_others/hmpbundleinstaller_fuzzer/hmpbundleinstaller_fuzzer.cpp create mode 100644 test/fuzztest/fuzztest_others/hmpbundleinstaller_fuzzer/hmpbundleinstaller_fuzzer.h create mode 100644 test/fuzztest/fuzztest_others/hmpbundleinstaller_fuzzer/project.xml create mode 100644 test/fuzztest/fuzztest_others/innereventreport_fuzzer/BUILD.gn create mode 100644 test/fuzztest/fuzztest_others/innereventreport_fuzzer/corpus/init create mode 100644 test/fuzztest/fuzztest_others/innereventreport_fuzzer/innereventreport_fuzzer.cpp create mode 100644 test/fuzztest/fuzztest_others/innereventreport_fuzzer/innereventreport_fuzzer.h create mode 100644 test/fuzztest/fuzztest_others/innereventreport_fuzzer/project.xml diff --git a/test/fuzztest/BUILD.gn b/test/fuzztest/BUILD.gn index 2f9c04edfc..6b19f31f45 100644 --- a/test/fuzztest/BUILD.gn +++ b/test/fuzztest/BUILD.gn @@ -168,6 +168,8 @@ group("fuzztest") { "fuzztest_others/getappjumpcontrolrule_fuzzer:GetAppJumpControlRuleFuzzTest", "fuzztest_others/getdynamicicon_fuzzer:GetDynamicIconFuzzTest", "fuzztest_others/getinnerbundleinfo_fuzzer:GetInnerBundleInfoFuzzTest", + "fuzztest_others/hmpbundleinstaller_fuzzer:HmpBundleInstallerFuzzTest", + "fuzztest_others/innereventreport_fuzzer:InnerEventReportFuzzTest", "fuzztest_others/innersaveextendresourceinfo_fuzzer:InnerSaveExtendResourceInfoFuzzTest", "fuzztest_others/installparamunmarshalling_fuzzer:InstallParamUnmarshallingFuzzTest", "fuzztest_others/launcherservice_fuzzer:LauncherServiceFuzzTest", diff --git a/test/fuzztest/fuzztest_application/bundleinstallerhost_fuzzer/bundleinstallerhost_fuzzer.cpp b/test/fuzztest/fuzztest_application/bundleinstallerhost_fuzzer/bundleinstallerhost_fuzzer.cpp index 4f80c43f3f..f0e094af06 100644 --- a/test/fuzztest/fuzztest_application/bundleinstallerhost_fuzzer/bundleinstallerhost_fuzzer.cpp +++ b/test/fuzztest/fuzztest_application/bundleinstallerhost_fuzzer/bundleinstallerhost_fuzzer.cpp @@ -15,6 +15,8 @@ #include "bundleinstallerhost_fuzzer.h" +#define private public + #include #include #include "bundle_installer_host.h" @@ -27,6 +29,7 @@ namespace OHOS { constexpr size_t FOO_MAX_LEN = 1024; constexpr size_t U32_AT_SIZE = 4; constexpr size_t MESSAGE_SIZE = 10; +constexpr size_t CODE_MAX = 13; uint32_t GetU32Data(const char* ptr) { @@ -35,19 +38,54 @@ uint32_t GetU32Data(const char* ptr) bool DoSomethingInterestingWithMyAPI(const char* data, size_t size) { + auto bundleInstallerHost = std::make_unique(); #ifdef ON_64BIT_SYSTEM - uint32_t code = (GetU32Data(data) % MESSAGE_SIZE); - MessageParcel datas; - std::u16string descriptor = BundleInstallerHost::GetDescriptor(); - datas.WriteInterfaceToken(descriptor); - datas.WriteBuffer(data, size); - datas.RewindRead(0); - MessageParcel reply; - MessageOption option; - BundleInstallerHost installerHost; - DelayedSingleton::GetInstance()->OnStop(); - installerHost.OnRemoteRequest(code, datas, reply, option); + for (uint32_t code = 0; code <= CODE_MAX; code++) { + MessageParcel datas; + std::u16string descriptor = BundleInstallerHost::GetDescriptor(); + datas.WriteInterfaceToken(descriptor); + datas.WriteBuffer(data, size); + datas.RewindRead(0); + MessageParcel reply; + MessageOption option; + DelayedSingleton::GetInstance()->OnStop(); + bundleInstallerHost->OnRemoteRequest(code, datas, reply, option); + } #endif + int32_t userId = 0; + int32_t appIndex = 0; + int32_t dplType = 0; + int32_t streamInstallerId = 0; + std::string bundleFilePath(std::string(data, size)); + std::string bundleName(std::string(data, size)); + std::string modulePackage(std::string(data, size)); + std::vector bundleFilePaths; + InstallParam installParam; + UninstallParam uninstallParam; + sptr statusReceiver; + bundleInstallerHost->Init(); + bundleInstallerHost->Install(bundleFilePath, installParam, statusReceiver); + bundleInstallerHost->Recover(bundleName, installParam, statusReceiver); + bundleInstallerHost->Install(bundleFilePaths, installParam, statusReceiver); + bundleInstallerHost->Uninstall(bundleName, installParam, statusReceiver); + bundleInstallerHost->Uninstall(bundleName, modulePackage, installParam, statusReceiver); + bundleInstallerHost->Uninstall(uninstallParam, statusReceiver); + bundleInstallerHost->InstallByBundleName(bundleName, installParam, statusReceiver); + bundleInstallerHost->InstallSandboxApp(bundleName, dplType, userId, appIndex); + bundleInstallerHost->UninstallSandboxApp(bundleName, appIndex, userId); + bundleInstallerHost->CreateStreamInstaller(installParam, statusReceiver); + bundleInstallerHost->DestoryBundleStreamInstaller(streamInstallerId); + bundleInstallerHost->StreamInstall(bundleFilePaths, installParam, statusReceiver); + bundleInstallerHost->UpdateBundleForSelf(bundleFilePaths, installParam, statusReceiver); + bundleInstallerHost->UninstallAndRecover(bundleName, installParam, statusReceiver); + bundleInstallerHost->GetCurTaskNum(); + bundleInstallerHost->GetThreadsNum(); + bundleInstallerHost->InstallCloneApp(bundleName, userId, appIndex); + bundleInstallerHost->UninstallCloneApp(bundleName, userId, appIndex); + bundleInstallerHost->InstallExisted(bundleName, userId); + bundleInstallerHost->CheckInstallParam(installParam); + InstallParam installParam2; + bundleInstallerHost->IsPermissionVaild(installParam, installParam2); return true; } } diff --git a/test/fuzztest/fuzztest_others/bundleagingmgr_fuzzer/bundleagingmgr_fuzzer.cpp b/test/fuzztest/fuzztest_others/bundleagingmgr_fuzzer/bundleagingmgr_fuzzer.cpp index aa5ee524a1..cad8c07eea 100644 --- a/test/fuzztest/fuzztest_others/bundleagingmgr_fuzzer/bundleagingmgr_fuzzer.cpp +++ b/test/fuzztest/fuzztest_others/bundleagingmgr_fuzzer/bundleagingmgr_fuzzer.cpp @@ -30,6 +30,12 @@ bool DoSomethingInterestingWithMyAPI(const char* data, size_t size) std::shared_ptr dataMgr = nullptr; bundleAgingMgr->Start(BundleAgingMgr::AgingTriggertype::FREE_INSTALL); bundleAgingMgr->InitAgingtTimer(); + bundleAgingMgr->ResetRequest(); + bundleAgingMgr->IsReachStartAgingThreshold(); + std::vector results; + bundleAgingMgr->QueryBundleStatsInfoByInterval(results); + bundleAgingMgr->InitAgingRequest(); + bundleAgingMgr->Process(dataMgr); return true; } diff --git a/test/fuzztest/fuzztest_others/bundleconnectabilitymgr_fuzzer/bundleconnectabilitymgr_fuzzer.cpp b/test/fuzztest/fuzztest_others/bundleconnectabilitymgr_fuzzer/bundleconnectabilitymgr_fuzzer.cpp index d003955261..8c14cfd4fc 100644 --- a/test/fuzztest/fuzztest_others/bundleconnectabilitymgr_fuzzer/bundleconnectabilitymgr_fuzzer.cpp +++ b/test/fuzztest/fuzztest_others/bundleconnectabilitymgr_fuzzer/bundleconnectabilitymgr_fuzzer.cpp @@ -46,8 +46,6 @@ bool DoSomethingInterestingWithMyAPI(const char* data, size_t size) int32_t flags = reinterpret_cast(data); AbilityInfo abilityInfo; sptr callBack = nullptr; - bundleConnectAbilityMgr.QueryAbilityInfo(want, flags, userId, abilityInfo, callBack); - bundleConnectAbilityMgr.SilentInstall(want, userId, callBack); bundleConnectAbilityMgr.UpgradeAtomicService(want, userId); bundleConnectAbilityMgr.UpgradeAtomicService(want, userId); bundleConnectAbilityMgr.UpgradeAtomicService(want, userId); @@ -67,7 +65,6 @@ bool DoSomethingInterestingWithMyAPI(const char* data, size_t size) bundleConnectAbilityMgr.SendRequest(code, datas, reply); TargetAbilityInfo targetAbilityInfo1; FreeInstallParams freeInstallParams; - bundleConnectAbilityMgr.SilentInstall(targetAbilityInfo1, want, freeInstallParams, userId); bundleConnectAbilityMgr.UpgradeCheck(targetAbilityInfo1, want, freeInstallParams, userId); int32_t callingUid = reinterpret_cast(data); std::vector bundleNames = { std::string(data, size) }; @@ -125,8 +122,6 @@ void DoSomething2(const char* data, size_t size) OHOS::sptr targetAbilityInfo1 = nullptr; bundleConnectAbilityMgr.GetPreloadList(bundleName, moduleName, userId, targetAbilityInfo1); bundleConnectAbilityMgr.LoadDownloadService(); - BmsExperienceRule rule; - bundleConnectAbilityMgr.CheckEcologicalRule(want, callerInfo, rule); bundleConnectAbilityMgr.CheckIsOnDemandLoad(targetAbilityInfo); bundleConnectAbilityMgr.GetModuleName(innerBundleInfo, want, moduleName); bundleConnectAbilityMgr.CheckIsModuleNeedUpdateWrap(innerBundleInfo, want, userId, callBack); diff --git a/test/fuzztest/fuzztest_others/hmpbundleinstaller_fuzzer/BUILD.gn b/test/fuzztest/fuzztest_others/hmpbundleinstaller_fuzzer/BUILD.gn new file mode 100644 index 0000000000..71d4c9003d --- /dev/null +++ b/test/fuzztest/fuzztest_others/hmpbundleinstaller_fuzzer/BUILD.gn @@ -0,0 +1,147 @@ +# Copyright (c) 2021-2023 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("HmpBundleInstallerFuzzTest") { + fuzz_config_file = + "../../../fuzztest/fuzztest_others/hmpbundleinstaller_fuzzer" + use_exceptions = true + module_out_path = module_output_path + include_dirs = [ "//third_party/jsoncpp/include" ] + sources = bundle_mgr_source + sources += bundle_install_sources + + sources += [] + + sources += [ "hmpbundleinstaller_fuzzer.cpp" ] + + configs = [ "${services_path}/bundlemgr/test:bundlemgr_test_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:app_manager", + "access_token:el5_filekey_manager_sdk", + "access_token:libprivacy_sdk", + "access_token:libtokenid_sdk", + "appverify:libhapverify", + "common_event_service:cesfwk_innerkits", + "eventhandler:libeventhandler", + "hilog:libhilog", + "hitrace:hitrace_meter", + "init:libbegetutil", + "safwk:system_ability_fwk", + "samgr:samgr_proxy", + ] + external_deps += bundle_install_external_deps + if (bundle_framework_graphics) { + external_deps += [ "image_framework:image_native" ] + } + defines = [] + if (configpolicy_enable) { + external_deps += [ "config_policy:configpolicy_util" ] + defines += [ "CONFIG_POLOCY_ENABLE" ] + } + + if (build_selinux) { + external_deps += [ "selinux_adapter:libhap_restorecon" ] + } + + if (account_enable) { + external_deps += [ "os_account:os_account_innerkits" ] + defines += [ "ACCOUNT_ENABLE" ] + } + + if (bundle_framework_free_install) { + sources += aging + sources += free_install + sources += distributed_manager + external_deps += [ + "ability_runtime:ability_manager", + "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 (hicollie_enable) { + external_deps += [ "hicollie:libhicollie" ] + defines += [ "HICOLLIE_ENABLE" ] + } + if (global_resmgr_enable) { + defines += [ "GLOBAL_RESMGR_ENABLE" ] + external_deps += [ "resource_management:global_resmgr" ] + } + + 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:udmf_client" ] + external_deps += [ "udmf:utd_client" ] + } + + 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" ] + } +} diff --git a/test/fuzztest/fuzztest_others/hmpbundleinstaller_fuzzer/corpus/init b/test/fuzztest/fuzztest_others/hmpbundleinstaller_fuzzer/corpus/init new file mode 100644 index 0000000000..e7c3fecd8d --- /dev/null +++ b/test/fuzztest/fuzztest_others/hmpbundleinstaller_fuzzer/corpus/init @@ -0,0 +1,14 @@ +# 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/fuzztest_others/hmpbundleinstaller_fuzzer/hmpbundleinstaller_fuzzer.cpp b/test/fuzztest/fuzztest_others/hmpbundleinstaller_fuzzer/hmpbundleinstaller_fuzzer.cpp new file mode 100644 index 0000000000..e0bd78b4fd --- /dev/null +++ b/test/fuzztest/fuzztest_others/hmpbundleinstaller_fuzzer/hmpbundleinstaller_fuzzer.cpp @@ -0,0 +1,84 @@ +/* + * 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. + */ + +#define private public +#include "hmpbundleinstaller_fuzzer.h" + +#include "hmp_bundle_installer.h" +#include "inner_bundle_info.h" +#include "securec.h" + +using namespace OHOS::AppExecFwk; +namespace OHOS { + +constexpr size_t FOO_MAX_LEN = 1024; +constexpr size_t U32_AT_SIZE = 4; +constexpr uint8_t ENABLE = 2; +bool DoSomethingInterestingWithMyAPI(const char* data, size_t size) +{ + HmpBundleInstaller hmpBundleInstaller; + std::set hapList; + std::set systemHspList; + std::unordered_map infos; + hmpBundleInstaller.InstallSystemHspInHmp(std::string(data, size)); + hmpBundleInstaller.InstallNormalAppInHmp(std::string(data, size)); + std::set userIds; + hmpBundleInstaller.GetRequiredUserIds(std::string(data, size), userIds); + hmpBundleInstaller.RollbackHmpBundle(systemHspList, hapList); + hmpBundleInstaller.UpdateBundleInfo(std::string(data, size), std::string(data, size), std::string(data, size)); + hmpBundleInstaller.GetHmpBundleList(std::string(data, size)); + hmpBundleInstaller.UpdateInnerBundleInfo(std::string(data, size), infos); + hmpBundleInstaller.ParseInfos(std::string(data, size), std::string(data, size), infos); + hmpBundleInstaller.ParseHapFiles(std::string(data, size), infos); + hmpBundleInstaller.UninstallSystemBundle(std::string(data, size), std::string(data, size)); + hmpBundleInstaller.CheckUninstallSystemHsp(std::string(data, size)); + hmpBundleInstaller.UpdatePreInfoInDb(std::string(data, size), infos); + hmpBundleInstaller.UpdateBundleInfoForHmp(std::string(data, size), hapList, systemHspList); + return true; +} +} // namespace OHOS + +// Fuzzer entry point. +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data */ + if (data == nullptr) { + return 0; + } + + /* Validate the length of size */ + if (size < OHOS::U32_AT_SIZE || size > OHOS::FOO_MAX_LEN) { + return 0; + } + + char* ch = (char*)malloc(size + 1); + if (ch == nullptr) { + std::cout << "malloc failed." << std::endl; + return 0; + } + + (void)memset_s(ch, size + 1, 0x00, size + 1); + if (memcpy_s(ch, size + 1, data, size) != EOK) { + std::cout << "copy failed." << std::endl; + free(ch); + ch = nullptr; + return 0; + } + + OHOS::DoSomethingInterestingWithMyAPI(ch, size); + free(ch); + ch = nullptr; + return 0; +} \ No newline at end of file diff --git a/test/fuzztest/fuzztest_others/hmpbundleinstaller_fuzzer/hmpbundleinstaller_fuzzer.h b/test/fuzztest/fuzztest_others/hmpbundleinstaller_fuzzer/hmpbundleinstaller_fuzzer.h new file mode 100644 index 0000000000..1bee669c41 --- /dev/null +++ b/test/fuzztest/fuzztest_others/hmpbundleinstaller_fuzzer/hmpbundleinstaller_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 TEST_FUZZTEST_HMPBUNDLEINSTALLER_FUZZER_H +#define TEST_FUZZTEST_HMPBUNDLEINSTALLER_FUZZER_H + +#define FUZZ_PROJECT_NAME "hmpbundleinstaller_fuzzer" + +#endif \ No newline at end of file diff --git a/test/fuzztest/fuzztest_others/hmpbundleinstaller_fuzzer/project.xml b/test/fuzztest/fuzztest_others/hmpbundleinstaller_fuzzer/project.xml new file mode 100644 index 0000000000..7133b2b924 --- /dev/null +++ b/test/fuzztest/fuzztest_others/hmpbundleinstaller_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/test/fuzztest/fuzztest_others/innereventreport_fuzzer/BUILD.gn b/test/fuzztest/fuzztest_others/innereventreport_fuzzer/BUILD.gn new file mode 100644 index 0000000000..7849a1eeea --- /dev/null +++ b/test/fuzztest/fuzztest_others/innereventreport_fuzzer/BUILD.gn @@ -0,0 +1,146 @@ +# Copyright (c) 2021-2023 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("InnerEventReportFuzzTest") { + fuzz_config_file = "../../../fuzztest/fuzztest_others/innereventreport_fuzzer" + use_exceptions = true + module_out_path = module_output_path + include_dirs = [ "//third_party/jsoncpp/include" ] + sources = bundle_mgr_source + sources += bundle_install_sources + + sources += [] + + sources += [ "innereventreport_fuzzer.cpp" ] + + configs = [ "${services_path}/bundlemgr/test:bundlemgr_test_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:app_manager", + "access_token:el5_filekey_manager_sdk", + "access_token:libprivacy_sdk", + "access_token:libtokenid_sdk", + "appverify:libhapverify", + "common_event_service:cesfwk_innerkits", + "eventhandler:libeventhandler", + "hilog:libhilog", + "hitrace:hitrace_meter", + "init:libbegetutil", + "safwk:system_ability_fwk", + "samgr:samgr_proxy", + ] + external_deps += bundle_install_external_deps + if (bundle_framework_graphics) { + external_deps += [ "image_framework:image_native" ] + } + defines = [] + if (configpolicy_enable) { + external_deps += [ "config_policy:configpolicy_util" ] + defines += [ "CONFIG_POLOCY_ENABLE" ] + } + + if (build_selinux) { + external_deps += [ "selinux_adapter:libhap_restorecon" ] + } + + if (account_enable) { + external_deps += [ "os_account:os_account_innerkits" ] + defines += [ "ACCOUNT_ENABLE" ] + } + + if (bundle_framework_free_install) { + sources += aging + sources += free_install + sources += distributed_manager + external_deps += [ + "ability_runtime:ability_manager", + "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 (hicollie_enable) { + external_deps += [ "hicollie:libhicollie" ] + defines += [ "HICOLLIE_ENABLE" ] + } + if (global_resmgr_enable) { + defines += [ "GLOBAL_RESMGR_ENABLE" ] + external_deps += [ "resource_management:global_resmgr" ] + } + + 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:udmf_client" ] + external_deps += [ "udmf:utd_client" ] + } + + 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" ] + } +} diff --git a/test/fuzztest/fuzztest_others/innereventreport_fuzzer/corpus/init b/test/fuzztest/fuzztest_others/innereventreport_fuzzer/corpus/init new file mode 100644 index 0000000000..e7c3fecd8d --- /dev/null +++ b/test/fuzztest/fuzztest_others/innereventreport_fuzzer/corpus/init @@ -0,0 +1,14 @@ +# 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/fuzztest_others/innereventreport_fuzzer/innereventreport_fuzzer.cpp b/test/fuzztest/fuzztest_others/innereventreport_fuzzer/innereventreport_fuzzer.cpp new file mode 100644 index 0000000000..274471b742 --- /dev/null +++ b/test/fuzztest/fuzztest_others/innereventreport_fuzzer/innereventreport_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. + */ + +#define private public +#include "innereventreport_fuzzer.h" + +#include "inner_event_report.h" +#include "inner_bundle_info.h" +#include "securec.h" + +using namespace OHOS::AppExecFwk; +namespace OHOS { + +constexpr size_t FOO_MAX_LEN = 1024; +constexpr size_t U32_AT_SIZE = 4; +constexpr uint8_t ENABLE = 2; +constexpr uint8_t CODE_MAX = 22; + +bool DoSomethingInterestingWithMyAPI(const char* data, size_t size) +{ + EventInfo eventInfo; + for (uint8_t code = 0; code <= CODE_MAX; code++) { + InnerEventReport::SendSystemEvent(BMSEventType(code), eventInfo); + } + return true; +} +} // namespace OHOS + +// Fuzzer entry point. +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data */ + if (data == nullptr) { + return 0; + } + + /* Validate the length of size */ + if (size < OHOS::U32_AT_SIZE || size > OHOS::FOO_MAX_LEN) { + return 0; + } + + char* ch = (char*)malloc(size + 1); + if (ch == nullptr) { + std::cout << "malloc failed." << std::endl; + return 0; + } + + (void)memset_s(ch, size + 1, 0x00, size + 1); + if (memcpy_s(ch, size + 1, data, size) != EOK) { + std::cout << "copy failed." << std::endl; + free(ch); + ch = nullptr; + return 0; + } + + OHOS::DoSomethingInterestingWithMyAPI(ch, size); + free(ch); + ch = nullptr; + return 0; +} \ No newline at end of file diff --git a/test/fuzztest/fuzztest_others/innereventreport_fuzzer/innereventreport_fuzzer.h b/test/fuzztest/fuzztest_others/innereventreport_fuzzer/innereventreport_fuzzer.h new file mode 100644 index 0000000000..98181cc421 --- /dev/null +++ b/test/fuzztest/fuzztest_others/innereventreport_fuzzer/innereventreport_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 TEST_FUZZTEST_INNEREVENTREPORT_FUZZER_H +#define TEST_FUZZTEST_INNEREVENTREPORT_FUZZER_H + +#define FUZZ_PROJECT_NAME "innereventreport_fuzzer" + +#endif \ No newline at end of file diff --git a/test/fuzztest/fuzztest_others/innereventreport_fuzzer/project.xml b/test/fuzztest/fuzztest_others/innereventreport_fuzzer/project.xml new file mode 100644 index 0000000000..7133b2b924 --- /dev/null +++ b/test/fuzztest/fuzztest_others/innereventreport_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/test/fuzztest/fuzztest_others/processaddextresource_fuzzer/processaddextresource_fuzzer.cpp b/test/fuzztest/fuzztest_others/processaddextresource_fuzzer/processaddextresource_fuzzer.cpp index c39b76585f..aad3a39ce6 100644 --- a/test/fuzztest/fuzztest_others/processaddextresource_fuzzer/processaddextresource_fuzzer.cpp +++ b/test/fuzztest/fuzztest_others/processaddextresource_fuzzer/processaddextresource_fuzzer.cpp @@ -27,9 +27,16 @@ namespace { ExtendResourceManagerHostImpl impl; std::vector filePaths; auto ret = impl.ProcessAddExtResource(TEST_BUNDLE, filePaths); - if (ret == ERR_OK) { - return true; - } + std::vector extendResourceInfos; + impl.InnerSaveExtendResourceInfo(TEST_BUNDLE, filePaths, extendResourceInfos); + impl.UpateExtResourcesDb(TEST_BUNDLE, extendResourceInfos); + std::vector moduleNames; + impl.RemoveExtResourcesDb(TEST_BUNDLE, moduleNames); + impl.InnerRemoveExtendResources(TEST_BUNDLE, moduleNames, extendResourceInfos); + std::string moduleName(reinterpret_cast(data), size); + impl.EnableDynamicIcon(TEST_BUNDLE, moduleName); + ExtendResourceInfo extendResourceInfo; + impl.GetExtendResourceInfo(TEST_BUNDLE, moduleName, extendResourceInfo); return false; } } -- Gitee From 478294b55a91bb85ae1a0ccd7cfddb2c22810e87 Mon Sep 17 00:00:00 2001 From: sunjiakun Date: Fri, 25 Oct 2024 16:32:42 +0800 Subject: [PATCH 2/2] =?UTF-8?q?6626=20bundlemanager=5Fbundle=5Fframework?= =?UTF-8?q?=20TDD=E7=94=A8=E4=BE=8B=E8=A1=A5=E5=85=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: sunjiakun --- .../bms_extension_data_mgr_test.cpp | 24 +++++ .../bms_installd_host_test.cpp | 98 +++++++++++++++++++ 2 files changed, 122 insertions(+) diff --git a/services/bundlemgr/test/unittest/bms_data_mgr_test/bms_extension_data_mgr_test.cpp b/services/bundlemgr/test/unittest/bms_data_mgr_test/bms_extension_data_mgr_test.cpp index a0488d6fa8..ea4a4aa34d 100644 --- a/services/bundlemgr/test/unittest/bms_data_mgr_test/bms_extension_data_mgr_test.cpp +++ b/services/bundlemgr/test/unittest/bms_data_mgr_test/bms_extension_data_mgr_test.cpp @@ -177,6 +177,18 @@ HWTEST_F(BmsExtensionDataMgrTest, BmsExtensionDataMgr_0002, Function | SmallTest #endif } +/** + * @tc.number: BmsExtensionDataMgr_0003 + * @tc.name: CheckApiInfo + * @tc.desc: CheckApiInfo + */ +HWTEST_F(BmsExtensionDataMgrTest, BmsExtensionDataMgr_0003, Function | SmallTest | Level0) +{ + BmsExtensionDataMgr bmsExtensionDataMgr; + bool res = bmsExtensionDataMgr.CheckApiInfo(SDK_VERSION, SDK_VERSION); + EXPECT_TRUE(res); +} + /** * @tc.number: BmsExtensionDataMgr_0004 * @tc.name: QueryAbilityInfosWithFlag @@ -816,4 +828,16 @@ HWTEST_F(BmsExtensionDataMgrTest, BmsExtensionDataMgr_0028, Function | SmallTest EXPECT_NE(res, ERR_OK); #endif } + +/** + * @tc.number: BmsExtensionDataMgr_0024 + * @tc.name: Init + * @tc.desc: Init + */ +HWTEST_F(BmsExtensionDataMgrTest, BmsExtensionDataMgr_0024, Function | SmallTest | Level0) +{ + BmsExtensionDataMgr bmsExtensionDataMgr; + bool res = bmsExtensionDataMgr.Init(); + EXPECT_TRUE(res); +} } // OHOS \ No newline at end of file diff --git a/services/bundlemgr/test/unittest/bms_installd_host_test/bms_installd_host_test.cpp b/services/bundlemgr/test/unittest/bms_installd_host_test/bms_installd_host_test.cpp index 0c56b4a94f..1efefa22c6 100644 --- a/services/bundlemgr/test/unittest/bms_installd_host_test/bms_installd_host_test.cpp +++ b/services/bundlemgr/test/unittest/bms_installd_host_test/bms_installd_host_test.cpp @@ -158,6 +158,34 @@ HWTEST_F(BmsInstalldHostTest, HandleExecuteAOT_0100, Function | SmallTest | Leve EXPECT_FALSE(res); } +/** + * @tc.number: HandlePendSignAOT_0100 + * @tc.name: test HandlePendSignAOT + * @tc.desc: 1.HandlePendSignAOT test + */ +HWTEST_F(BmsInstalldHostTest, HandlePendSignAOT_0100, Function | SmallTest | Level1) +{ + InstalldHost installdHost; + MessageParcel data; + MessageParcel reply; + ErrCode res = installdHost.HandlePendSignAOT(data, reply); + EXPECT_TRUE(res); +} + +/** + * @tc.number: HandleStopAOT_0100 + * @tc.name: test HandleStopAOT + * @tc.desc: 1.HandleStopAOT test + */ +HWTEST_F(BmsInstalldHostTest, HandleStopAOT_0100, Function | SmallTest | Level1) +{ + InstalldHost installdHost; + MessageParcel data; + MessageParcel reply; + ErrCode res = installdHost.HandleStopAOT(data, reply); + EXPECT_TRUE(res); +} + /** * @tc.number: HandleRenameModuleDir_0100 * @tc.name: test HandleRenameModuleDir @@ -242,6 +270,20 @@ HWTEST_F(BmsInstalldHostTest, HandleRemoveDir_0100, Function | SmallTest | Level EXPECT_TRUE(res); } +/** + * @tc.number: HandleGetDiskUsage_0100 + * @tc.name: test HandleGetDiskUsage + * @tc.desc: 1.HandleGetDiskUsage test + */ +HWTEST_F(BmsInstalldHostTest, HandleGetDiskUsage_0100, Function | SmallTest | Level1) +{ + InstalldHost installdHost; + MessageParcel data; + MessageParcel reply; + ErrCode res = installdHost.HandleGetDiskUsage(data, reply); + EXPECT_TRUE(res); +} + /** * @tc.number: HandleCleanBundleDataDir_0100 * @tc.name: test HandleCleanBundleDataDir @@ -661,4 +703,60 @@ HWTEST_F(BmsInstalldHostTest, HandleDeleteEncryptionKeyId_0100, Function | Small ErrCode res = installdHost.HandleDeleteEncryptionKeyId(data, reply); EXPECT_TRUE(res); } + +/** + * @tc.number: HandleRemoveExtensionDir_0100 + * @tc.name: test HandleRemoveExtensionDir + * @tc.desc: 1.HandleRemoveExtensionDir test + */ +HWTEST_F(BmsInstalldHostTest, HandleRemoveExtensionDir_0100, Function | SmallTest | Level1) +{ + InstalldHost installdHost; + MessageParcel data; + MessageParcel reply; + ErrCode res = installdHost.HandleRemoveExtensionDir(data, reply); + EXPECT_FALSE(res); +} + +/** + * @tc.number: HandleIsExistExtensionDir_0100 + * @tc.name: test HandleIsExistExtensionDir + * @tc.desc: 1.HandleIsExistExtensionDir test + */ +HWTEST_F(BmsInstalldHostTest, HandleIsExistExtensionDir_0100, Function | SmallTest | Level1) +{ + InstalldHost installdHost; + MessageParcel data; + MessageParcel reply; + ErrCode res = installdHost.HandleIsExistExtensionDir(data, reply); + EXPECT_TRUE(res); +} + +/** + * @tc.number: HandleCreateExtensionDataDir_0100 + * @tc.name: test HandleCreateExtensionDataDir + * @tc.desc: 1.HandleCreateExtensionDataDir test + */ +HWTEST_F(BmsInstalldHostTest, HandleCreateExtensionDataDir_0100, Function | SmallTest | Level1) +{ + InstalldHost installdHost; + MessageParcel data; + MessageParcel reply; + ErrCode res = installdHost.HandleCreateExtensionDataDir(data, reply); + EXPECT_TRUE(res); +} + +/** + * @tc.number: HandleGetExtensionSandboxTypeList_0100 + * @tc.name: test HandleGetExtensionSandboxTypeList + * @tc.desc: 1.HandleGetExtensionSandboxTypeList test + */ +HWTEST_F(BmsInstalldHostTest, HandleGetExtensionSandboxTypeList_0100, Function | SmallTest | Level1) +{ + InstalldHost installdHost; + MessageParcel data; + MessageParcel reply; + ErrCode res = installdHost.HandleGetExtensionSandboxTypeList(data, reply); + EXPECT_TRUE(res); +} } // OHOS \ No newline at end of file -- Gitee