diff --git a/test/fuzztest/bms_fuzztest_util.h b/test/fuzztest/bms_fuzztest_util.h index 88b81dc86221fbd31b94ff980d66fe7d73d56b75..a9401c67f406d21696fca8b9daca8b1fd9c01175 100644 --- a/test/fuzztest/bms_fuzztest_util.h +++ b/test/fuzztest/bms_fuzztest_util.h @@ -26,6 +26,7 @@ #include "form_info.h" #include "install_param.h" #include "install_plugin_param.h" +#include "ipc/code_signature_param.h" #include "shortcut_info.h" namespace OHOS { @@ -631,6 +632,20 @@ int32_t GenerateRandomUser(FuzzedDataProvider& fdp) return USERS[index]; } +void GenerateCodeSignatureParam(FuzzedDataProvider& fdp, CodeSignatureParam &codeSignatureParam) +{ + codeSignatureParam.isEnterpriseBundle = fdp.ConsumeBool(); + codeSignatureParam.isPreInstalledBundle = fdp.ConsumeBool(); + codeSignatureParam.isCompileSdkOpenHarmony = fdp.ConsumeBool(); + codeSignatureParam.isInternaltestingBundle = fdp.ConsumeBool(); + codeSignatureParam.isCompressNativeLibrary = fdp.ConsumeBool(); + codeSignatureParam.modulePath = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH); + codeSignatureParam.cpuAbi = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH); + codeSignatureParam.targetSoPath = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH); + codeSignatureParam.signatureFileDir = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH); + codeSignatureParam.appIdentifier = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH); +} + void GenerateHapModuleInfo(FuzzedDataProvider& fdp, HapModuleInfo &hapModuleInfo) { hapModuleInfo.compressNativeLibs = fdp.ConsumeBool(); diff --git a/test/fuzztest/fuzztest_bundlemanager/BUILD.gn b/test/fuzztest/fuzztest_bundlemanager/BUILD.gn index 57be731faf33f58af68cf09fe3274507985a2a79..2df9823120ae024dcc2df6667599397ff104b714 100644 --- a/test/fuzztest/fuzztest_bundlemanager/BUILD.gn +++ b/test/fuzztest/fuzztest_bundlemanager/BUILD.gn @@ -71,10 +71,13 @@ group("bundlemanagerfuzztest") { "bmscleancachecallbackproxy_fuzzer:BMSCleanCacheCallbackProxyFuzzTest", "bmscheckabilityenableinstall_fuzzer:BMSCheckAbilityEnableInstallFuzzTest", "bmscompatibleabilityinfo_fuzzer:BMSCompatibleAbilityInfoFuzzTest", + "bmscodesignatureparam_fuzzer:BMSCodeSignatureParamFuzzTest", "bmscompatibleapplicationinfo_fuzzer:BMSCompatibleApplicationInfoFuzzTest", "bmsconverttargetabilityinfo_fuzzer:BMSConvertTargetAbilityInfoFuzzTest", + "bmscreatedirparam_fuzzer:BMSCreateDirParamFuzzTest", "bmsdeletefirstinstallbundleinfo_fuzzer:BMSDeleteFirstInstallBundleInfoFuzzTest", "bmsdriverinstaller_fuzzer:BMSDriverInstallerFuzzTest", + "bmsencryptionparam_fuzzer:BMSEncryptionParamFuzzTest", "bmsextendresourcemanager_fuzzer:BMSExtendResourceManagerFuzzTest", "bmsextensionabilityinfo_fuzzer:BMSExtensionAbilityInfoFuzzTest", "bmsfirstinstallbundleinfo_fuzzer:BMSFirstInstallBundleInfoFuzzTest", diff --git a/test/fuzztest/fuzztest_bundlemanager/bmsappservicefwkinstallerbeforeinstall_fuzzer copy/corpus/init b/test/fuzztest/fuzztest_bundlemanager/bmsappservicefwkinstallerbeforeinstall_fuzzer copy/corpus/init deleted file mode 100644 index 62d0290f27974dbdea2a640d0ec42f21f8615e5a..0000000000000000000000000000000000000000 --- a/test/fuzztest/fuzztest_bundlemanager/bmsappservicefwkinstallerbeforeinstall_fuzzer copy/corpus/init +++ /dev/null @@ -1 +0,0 @@ -FUZZ \ No newline at end of file diff --git a/test/fuzztest/fuzztest_bundlemanager/bmsappservicefwkinstallerbeforeinstall_fuzzer copy/BUILD.gn b/test/fuzztest/fuzztest_bundlemanager/bmscodesignatureparam_fuzzer/BUILD.gn similarity index 88% rename from test/fuzztest/fuzztest_bundlemanager/bmsappservicefwkinstallerbeforeinstall_fuzzer copy/BUILD.gn rename to test/fuzztest/fuzztest_bundlemanager/bmscodesignatureparam_fuzzer/BUILD.gn index d842ad93a6563a64a644af0dd34a42b3fcccfb2b..34973997419718cd71566439755318be73820b01 100644 --- a/test/fuzztest/fuzztest_bundlemanager/bmsappservicefwkinstallerbeforeinstall_fuzzer copy/BUILD.gn +++ b/test/fuzztest/fuzztest_bundlemanager/bmscodesignatureparam_fuzzer/BUILD.gn @@ -17,8 +17,8 @@ import("../../../../services/bundlemgr/appexecfwk_bundlemgr.gni") module_output_path = fuzz_test_path -ohos_fuzztest("BMSAppServiceFwkInstallerBeforeInstallFuzzTest") { - fuzz_config_file = "../../../fuzztest/fuzztest_bundlemanager/bmsappservicefwkinstallerbeforeinstall_fuzzer" +ohos_fuzztest("BMSCodeSignatureParamFuzzTest") { + fuzz_config_file = "../../../fuzztest/fuzztest_bundlemanager/bmscodesignatureparam_fuzzer" use_exceptions = true module_out_path = module_output_path @@ -36,7 +36,7 @@ ohos_fuzztest("BMSAppServiceFwkInstallerBeforeInstallFuzzTest") { sources += bundle_install_sources - sources += [ "bmsappservicefwkinstallerbeforeinstall_fuzzer.cpp" ] + sources += [ "bmscodesignatureparam_fuzzer.cpp" ] configs = [ "${services_path}/bundlemgr/test:bundlemgr_test_config" ] cflags = [ @@ -47,11 +47,6 @@ ohos_fuzztest("BMSAppServiceFwkInstallerBeforeInstallFuzzTest") { ] deps = [ - "${bundle_framework_path}/test/sceneProject/unittest/bundle_app_service/app_service_version1_library1:appService_v1_library1", - "${bundle_framework_path}/test/sceneProject/unittest/bundle_app_service/app_service_version1_library2:appService_v1_library2", - "${bundle_framework_path}/test/sceneProject/unittest/bundle_app_service/app_service_version2_library1:appService_v2_library1", - "${bundle_framework_path}/test/sceneProject/unittest/bundle_app_service/app_service_version2_library2:appService_v2_library2", - "${bundle_framework_path}/test/sceneProject/unittest/test_bundle/rightTest:rightTest", "${core_path}:appexecfwk_core", ] deps += bundle_install_deps diff --git a/test/fuzztest/fuzztest_bundlemanager/bmscodesignatureparam_fuzzer/bmscodesignatureparam_fuzzer.cpp b/test/fuzztest/fuzztest_bundlemanager/bmscodesignatureparam_fuzzer/bmscodesignatureparam_fuzzer.cpp new file mode 100644 index 0000000000000000000000000000000000000000..4a83ba3baf60999d20cf87470061906c7f0c5cc6 --- /dev/null +++ b/test/fuzztest/fuzztest_bundlemanager/bmscodesignatureparam_fuzzer/bmscodesignatureparam_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 "ipc/code_signature_param.h" +#include "parcel.h" + +#include "bmscodesignatureparam_fuzzer.h" +#include "bms_fuzztest_util.h" + +using namespace OHOS::AppExecFwk; +using namespace OHOS::AppExecFwk::BMSFuzzTestUtil; +namespace OHOS { +bool DoSomethingInterestingWithMyAPI(const uint8_t* data, size_t size) +{ + FuzzedDataProvider fdp(data, size); + CodeSignatureParam codeSignatureParam; + codeSignatureParam.isEnterpriseBundle = fdp.ConsumeBool(); + codeSignatureParam.isPreInstalledBundle = fdp.ConsumeBool(); + codeSignatureParam.isCompileSdkOpenHarmony = fdp.ConsumeBool(); + codeSignatureParam.isInternaltestingBundle = fdp.ConsumeBool(); + codeSignatureParam.isCompressNativeLibrary = fdp.ConsumeBool(); + codeSignatureParam.ToString(); + 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; +} diff --git a/test/fuzztest/fuzztest_bundlemanager/bmsappservicefwkinstallerbeforeinstall_fuzzer copy/bmsappservicefwkinstallerbeforeinstall_fuzzer.h b/test/fuzztest/fuzztest_bundlemanager/bmscodesignatureparam_fuzzer/bmscodesignatureparam_fuzzer.h similarity index 71% rename from test/fuzztest/fuzztest_bundlemanager/bmsappservicefwkinstallerbeforeinstall_fuzzer copy/bmsappservicefwkinstallerbeforeinstall_fuzzer.h rename to test/fuzztest/fuzztest_bundlemanager/bmscodesignatureparam_fuzzer/bmscodesignatureparam_fuzzer.h index e7b154fcf29b77d1aa164c080b3096bb5f76112a..38636484855294fce9a06d41fa2e5b9c0a746cf8 100644 --- a/test/fuzztest/fuzztest_bundlemanager/bmsappservicefwkinstallerbeforeinstall_fuzzer copy/bmsappservicefwkinstallerbeforeinstall_fuzzer.h +++ b/test/fuzztest/fuzztest_bundlemanager/bmscodesignatureparam_fuzzer/bmscodesignatureparam_fuzzer.h @@ -1,21 +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_APPSERVICEFWKINSTALLERBEFOREINSTALL_FUZZER_H -#define TEST_FUZZTEST_BMS_APPSERVICEFWKINSTALLERBEFOREINSTALL_FUZZER_H - -#define FUZZ_PROJECT_NAME "bmsappservicefwkinstallerbeforeinstall_fuzzer" - -#endif \ No newline at end of file +/* + * 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_CODE_SIGNATURE_PARAM_FUZZER_H +#define TEST_FUZZTEST_BMS_CODE_SIGNATURE_PARAM_FUZZER_H + +#define FUZZ_PROJECT_NAME "bmscodesignatureparam_fuzzer" + +#endif // TEST_FUZZTEST_BMS_CODE_SIGNATURE_PARAM_FUZZER_H diff --git a/test/fuzztest/fuzztest_bundlemanager/bmscodesignatureparam_fuzzer/corpus/init b/test/fuzztest/fuzztest_bundlemanager/bmscodesignatureparam_fuzzer/corpus/init new file mode 100644 index 0000000000000000000000000000000000000000..6b7212c8a6a9ee6e433ea43d0c2c2e96568ad4c4 --- /dev/null +++ b/test/fuzztest/fuzztest_bundlemanager/bmscodesignatureparam_fuzzer/corpus/init @@ -0,0 +1 @@ +FUZZ \ No newline at end of file diff --git a/test/fuzztest/fuzztest_bundlemanager/bmsappservicefwkinstallerbeforeinstall_fuzzer copy/project.xml b/test/fuzztest/fuzztest_bundlemanager/bmscodesignatureparam_fuzzer/project.xml similarity index 97% rename from test/fuzztest/fuzztest_bundlemanager/bmsappservicefwkinstallerbeforeinstall_fuzzer copy/project.xml rename to test/fuzztest/fuzztest_bundlemanager/bmscodesignatureparam_fuzzer/project.xml index 66e1dcac475475fb101b6f8670ec699e6e9696aa..b04cd8961fdcb63b8e0ac50bdfe77b6296db3cb5 100644 --- a/test/fuzztest/fuzztest_bundlemanager/bmsappservicefwkinstallerbeforeinstall_fuzzer copy/project.xml +++ b/test/fuzztest/fuzztest_bundlemanager/bmscodesignatureparam_fuzzer/project.xml @@ -16,7 +16,7 @@ - 1000 + 5000 300 diff --git a/test/fuzztest/fuzztest_bundlemanager/bmscreatedirparam_fuzzer/BUILD.gn b/test/fuzztest/fuzztest_bundlemanager/bmscreatedirparam_fuzzer/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..e20c6fbb72ba7a7d3f6aaeda99d812d293b81f1a --- /dev/null +++ b/test/fuzztest/fuzztest_bundlemanager/bmscreatedirparam_fuzzer/BUILD.gn @@ -0,0 +1,188 @@ +# 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("BMSCreateDirParamFuzzTest") { + fuzz_config_file = "../../../fuzztest/fuzztest_bundlemanager/bmscreatedirparam_fuzzer" + + use_exceptions = true + module_out_path = module_output_path + 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_service.cpp", + ] + + sources += + [ "${services_path}/bundlemgr/src/installd/installd_permission_mgr.cpp" ] + + sources += bundle_install_sources + + sources += [ "bmscreatedirparam_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", + "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 + + 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 (configpolicy_enable) { + external_deps += [ "config_policy:configpolicy_util" ] + defines += [ "CONFIG_POLOCY_ENABLE" ] + } + + 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 (current_cpu == "arm64") { + defines += [ "USE_BUNDLE_EXTENSION" ] + } + + 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 (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 (bundle_framework_quick_fix) { + include_dirs += [ "${services_path}/bundlemgr/src/include/quick_fix" ] + sources += quick_fix + defines += [ "BUNDLE_FRAMEWORK_QUICK_FIX" ] + } + + if (storage_service_enable) { + external_deps += [ "storage_service:storage_manager_sa_proxy" ] + defines += [ "STORAGE_SERVICE_ENABLE" ] + } + + external_deps += [ "kv_store:distributeddata_inner" ] + 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 (udmf_enabled) { + defines += [ "BUNDLE_FRAMEWORK_UDMF_ENABLED" ] + external_deps += [ "udmf:udmf_client" ] + 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" ] + } +} diff --git a/test/fuzztest/fuzztest_bundlemanager/bmsappservicefwkinstallerbeforeinstall_fuzzer copy/bmsappservicefwkinstallerbeforeinstall_fuzzer.cpp b/test/fuzztest/fuzztest_bundlemanager/bmscreatedirparam_fuzzer/bmscreatedirparam_fuzzer.cpp similarity index 70% rename from test/fuzztest/fuzztest_bundlemanager/bmsappservicefwkinstallerbeforeinstall_fuzzer copy/bmsappservicefwkinstallerbeforeinstall_fuzzer.cpp rename to test/fuzztest/fuzztest_bundlemanager/bmscreatedirparam_fuzzer/bmscreatedirparam_fuzzer.cpp index 668c4e642c467f9226a5787fd502af532dbe66e2..2c57a5c50cce7bab4e0cd4cfffbf1e313b39039c 100644 --- a/test/fuzztest/fuzztest_bundlemanager/bmsappservicefwkinstallerbeforeinstall_fuzzer copy/bmsappservicefwkinstallerbeforeinstall_fuzzer.cpp +++ b/test/fuzztest/fuzztest_bundlemanager/bmscreatedirparam_fuzzer/bmscreatedirparam_fuzzer.cpp @@ -1,48 +1,47 @@ -/* - * 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. - */ - -#define private public -#include -#include -#include - -#include "app_service_fwk/app_service_fwk_installer.h" - -#include "bmsappservicefwkinstallerbeforeinstall_fuzzer.h" -#include "bms_fuzztest_util.h" -#include "securec.h" - -using namespace OHOS::AppExecFwk; -using namespace OHOS::AppExecFwk::BMSFuzzTestUtil; -namespace OHOS { -bool DoSomethingInterestingWithMyAPI(const uint8_t* data, size_t size) -{ - InstallParam installParam; - FuzzedDataProvider fdp(data, size); - GenerateInstallParam(fdp, installParam); - AppServiceFwkInstaller appServicefwk; - std::vector hspPaths = GenerateStringArray(fdp); - appServicefwk.BeforeInstall(hspPaths, installParam); - 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 +/* + * 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 "ipc/create_dir_param.h" +#include "parcel.h" + +#include "bmscreatedirparam_fuzzer.h" +#include "bms_fuzztest_util.h" + +using namespace OHOS::AppExecFwk; +using namespace OHOS::AppExecFwk::BMSFuzzTestUtil; +namespace OHOS { +bool DoSomethingInterestingWithMyAPI(const uint8_t* data, size_t size) +{ + FuzzedDataProvider fdp(data, size); + CreateDirParam createDirParam; + createDirParam.extensionDirs = GenerateStringArray(fdp); + createDirParam.extensionDirs.emplace_back("test"); + Parcel dataMessageParcel; + createDirParam.Marshalling(dataMessageParcel); + 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; +} diff --git a/test/fuzztest/fuzztest_bundlemanager/bmscreatedirparam_fuzzer/bmscreatedirparam_fuzzer.h b/test/fuzztest/fuzztest_bundlemanager/bmscreatedirparam_fuzzer/bmscreatedirparam_fuzzer.h new file mode 100644 index 0000000000000000000000000000000000000000..2d0e1ba9e2f83f45b689c7beb4e78a304bab88c7 --- /dev/null +++ b/test/fuzztest/fuzztest_bundlemanager/bmscreatedirparam_fuzzer/bmscreatedirparam_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_CREATE_DIR_PARAM_FUZZER_H +#define TEST_FUZZTEST_BMS_CREATE_DIR_PARAM_FUZZER_H + +#define FUZZ_PROJECT_NAME "bmscreatedirparam_fuzzer" + +#endif // TEST_FUZZTEST_BMS_CREATE_DIR_PARAM_FUZZER_H diff --git a/test/fuzztest/fuzztest_bundlemanager/bmscreatedirparam_fuzzer/corpus/init b/test/fuzztest/fuzztest_bundlemanager/bmscreatedirparam_fuzzer/corpus/init new file mode 100644 index 0000000000000000000000000000000000000000..6b7212c8a6a9ee6e433ea43d0c2c2e96568ad4c4 --- /dev/null +++ b/test/fuzztest/fuzztest_bundlemanager/bmscreatedirparam_fuzzer/corpus/init @@ -0,0 +1 @@ +FUZZ \ No newline at end of file diff --git a/test/fuzztest/fuzztest_bundlemanager/bmscreatedirparam_fuzzer/project.xml b/test/fuzztest/fuzztest_bundlemanager/bmscreatedirparam_fuzzer/project.xml new file mode 100644 index 0000000000000000000000000000000000000000..b04cd8961fdcb63b8e0ac50bdfe77b6296db3cb5 --- /dev/null +++ b/test/fuzztest/fuzztest_bundlemanager/bmscreatedirparam_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 5000 + + 300 + + 4096 + + diff --git a/test/fuzztest/fuzztest_bundlemanager/bmsencryptionparam_fuzzer/BUILD.gn b/test/fuzztest/fuzztest_bundlemanager/bmsencryptionparam_fuzzer/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..a41112359b5acebfcba616655f8a52907bddc656 --- /dev/null +++ b/test/fuzztest/fuzztest_bundlemanager/bmsencryptionparam_fuzzer/BUILD.gn @@ -0,0 +1,188 @@ +# 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("BMSEncryptionParamFuzzTest") { + fuzz_config_file = "../../../fuzztest/fuzztest_bundlemanager/bmsencryptionparam_fuzzer" + + use_exceptions = true + module_out_path = module_output_path + 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_service.cpp", + ] + + sources += + [ "${services_path}/bundlemgr/src/installd/installd_permission_mgr.cpp" ] + + sources += bundle_install_sources + + sources += [ "bmsencryptionparam_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", + "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 + + 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 (configpolicy_enable) { + external_deps += [ "config_policy:configpolicy_util" ] + defines += [ "CONFIG_POLOCY_ENABLE" ] + } + + 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 (current_cpu == "arm64") { + defines += [ "USE_BUNDLE_EXTENSION" ] + } + + 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 (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 (bundle_framework_quick_fix) { + include_dirs += [ "${services_path}/bundlemgr/src/include/quick_fix" ] + sources += quick_fix + defines += [ "BUNDLE_FRAMEWORK_QUICK_FIX" ] + } + + if (storage_service_enable) { + external_deps += [ "storage_service:storage_manager_sa_proxy" ] + defines += [ "STORAGE_SERVICE_ENABLE" ] + } + + external_deps += [ "kv_store:distributeddata_inner" ] + 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 (udmf_enabled) { + defines += [ "BUNDLE_FRAMEWORK_UDMF_ENABLED" ] + external_deps += [ "udmf:udmf_client" ] + 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" ] + } +} diff --git a/test/fuzztest/fuzztest_bundlemanager/bmsencryptionparam_fuzzer/bmsencryptionparam_fuzzer.cpp b/test/fuzztest/fuzztest_bundlemanager/bmsencryptionparam_fuzzer/bmsencryptionparam_fuzzer.cpp new file mode 100644 index 0000000000000000000000000000000000000000..a8677b9bd5bc2e38d244f5997ddc39551d43db3c --- /dev/null +++ b/test/fuzztest/fuzztest_bundlemanager/bmsencryptionparam_fuzzer/bmsencryptionparam_fuzzer.cpp @@ -0,0 +1,51 @@ +/* + * 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 "ipc/encryption_param.h" +#include "parcel.h" + +#include "bmsencryptionparam_fuzzer.h" +#include "bms_fuzztest_util.h" + +using namespace OHOS::AppExecFwk; +using namespace OHOS::AppExecFwk::BMSFuzzTestUtil; +namespace OHOS { +bool DoSomethingInterestingWithMyAPI(const uint8_t* data, size_t size) +{ + FuzzedDataProvider fdp(data, size); + std::string name = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH); + std::string id = fdp.ConsumeRandomLengthString(STRING_MAX_LENGTH); + int32_t uidParam = fdp.ConsumeIntegral(); + int32_t userIdParam = fdp.ConsumeIntegral(); + EncryptionDirType dirType = fdp.ConsumeBool() ? EncryptionDirType::APP : EncryptionDirType::GROUP; + + EncryptionParam encryptionParam(name, id, uidParam, userIdParam, dirType); + Parcel dataMessageParcel; + encryptionParam.Marshalling(dataMessageParcel); + 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; +} diff --git a/test/fuzztest/fuzztest_bundlemanager/bmsencryptionparam_fuzzer/bmsencryptionparam_fuzzer.h b/test/fuzztest/fuzztest_bundlemanager/bmsencryptionparam_fuzzer/bmsencryptionparam_fuzzer.h new file mode 100644 index 0000000000000000000000000000000000000000..381f4307a540e6f42da47f18199dc2a396702d47 --- /dev/null +++ b/test/fuzztest/fuzztest_bundlemanager/bmsencryptionparam_fuzzer/bmsencryptionparam_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_ENCRYPTION_PARAM_FUZZER_H +#define TEST_FUZZTEST_BMS_ENCRYPTION_PARAM_FUZZER_H + +#define FUZZ_PROJECT_NAME "bmsencryptionparam_fuzzer" + +#endif // TEST_FUZZTEST_BMS_ENCRYPTION_PARAM_FUZZER_H diff --git a/test/fuzztest/fuzztest_bundlemanager/bmsencryptionparam_fuzzer/corpus/init b/test/fuzztest/fuzztest_bundlemanager/bmsencryptionparam_fuzzer/corpus/init new file mode 100644 index 0000000000000000000000000000000000000000..6b7212c8a6a9ee6e433ea43d0c2c2e96568ad4c4 --- /dev/null +++ b/test/fuzztest/fuzztest_bundlemanager/bmsencryptionparam_fuzzer/corpus/init @@ -0,0 +1 @@ +FUZZ \ No newline at end of file diff --git a/test/fuzztest/fuzztest_bundlemanager/bmsencryptionparam_fuzzer/project.xml b/test/fuzztest/fuzztest_bundlemanager/bmsencryptionparam_fuzzer/project.xml new file mode 100644 index 0000000000000000000000000000000000000000..b04cd8961fdcb63b8e0ac50bdfe77b6296db3cb5 --- /dev/null +++ b/test/fuzztest/fuzztest_bundlemanager/bmsencryptionparam_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 5000 + + 300 + + 4096 + +