diff --git a/services/distributeddataservice/service/test/fuzztest/BUILD.gn b/services/distributeddataservice/service/test/fuzztest/BUILD.gn index 6dd680bddd17f5ab4b50dcc87f545b0acdfbb1f1..cc8f56b038c2915bd9040bb343399525d0545682 100644 --- a/services/distributeddataservice/service/test/fuzztest/BUILD.gn +++ b/services/distributeddataservice/service/test/fuzztest/BUILD.gn @@ -48,9 +48,13 @@ group("fuzztest") { deps += [ "kvdbservicestub_fuzzer:fuzztest" ] } + if (datamgr_service_data_share) { - deps += [ + deps += [ + #Due to timeout risks from excessive fuzz cases, datashareservicestub_fuzzer split into three files. "datashareservicestub_fuzzer:fuzztest", + "datashareservicestub2_fuzzer:fuzztest", + "datashareservicestub3_fuzzer:fuzztest", "datashareserviceimpl_fuzzer:fuzztest", "datasharesubscriber_fuzzer:fuzztest", ] diff --git a/services/distributeddataservice/service/test/fuzztest/datashareservicestub2_fuzzer/BUILD.gn b/services/distributeddataservice/service/test/fuzztest/datashareservicestub2_fuzzer/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..a282acce69285648dd6eeb97cabd07936a08e390 --- /dev/null +++ b/services/distributeddataservice/service/test/fuzztest/datashareservicestub2_fuzzer/BUILD.gn @@ -0,0 +1,150 @@ +# 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/test.gni") +import("//foundation/distributeddatamgr/datamgr_service/datamgr_service.gni") + +##############################fuzztest########################################## +ohos_fuzztest("DataShareServiceStub2FuzzTest") { + module_out_path = "datamgr_service/datamgr_service" + + include_dirs = [ + "${data_service_path}/adapter/include", + "${data_service_path}/app/src", + "${data_service_path}/framework/include", + "${data_service_path}/service/common", + "${data_service_path}/service/config/include", + "${data_service_path}/service/crypto/include", + "${data_service_path}/service/data_share/common", + "${data_service_path}/service/data_share/data", + "${data_service_path}/service/data_share/dfx", + "${data_service_path}/service/data_share/strategies", + "${data_service_path}/service/data_share/subscriber_managers", + "${data_service_path}/service/data_share", + "${data_service_path}/service/kvdb", + "${data_service_path}/service/permission/include", + "${data_service_path}/adapter/include/communicator", + ] + + fuzz_config_file = + "${data_service_path}/service/test/fuzztest/datashareservicestub2_fuzzer" + + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + + sources = [ + "${data_service_path}/service/common/bundle_utils.cpp", + "${data_service_path}/service/common/xcollie.cpp", + "${data_service_path}/service/data_share/common/app_connect_manager.cpp", + "${data_service_path}/service/data_share/common/bundle_mgr_proxy.cpp", + "${data_service_path}/service/data_share/common/common_utils.cpp", + "${data_service_path}/service/data_share/common/db_delegate.cpp", + "${data_service_path}/service/data_share/common/div_strategy.cpp", + "${data_service_path}/service/data_share/common/extension_ability_manager.cpp", + "${data_service_path}/service/data_share/common/extension_connect_adaptor.cpp", + "${data_service_path}/service/data_share/common/extension_mgr_proxy.cpp", + "${data_service_path}/service/data_share/common/kv_delegate.cpp", + "${data_service_path}/service/data_share/common/proxy_data_manager.cpp", + "${data_service_path}/service/data_share/common/rdb_delegate.cpp", + "${data_service_path}/service/data_share/common/scheduler_manager.cpp", + "${data_service_path}/service/data_share/common/seq_strategy.cpp", + "${data_service_path}/service/data_share/common/utils.cpp", + "${data_service_path}/service/data_share/data/published_data.cpp", + "${data_service_path}/service/data_share/data/resultset_json_formatter.cpp", + "${data_service_path}/service/data_share/data/template_data.cpp", + "${data_service_path}/service/data_share/data_provider_config.cpp", + "${data_service_path}/service/data_share/data_share_db_config.cpp", + "${data_service_path}/service/data_share/data_share_obs_proxy.cpp", + "${data_service_path}/service/data_share/data_share_profile_config.cpp", + "${data_service_path}/service/data_share/data_share_service_impl.cpp", + "${data_service_path}/service/data_share/data_share_service_stub.cpp", + "${data_service_path}/service/data_share/data_share_silent_config.cpp", + "${data_service_path}/service/data_share/data_share_types_util.cpp", + "${data_service_path}/service/data_share/dfx/hiview_adapter.cpp", + "${data_service_path}/service/data_share/dfx/hiview_fault_adapter.cpp", + "${data_service_path}/service/data_share/strategies/data_proxy/load_config_from_data_proxy_node_strategy.cpp", + "${data_service_path}/service/data_share/strategies/data_share/load_config_from_data_share_bundle_info_strategy.cpp", + "${data_service_path}/service/data_share/strategies/general/check_is_data_proxy_strategy.cpp", + "${data_service_path}/service/data_share/strategies/general/check_is_single_app_strategy.cpp", + "${data_service_path}/service/data_share/strategies/general/cross_permission_strategy.cpp", + "${data_service_path}/service/data_share/strategies/general/load_config_common_strategy.cpp", + "${data_service_path}/service/data_share/strategies/general/load_config_data_info_strategy.cpp", + "${data_service_path}/service/data_share/strategies/general/load_config_from_bundle_info_strategy.cpp", + "${data_service_path}/service/data_share/strategies/general/permission_strategy.cpp", + "${data_service_path}/service/data_share/strategies/get_data_strategy.cpp", + "${data_service_path}/service/data_share/strategies/publish_strategy.cpp", + "${data_service_path}/service/data_share/strategies/rdb_notify_strategy.cpp", + "${data_service_path}/service/data_share/strategies/subscribe_strategy.cpp", + "${data_service_path}/service/data_share/strategies/template_strategy.cpp", + "${data_service_path}/service/data_share/subscriber_managers/proxy_data_subscriber_manager.cpp", + "${data_service_path}/service/data_share/subscriber_managers/published_data_subscriber_manager.cpp", + "${data_service_path}/service/data_share/subscriber_managers/rdb_subscriber_manager.cpp", + "${data_service_path}/service/data_share/sys_event_subscriber.cpp", + "${data_service_path}/service/kvdb/user_delegate.cpp", + "${data_service_path}/service/permission/src/permit_delegate.cpp", + "${data_service_path}/service/permission/src/permission_validator.cpp", + "datashareservicestub2_fuzzer.cpp", + ] + + deps = [ + "${data_service_path}/adapter/account:distributeddata_account", + "${data_service_path}/adapter/communicator:distributeddata_communicator", + "${data_service_path}/framework:distributeddatasvcfwk", + "${data_service_path}/service/config:distributeddata_config", + ] + + external_deps = [ + "ability_base:base", + "ability_base:want", + "ability_base:zuri", + "ability_runtime:dataobs_manager", + "ability_runtime:extension_manager", + "ability_runtime:wantagent_innerkits", + "access_token:libaccesstoken_sdk", + "access_token:libtokenid_sdk", + "bundle_framework:appexecfwk_base", + "bundle_framework:appexecfwk_core", + "c_utils:utils", + "common_event_service:cesfwk_innerkits", + "data_share:datashare_common", + "data_share:datashare_consumer", + "device_manager:devicemanagersdk", + "hicollie:libhicollie", + "hilog:libhilog", + "hisysevent:libhisysevent", + "huks:libhukssdk", + "ipc:ipc_core", + "kv_store:distributeddata_inner", + "kv_store:distributeddb", + "qos_manager:concurrent_task_client", + "qos_manager:qos", + "relational_store:native_rdb", + "relational_store:rdb_data_share_adapter", + "resource_management:global_resmgr", + "samgr:samgr_proxy", + "time_service:time_client", + ] +} + +############################################################################### +group("fuzztest") { + testonly = true + + deps = [ ":DataShareServiceStub2FuzzTest" ] +} +############################################################################### diff --git a/services/distributeddataservice/service/test/fuzztest/datashareservicestub2_fuzzer/corpus/init b/services/distributeddataservice/service/test/fuzztest/datashareservicestub2_fuzzer/corpus/init new file mode 100644 index 0000000000000000000000000000000000000000..7ade8a0faafeaedba7241e7d4a97b8e1f9691932 --- /dev/null +++ b/services/distributeddataservice/service/test/fuzztest/datashareservicestub2_fuzzer/corpus/init @@ -0,0 +1,16 @@ +/* + * 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. + */ + +FUZZ \ No newline at end of file diff --git a/services/distributeddataservice/service/test/fuzztest/datashareservicestub2_fuzzer/datashareservicestub2_fuzzer.cpp b/services/distributeddataservice/service/test/fuzztest/datashareservicestub2_fuzzer/datashareservicestub2_fuzzer.cpp new file mode 100644 index 0000000000000000000000000000000000000000..b9c8d78ff18a8516f737a927d466998785f589c4 --- /dev/null +++ b/services/distributeddataservice/service/test/fuzztest/datashareservicestub2_fuzzer/datashareservicestub2_fuzzer.cpp @@ -0,0 +1,270 @@ +/* + * 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 "datashareservicestub2_fuzzer.h" + +#include +#include + +#include "data_share_service_impl.h" +#include "ipc_skeleton.h" +#include "itypes_util.h" +#include "message_parcel.h" +#include "securec.h" + +using namespace OHOS::DataShare; + +namespace OHOS { +constexpr size_t NUM_MIN = 5; +constexpr size_t NUM_MAX = 12; + +bool OnInsertExFuzz(FuzzedDataProvider &provider) +{ + std::shared_ptr dataShareServiceImpl = std::make_shared(); + std::shared_ptr executor = std::make_shared(NUM_MAX, NUM_MIN); + dataShareServiceImpl->OnBind( + { "DataShareServiceStubFuzz", static_cast(IPCSkeleton::GetSelfTokenID()), std::move(executor) }); + std::shared_ptr dataShareServiceStub = dataShareServiceImpl; + std::string uri = provider.ConsumeRandomLengthString(); + std::string extUri = provider.ConsumeRandomLengthString(); + DataShareValueObject::Type intValue = provider.ConsumeIntegral(); + std::map values; + values["int_key"] = intValue; + DataShareValuesBucket bucket(values); + MessageParcel request; + request.WriteInterfaceToken(IDataShareService::GetDescriptor()); + ITypesUtil::Marshal(request, uri, extUri, bucket.valuesMap); + MessageParcel reply; + dataShareServiceStub->OnRemoteRequest( + static_cast(IDataShareService::DATA_SHARE_SERVICE_CMD_INSERTEX), request, reply); + return true; +} + +bool OnUpdateExFuzz(FuzzedDataProvider &provider) +{ + std::shared_ptr dataShareServiceImpl = std::make_shared(); + std::shared_ptr executor = std::make_shared(NUM_MAX, NUM_MIN); + dataShareServiceImpl->OnBind( + { "DataShareServiceStubFuzz", static_cast(IPCSkeleton::GetSelfTokenID()), std::move(executor) }); + std::shared_ptr dataShareServiceStub = dataShareServiceImpl; + std::string uri = provider.ConsumeRandomLengthString(); + std::string extUri = provider.ConsumeRandomLengthString(); + DataSharePredicates predicate; + DataShareValueObject::Type intValue = provider.ConsumeIntegral(); + std::map values; + values["int_key"] = intValue; + DataShareValuesBucket bucket(values); + MessageParcel request; + request.WriteInterfaceToken(IDataShareService::GetDescriptor()); + ITypesUtil::Marshal(request, uri, extUri, predicate, bucket.valuesMap); + MessageParcel reply; + dataShareServiceStub->OnRemoteRequest( + static_cast(IDataShareService::DATA_SHARE_SERVICE_CMD_UPDATEEX), request, reply); + return true; +} + +bool OnDeleteExFuzz(FuzzedDataProvider &provider) +{ + std::shared_ptr dataShareServiceImpl = std::make_shared(); + std::shared_ptr executor = std::make_shared(NUM_MAX, NUM_MIN); + dataShareServiceImpl->OnBind( + { "DataShareServiceStubFuzz", static_cast(IPCSkeleton::GetSelfTokenID()), std::move(executor) }); + std::shared_ptr dataShareServiceStub = dataShareServiceImpl; + std::string uri = provider.ConsumeRandomLengthString(); + std::string extUri = provider.ConsumeRandomLengthString(); + DataSharePredicates predicate; + MessageParcel request; + request.WriteInterfaceToken(IDataShareService::GetDescriptor()); + ITypesUtil::Marshal(request, uri, extUri, predicate); + MessageParcel reply; + dataShareServiceStub->OnRemoteRequest( + static_cast(IDataShareService::DATA_SHARE_SERVICE_CMD_DELETEEX), request, reply); + return true; +} + +bool OnQueryFuzz(FuzzedDataProvider &provider) +{ + std::shared_ptr dataShareServiceImpl = std::make_shared(); + std::shared_ptr executor = std::make_shared(NUM_MAX, NUM_MIN); + dataShareServiceImpl->OnBind( + { "DataShareServiceStubFuzz", static_cast(IPCSkeleton::GetSelfTokenID()), std::move(executor) }); + std::shared_ptr dataShareServiceStub = dataShareServiceImpl; + std::string uri = provider.ConsumeRandomLengthString(); + std::string extUri = provider.ConsumeRandomLengthString(); + DataSharePredicates predicate; + uint8_t len = provider.ConsumeIntegral(); + std::vector columns(len); + for (int i = 0; i < len; i++) { + std::string column = provider.ConsumeRandomLengthString(); + columns[i] = column; + } + MessageParcel request; + request.WriteInterfaceToken(IDataShareService::GetDescriptor()); + ITypesUtil::Marshal(request, uri, extUri, predicate, columns); + MessageParcel reply; + dataShareServiceStub->OnRemoteRequest( + static_cast(IDataShareService::DATA_SHARE_SERVICE_CMD_QUERY), request, reply); + return true; +} + +bool OnAddTemplateFuzz(FuzzedDataProvider &provider) +{ + std::shared_ptr dataShareServiceImpl = std::make_shared(); + std::shared_ptr executor = std::make_shared(NUM_MAX, NUM_MIN); + dataShareServiceImpl->OnBind( + { "DataShareServiceStubFuzz", static_cast(IPCSkeleton::GetSelfTokenID()), std::move(executor) }); + std::shared_ptr dataShareServiceStub = dataShareServiceImpl; + std::string uri = provider.ConsumeRandomLengthString(); + int64_t subscriberId = provider.ConsumeIntegral(); + std::string update = provider.ConsumeRandomLengthString(); + std::vector predicates; + std::string scheduler = provider.ConsumeRandomLengthString(); + Template tpl(update, predicates, scheduler); + MessageParcel request; + request.WriteInterfaceToken(IDataShareService::GetDescriptor()); + ITypesUtil::Marshal(request, uri, subscriberId, tpl.update_, tpl.predicates_, tpl.scheduler_); + MessageParcel reply; + dataShareServiceStub->OnRemoteRequest( + static_cast(IDataShareService::DATA_SHARE_SERVICE_CMD_ADD_TEMPLATE), request, reply); + return true; +} + +bool OnDelTemplateFuzz(FuzzedDataProvider &provider) +{ + std::shared_ptr dataShareServiceImpl = std::make_shared(); + std::shared_ptr executor = std::make_shared(NUM_MAX, NUM_MIN); + dataShareServiceImpl->OnBind( + { "DataShareServiceStubFuzz", static_cast(IPCSkeleton::GetSelfTokenID()), std::move(executor) }); + std::shared_ptr dataShareServiceStub = dataShareServiceImpl; + std::string uri = provider.ConsumeRandomLengthString(); + int64_t subscriberId = provider.ConsumeIntegral(); + MessageParcel request; + request.WriteInterfaceToken(IDataShareService::GetDescriptor()); + ITypesUtil::Marshal(request, uri, subscriberId); + MessageParcel reply; + dataShareServiceStub->OnRemoteRequest( + static_cast(IDataShareService::DATA_SHARE_SERVICE_CMD_DEL_TEMPLATE), request, reply); + return true; +} + +bool OnPublishFuzz(FuzzedDataProvider &provider) +{ + std::shared_ptr dataShareServiceImpl = std::make_shared(); + std::shared_ptr executor = std::make_shared(NUM_MAX, NUM_MIN); + dataShareServiceImpl->OnBind( + { "DataShareServiceStubFuzz", static_cast(IPCSkeleton::GetSelfTokenID()), std::move(executor) }); + std::shared_ptr dataShareServiceStub = dataShareServiceImpl; + Data publishData; + publishData.version_ = provider.ConsumeIntegral(); + std::string bundleName = provider.ConsumeRandomLengthString(); + MessageParcel request; + request.WriteInterfaceToken(IDataShareService::GetDescriptor()); + ITypesUtil::Marshal(request, publishData.datas_, publishData.version_, bundleName); + MessageParcel reply; + dataShareServiceStub->OnRemoteRequest( + static_cast(IDataShareService::DATA_SHARE_SERVICE_CMD_PUBLISH), request, reply); + return true; +} + +bool OnGetDataFuzz(FuzzedDataProvider &provider) +{ + std::shared_ptr dataShareServiceImpl = std::make_shared(); + std::shared_ptr executor = std::make_shared(NUM_MAX, NUM_MIN); + dataShareServiceImpl->OnBind( + { "DataShareServiceStubFuzz", static_cast(IPCSkeleton::GetSelfTokenID()), std::move(executor) }); + std::shared_ptr dataShareServiceStub = dataShareServiceImpl; + std::string bundleName = provider.ConsumeRandomLengthString(); + MessageParcel request; + request.WriteInterfaceToken(IDataShareService::GetDescriptor()); + ITypesUtil::Marshal(request, bundleName); + MessageParcel reply; + dataShareServiceStub->OnRemoteRequest( + static_cast(IDataShareService::DATA_SHARE_SERVICE_CMD_GET_DATA), request, reply); + return true; +} + +bool OnNotifyObserverFuzz(FuzzedDataProvider &provider) +{ + std::shared_ptr dataShareServiceImpl = std::make_shared(); + std::shared_ptr executor = std::make_shared(NUM_MAX, NUM_MIN); + dataShareServiceImpl->OnBind( + { "DataShareServiceStubFuzz", static_cast(IPCSkeleton::GetSelfTokenID()), std::move(executor) }); + std::shared_ptr dataShareServiceStub = dataShareServiceImpl; + std::string uri = provider.ConsumeRandomLengthString(); + MessageParcel request; + request.WriteInterfaceToken(IDataShareService::GetDescriptor()); + ITypesUtil::Marshal(request, uri); + MessageParcel reply; + dataShareServiceStub->OnRemoteRequest( + IDataShareService::DATA_SHARE_SERVICE_CMD_NOTIFY_OBSERVERS, request, reply); + return true; +} + +bool OnSetSilentSwitchFuzz(FuzzedDataProvider &provider) +{ + std::shared_ptr dataShareServiceImpl = std::make_shared(); + std::shared_ptr executor = std::make_shared(NUM_MAX, NUM_MIN); + dataShareServiceImpl->OnBind( + { "DataShareServiceStubFuzz", static_cast(IPCSkeleton::GetSelfTokenID()), std::move(executor) }); + std::shared_ptr dataShareServiceStub = dataShareServiceImpl; + std::string uri = provider.ConsumeRandomLengthString(); + bool enable = provider.ConsumeBool(); + MessageParcel request; + request.WriteInterfaceToken(IDataShareService::GetDescriptor()); + ITypesUtil::Marshal(request, uri, enable); + MessageParcel reply; + dataShareServiceStub->OnRemoteRequest( + IDataShareService::DATA_SHARE_SERVICE_CMD_SET_SILENT_SWITCH, request, reply); + return true; +} + +bool OnGetSilentProxyStatusFuzz(FuzzedDataProvider &provider) +{ + std::shared_ptr dataShareServiceImpl = std::make_shared(); + std::shared_ptr executor = std::make_shared(NUM_MAX, NUM_MIN); + dataShareServiceImpl->OnBind( + { "DataShareServiceStubFuzz", static_cast(IPCSkeleton::GetSelfTokenID()), std::move(executor) }); + std::shared_ptr dataShareServiceStub = dataShareServiceImpl; + std::string uri = provider.ConsumeRandomLengthString(); + MessageParcel request; + request.WriteInterfaceToken(IDataShareService::GetDescriptor()); + ITypesUtil::Marshal(request, uri); + MessageParcel reply; + dataShareServiceStub->OnRemoteRequest( + IDataShareService::DATA_SHARE_SERVICE_CMD_GET_SILENT_PROXY_STATUS, request, reply); + return true; +} + +} // namespace OHOS + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) +{ + FuzzedDataProvider provider(data, size); + OHOS::OnInsertExFuzz(provider); + OHOS::OnUpdateExFuzz(provider); + OHOS::OnDeleteExFuzz(provider); + OHOS::OnQueryFuzz(provider); + OHOS::OnAddTemplateFuzz(provider); + OHOS::OnDelTemplateFuzz(provider); + OHOS::OnPublishFuzz(provider); + OHOS::OnGetDataFuzz(provider); + OHOS::OnNotifyObserverFuzz(provider); + OHOS::OnSetSilentSwitchFuzz(provider); + OHOS::OnGetSilentProxyStatusFuzz(provider); + return 0; +} \ No newline at end of file diff --git a/services/distributeddataservice/service/test/fuzztest/datashareservicestub2_fuzzer/datashareservicestub2_fuzzer.h b/services/distributeddataservice/service/test/fuzztest/datashareservicestub2_fuzzer/datashareservicestub2_fuzzer.h new file mode 100644 index 0000000000000000000000000000000000000000..7ba4563a0b0c841b7bab416dc73f6fc17082d228 --- /dev/null +++ b/services/distributeddataservice/service/test/fuzztest/datashareservicestub2_fuzzer/datashareservicestub2_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 DATAMGR_SERVICE_DATA_SHARE_SERVICE_STUB2_FUZZER_H +#define DATAMGR_SERVICE_DATA_SHARE_SERVICE_STUB2_FUZZER_H + +#define FUZZ_PROJECT_NAME "datashareservicestub2_fuzzer" + +#endif // DATAMGR_SERVICE_DATA_SHARE_SERVICE_STUB2_FUZZER_H \ No newline at end of file diff --git a/services/distributeddataservice/service/test/fuzztest/datashareservicestub2_fuzzer/project.xml b/services/distributeddataservice/service/test/fuzztest/datashareservicestub2_fuzzer/project.xml new file mode 100644 index 0000000000000000000000000000000000000000..a37a23b1533f07ab59744732b0f46b2b5fd958d8 --- /dev/null +++ b/services/distributeddataservice/service/test/fuzztest/datashareservicestub2_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + \ No newline at end of file diff --git a/services/distributeddataservice/service/test/fuzztest/datashareservicestub3_fuzzer/BUILD.gn b/services/distributeddataservice/service/test/fuzztest/datashareservicestub3_fuzzer/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..4af90ede1bf6774d55090be4a473e3d7d0a1e4a7 --- /dev/null +++ b/services/distributeddataservice/service/test/fuzztest/datashareservicestub3_fuzzer/BUILD.gn @@ -0,0 +1,150 @@ +# 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/test.gni") +import("//foundation/distributeddatamgr/datamgr_service/datamgr_service.gni") + +##############################fuzztest########################################## +ohos_fuzztest("DataShareServiceStub3FuzzTest") { + module_out_path = "datamgr_service/datamgr_service" + + include_dirs = [ + "${data_service_path}/adapter/include", + "${data_service_path}/app/src", + "${data_service_path}/framework/include", + "${data_service_path}/service/common", + "${data_service_path}/service/config/include", + "${data_service_path}/service/crypto/include", + "${data_service_path}/service/data_share/common", + "${data_service_path}/service/data_share/data", + "${data_service_path}/service/data_share/dfx", + "${data_service_path}/service/data_share/strategies", + "${data_service_path}/service/data_share/subscriber_managers", + "${data_service_path}/service/data_share", + "${data_service_path}/service/kvdb", + "${data_service_path}/service/permission/include", + "${data_service_path}/adapter/include/communicator", + ] + + fuzz_config_file = + "${data_service_path}/service/test/fuzztest/datashareservicestub3_fuzzer" + + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + + sources = [ + "${data_service_path}/service/common/bundle_utils.cpp", + "${data_service_path}/service/common/xcollie.cpp", + "${data_service_path}/service/data_share/common/app_connect_manager.cpp", + "${data_service_path}/service/data_share/common/bundle_mgr_proxy.cpp", + "${data_service_path}/service/data_share/common/common_utils.cpp", + "${data_service_path}/service/data_share/common/db_delegate.cpp", + "${data_service_path}/service/data_share/common/div_strategy.cpp", + "${data_service_path}/service/data_share/common/extension_ability_manager.cpp", + "${data_service_path}/service/data_share/common/extension_connect_adaptor.cpp", + "${data_service_path}/service/data_share/common/extension_mgr_proxy.cpp", + "${data_service_path}/service/data_share/common/kv_delegate.cpp", + "${data_service_path}/service/data_share/common/proxy_data_manager.cpp", + "${data_service_path}/service/data_share/common/rdb_delegate.cpp", + "${data_service_path}/service/data_share/common/scheduler_manager.cpp", + "${data_service_path}/service/data_share/common/seq_strategy.cpp", + "${data_service_path}/service/data_share/common/utils.cpp", + "${data_service_path}/service/data_share/data/published_data.cpp", + "${data_service_path}/service/data_share/data/resultset_json_formatter.cpp", + "${data_service_path}/service/data_share/data/template_data.cpp", + "${data_service_path}/service/data_share/data_provider_config.cpp", + "${data_service_path}/service/data_share/data_share_db_config.cpp", + "${data_service_path}/service/data_share/data_share_obs_proxy.cpp", + "${data_service_path}/service/data_share/data_share_profile_config.cpp", + "${data_service_path}/service/data_share/data_share_service_impl.cpp", + "${data_service_path}/service/data_share/data_share_service_stub.cpp", + "${data_service_path}/service/data_share/data_share_silent_config.cpp", + "${data_service_path}/service/data_share/data_share_types_util.cpp", + "${data_service_path}/service/data_share/dfx/hiview_adapter.cpp", + "${data_service_path}/service/data_share/dfx/hiview_fault_adapter.cpp", + "${data_service_path}/service/data_share/strategies/data_proxy/load_config_from_data_proxy_node_strategy.cpp", + "${data_service_path}/service/data_share/strategies/data_share/load_config_from_data_share_bundle_info_strategy.cpp", + "${data_service_path}/service/data_share/strategies/general/check_is_data_proxy_strategy.cpp", + "${data_service_path}/service/data_share/strategies/general/check_is_single_app_strategy.cpp", + "${data_service_path}/service/data_share/strategies/general/cross_permission_strategy.cpp", + "${data_service_path}/service/data_share/strategies/general/load_config_common_strategy.cpp", + "${data_service_path}/service/data_share/strategies/general/load_config_data_info_strategy.cpp", + "${data_service_path}/service/data_share/strategies/general/load_config_from_bundle_info_strategy.cpp", + "${data_service_path}/service/data_share/strategies/general/permission_strategy.cpp", + "${data_service_path}/service/data_share/strategies/get_data_strategy.cpp", + "${data_service_path}/service/data_share/strategies/publish_strategy.cpp", + "${data_service_path}/service/data_share/strategies/rdb_notify_strategy.cpp", + "${data_service_path}/service/data_share/strategies/subscribe_strategy.cpp", + "${data_service_path}/service/data_share/strategies/template_strategy.cpp", + "${data_service_path}/service/data_share/subscriber_managers/proxy_data_subscriber_manager.cpp", + "${data_service_path}/service/data_share/subscriber_managers/published_data_subscriber_manager.cpp", + "${data_service_path}/service/data_share/subscriber_managers/rdb_subscriber_manager.cpp", + "${data_service_path}/service/data_share/sys_event_subscriber.cpp", + "${data_service_path}/service/kvdb/user_delegate.cpp", + "${data_service_path}/service/permission/src/permit_delegate.cpp", + "${data_service_path}/service/permission/src/permission_validator.cpp", + "datashareservicestub3_fuzzer.cpp", + ] + + deps = [ + "${data_service_path}/adapter/account:distributeddata_account", + "${data_service_path}/adapter/communicator:distributeddata_communicator", + "${data_service_path}/framework:distributeddatasvcfwk", + "${data_service_path}/service/config:distributeddata_config", + ] + + external_deps = [ + "ability_base:base", + "ability_base:want", + "ability_base:zuri", + "ability_runtime:dataobs_manager", + "ability_runtime:extension_manager", + "ability_runtime:wantagent_innerkits", + "access_token:libaccesstoken_sdk", + "access_token:libtokenid_sdk", + "bundle_framework:appexecfwk_base", + "bundle_framework:appexecfwk_core", + "c_utils:utils", + "common_event_service:cesfwk_innerkits", + "data_share:datashare_common", + "data_share:datashare_consumer", + "device_manager:devicemanagersdk", + "hicollie:libhicollie", + "hilog:libhilog", + "hisysevent:libhisysevent", + "huks:libhukssdk", + "ipc:ipc_core", + "kv_store:distributeddata_inner", + "kv_store:distributeddb", + "qos_manager:concurrent_task_client", + "qos_manager:qos", + "relational_store:native_rdb", + "relational_store:rdb_data_share_adapter", + "resource_management:global_resmgr", + "samgr:samgr_proxy", + "time_service:time_client", + ] +} + +############################################################################### +group("fuzztest") { + testonly = true + + deps = [ ":DataShareServiceStub3FuzzTest" ] +} +############################################################################### diff --git a/services/distributeddataservice/service/test/fuzztest/datashareservicestub3_fuzzer/corpus/init b/services/distributeddataservice/service/test/fuzztest/datashareservicestub3_fuzzer/corpus/init new file mode 100644 index 0000000000000000000000000000000000000000..7ade8a0faafeaedba7241e7d4a97b8e1f9691932 --- /dev/null +++ b/services/distributeddataservice/service/test/fuzztest/datashareservicestub3_fuzzer/corpus/init @@ -0,0 +1,16 @@ +/* + * 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. + */ + +FUZZ \ No newline at end of file diff --git a/services/distributeddataservice/service/test/fuzztest/datashareservicestub3_fuzzer/datashareservicestub3_fuzzer.cpp b/services/distributeddataservice/service/test/fuzztest/datashareservicestub3_fuzzer/datashareservicestub3_fuzzer.cpp new file mode 100644 index 0000000000000000000000000000000000000000..16dbc6f124810b74e88d54b9018fc22eccf3cc6d --- /dev/null +++ b/services/distributeddataservice/service/test/fuzztest/datashareservicestub3_fuzzer/datashareservicestub3_fuzzer.cpp @@ -0,0 +1,125 @@ +/* + * 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 "datashareservicestub3_fuzzer.h" + +#include +#include + +#include "data_share_service_impl.h" +#include "ipc_skeleton.h" +#include "itypes_util.h" +#include "message_parcel.h" +#include "securec.h" + +using namespace OHOS::DataShare; + +namespace OHOS { +constexpr size_t NUM_MIN = 5; +constexpr size_t NUM_MAX = 12; + +bool OnRemoteRequestFuzz(uint32_t code, FuzzedDataProvider &provider) +{ + std::shared_ptr dataShareServiceImpl = std::make_shared(); + std::shared_ptr executor = std::make_shared(NUM_MAX, NUM_MIN); + dataShareServiceImpl->OnBind( + { "DataShareServiceStubFuzz", static_cast(IPCSkeleton::GetSelfTokenID()), std::move(executor) }); + std::shared_ptr dataShareServiceStub = dataShareServiceImpl; + uint8_t len = provider.ConsumeIntegral(); + std::vector uris(len); + for (int i = 0; i < len; i++) { + std::string uri = provider.ConsumeRandomLengthString(); + uris[i] = uri; + } + TemplateId templateId; + MessageParcel request; + request.WriteInterfaceToken(IDataShareService::GetDescriptor()); + ITypesUtil::Marshal(request, uris, templateId); + MessageParcel reply; + dataShareServiceStub->OnRemoteRequest(code, request, reply); + return true; +} + +bool OnSubscribePublishedDataFuzz(uint32_t code, FuzzedDataProvider &provider) +{ + std::shared_ptr dataShareServiceImpl = std::make_shared(); + std::shared_ptr executor = std::make_shared(NUM_MAX, NUM_MIN); + dataShareServiceImpl->OnBind( + { "DataShareServiceStubFuzz", static_cast(IPCSkeleton::GetSelfTokenID()), std::move(executor) }); + std::shared_ptr dataShareServiceStub = dataShareServiceImpl; + uint8_t len = provider.ConsumeIntegral(); + std::vector uris(len); + for (int i = 0; i < len; i++) { + std::string uri = provider.ConsumeRandomLengthString(); + uris[i] = uri; + } + int64_t subscriberId = provider.ConsumeIntegral(); + MessageParcel request; + request.WriteInterfaceToken(IDataShareService::GetDescriptor()); + ITypesUtil::Marshal(request, uris, subscriberId); + MessageParcel reply; + dataShareServiceStub->OnRemoteRequest(code, request, reply); + return true; +} + +bool OnDeleteProxyDataFuzz(uint32_t code, FuzzedDataProvider &provider) +{ + std::shared_ptr dataShareServiceImpl = std::make_shared(); + std::shared_ptr executor = std::make_shared(NUM_MAX, NUM_MIN); + dataShareServiceImpl->OnBind( + { "DataShareServiceStubFuzz", static_cast(IPCSkeleton::GetSelfTokenID()), std::move(executor) }); + std::shared_ptr dataShareServiceStub = dataShareServiceImpl; + uint8_t len = provider.ConsumeIntegral(); + std::vector uris(len); + for (int i = 0; i < len; i++) { + std::string uri = provider.ConsumeRandomLengthString(); + uris[i] = uri; + } + DataProxyConfig config; + config.type_ = DataProxyType::SHARED_CONFIG; + MessageParcel request; + request.WriteInterfaceToken(IDataShareService::GetDescriptor()); + ITypesUtil::Marshal(request, uris, config); + MessageParcel reply; + dataShareServiceStub->OnRemoteRequest(code, request, reply); + return true; +} +} // namespace OHOS + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) +{ + FuzzedDataProvider provider(data, size); + uint32_t codeTest = IDataShareService::DATA_SHARE_SERVICE_CMD_SUBSCRIBE_RDB; + while (codeTest <= IDataShareService::DATA_SHARE_SERVICE_CMD_DISABLE_SUBSCRIBE_PUBLISHED) { + OHOS::OnRemoteRequestFuzz(codeTest, provider); + codeTest++; + } + + codeTest = IDataShareService::DATA_SHARE_SERVICE_CMD_SUBSCRIBE_PUBLISHED; + while (codeTest <= IDataShareService::DATA_SHARE_SERVICE_CMD_DISABLE_SUBSCRIBE_PUBLISHED) { + OHOS::OnSubscribePublishedDataFuzz(codeTest, provider); + codeTest++; + } + + codeTest = IDataShareService::DATA_SHARE_SERVICE_CMD_PROXY_DELETE; + while (codeTest <= IDataShareService::DATA_SHARE_SERVICE_CMD_UNSUBSCRIBE_PROXY_DATA) { + OHOS::OnDeleteProxyDataFuzz(codeTest, provider); + codeTest++; + } + return 0; +} \ No newline at end of file diff --git a/services/distributeddataservice/service/test/fuzztest/datashareservicestub3_fuzzer/datashareservicestub3_fuzzer.h b/services/distributeddataservice/service/test/fuzztest/datashareservicestub3_fuzzer/datashareservicestub3_fuzzer.h new file mode 100644 index 0000000000000000000000000000000000000000..5d21972ecc6cae15c4a107b7073ee88a0ad38faa --- /dev/null +++ b/services/distributeddataservice/service/test/fuzztest/datashareservicestub3_fuzzer/datashareservicestub3_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 DATAMGR_SERVICE_DATA_SHARE_SERVICE_STUB3_FUZZER_H +#define DATAMGR_SERVICE_DATA_SHARE_SERVICE_STUB3_FUZZER_H + +#define FUZZ_PROJECT_NAME "datashareservicestub3_fuzzer" + +#endif // DATAMGR_SERVICE_DATA_SHARE_SERVICE_STUB3_FUZZER_H \ No newline at end of file diff --git a/services/distributeddataservice/service/test/fuzztest/datashareservicestub3_fuzzer/project.xml b/services/distributeddataservice/service/test/fuzztest/datashareservicestub3_fuzzer/project.xml new file mode 100644 index 0000000000000000000000000000000000000000..a37a23b1533f07ab59744732b0f46b2b5fd958d8 --- /dev/null +++ b/services/distributeddataservice/service/test/fuzztest/datashareservicestub3_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + \ No newline at end of file