diff --git a/services/distributeddataservice/service/test/fuzztest/BUILD.gn b/services/distributeddataservice/service/test/fuzztest/BUILD.gn index 6dd680bddd17f5ab4b50dcc87f545b0acdfbb1f1..9ef9b149d4ba72863462efcb9844449486a69e60 100644 --- a/services/distributeddataservice/service/test/fuzztest/BUILD.gn +++ b/services/distributeddataservice/service/test/fuzztest/BUILD.gn @@ -57,6 +57,19 @@ group("fuzztest") { } if (datamgr_service_udmf) { - deps += [ "udmfservice_fuzzer:fuzztest" ] + deps += [ "udmfserviceasynprocess_fuzzer:fuzztest" ] + deps += [ "udmfservicecheckkeyandintention_fuzzer:fuzztest" ] + deps += [ "udmfservicecheckpermission_fuzzer:fuzztest" ] + deps += [ "udmfservicechecktransferparams_fuzzer:fuzztest" ] + deps += [ "udmfservicedata_fuzzer:fuzztest" ] + deps += [ "udmfservicedatamanager_fuzzer:fuzztest" ] + deps += [ "udmfservicedelaydata_fuzzer:fuzztest" ] + deps += [ "udmfservicehandleappshareoption_fuzzer:fuzztest" ] + deps += [ "udmfservicehandledbstatus_fuzzer:fuzztest" ] + deps += [ "udmfserviceprivilege_fuzzer:fuzztest" ] + deps += [ "udmfserviceprocessdata_fuzzer:fuzztest" ] + deps += [ "udmfserviceremoteinteraction_fuzzer:fuzztest" ] + deps += [ "udmfservicesyncandmeta_fuzzer:fuzztest" ] + deps += [ "udmfserviceverifypermission_fuzzer:fuzztest" ] } } diff --git a/services/distributeddataservice/service/test/fuzztest/udmfservice_fuzzer/udmfservice_fuzzer.cpp b/services/distributeddataservice/service/test/fuzztest/udmfservice_fuzzer/udmfservice_fuzzer.cpp deleted file mode 100644 index 827a48d7c784e6cc8ebb603e1f3e469df210e06d..0000000000000000000000000000000000000000 --- a/services/distributeddataservice/service/test/fuzztest/udmfservice_fuzzer/udmfservice_fuzzer.cpp +++ /dev/null @@ -1,970 +0,0 @@ -/* - * Copyright (c) 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. - */ - -#include - -#include "udmfservice_fuzzer.h" - -#include "accesstoken_kit.h" -#include "distributeddata_udmf_ipc_interface_code.h" -#include "itypes_util.h" -#include "ipc_skeleton.h" -#include "message_parcel.h" -#include "securec.h" -#include "token_setproc.h" -#include "udmf_service_impl.h" -#include "udmf_types_util.h" - -using namespace OHOS::UDMF; - -namespace OHOS { -const std::u16string INTERFACE_TOKEN = u"OHOS.UDMF.UdmfService"; -constexpr uint32_t CODE_MIN = 0; -constexpr uint32_t CODE_MAX = static_cast(UdmfServiceInterfaceCode::CODE_BUTT) + 1; -constexpr size_t NUM_MIN = 5; -constexpr size_t NUM_MAX = 12; -static constexpr int ID_LEN = 32; -static constexpr int MINIMUM = 48; -static constexpr int MAXIMUM = 121; - -QueryOption GenerateFuzzQueryOption(FuzzedDataProvider &provider) -{ - std::vector groupId(ID_LEN, '0'); - for (size_t i = 0; i < groupId.size(); ++i) { - groupId[i] = provider.ConsumeIntegralInRange(MINIMUM, MAXIMUM); - } - std::string groupIdStr(groupId.begin(), groupId.end()); - UnifiedKey udKey = UnifiedKey("drag", "com.test.demo", groupIdStr); - QueryOption query; - query.key = udKey.GetUnifiedKey(); - query.intention = Intention::UD_INTENTION_DRAG; - query.tokenId = provider.ConsumeIntegral(); - return query; -} - -bool OnRemoteRequestFuzz(FuzzedDataProvider &provider) -{ - std::shared_ptr udmfServiceImpl = std::make_shared(); - std::shared_ptr executor = std::make_shared(NUM_MAX, NUM_MIN); - udmfServiceImpl->OnBind( - { "UdmfServiceStubFuzz", static_cast(IPCSkeleton::GetSelfTokenID()), std::move(executor) }); - - uint32_t code = provider.ConsumeIntegralInRange(CODE_MIN, CODE_MAX); - std::vector remainingData = provider.ConsumeRemainingBytes(); - MessageParcel request; - request.WriteInterfaceToken(INTERFACE_TOKEN); - request.WriteBuffer(static_cast(remainingData.data()), remainingData.size()); - request.RewindRead(0); - MessageParcel reply; - udmfServiceImpl->OnRemoteRequest(code, request, reply); - udmfServiceImpl->OnBind( - { "UdmfServiceStubFuzz", static_cast(IPCSkeleton::GetSelfTokenID()), nullptr }); - executor = nullptr; - return true; -} - -void SetDataFuzz(FuzzedDataProvider &provider) -{ - std::shared_ptr udmfServiceImpl = std::make_shared(); - std::shared_ptr executor = std::make_shared(NUM_MAX, NUM_MIN); - udmfServiceImpl->OnBind( - { "UdmfServiceStubFuzz", static_cast(IPCSkeleton::GetSelfTokenID()), std::move(executor) }); - CustomOption option1 = {.intention = Intention::UD_INTENTION_DRAG}; - - std::string svalue = provider.ConsumeRandomLengthString(); - UnifiedData data1; - std::shared_ptr obj = std::make_shared(); - obj->value_[UNIFORM_DATA_TYPE] = "general.file-uri"; - obj->value_[FILE_URI_PARAM] = svalue; - obj->value_[FILE_TYPE] = provider.ConsumeRandomLengthString(); - auto record = std::make_shared(FILE_URI, obj); - data1.AddRecord(record); - MessageParcel request; - request.WriteInterfaceToken(INTERFACE_TOKEN); - ITypesUtil::Marshal(request, option1, data1); - MessageParcel reply; - udmfServiceImpl->OnRemoteRequest(static_cast(UdmfServiceInterfaceCode::SET_DATA), request, reply); - udmfServiceImpl->OnBind( - { "UdmfServiceStubFuzz", static_cast(IPCSkeleton::GetSelfTokenID()), nullptr }); - executor = nullptr; -} - -void GetDataFuzz(FuzzedDataProvider &provider) -{ - std::shared_ptr udmfServiceImpl = std::make_shared(); - std::shared_ptr executor = std::make_shared(NUM_MAX, NUM_MIN); - udmfServiceImpl->OnBind( - { "UdmfServiceStubFuzz", static_cast(IPCSkeleton::GetSelfTokenID()), std::move(executor) }); - QueryOption query = GenerateFuzzQueryOption(provider); - MessageParcel request; - request.WriteInterfaceToken(INTERFACE_TOKEN); - ITypesUtil::Marshal(request, query); - MessageParcel reply; - udmfServiceImpl->OnRemoteRequest(static_cast(UdmfServiceInterfaceCode::GET_DATA), request, reply); - udmfServiceImpl->OnBind( - { "UdmfServiceStubFuzz", static_cast(IPCSkeleton::GetSelfTokenID()), nullptr }); - executor = nullptr; -} - -void GetBatchDataFuzz(FuzzedDataProvider &provider) -{ - std::shared_ptr udmfServiceImpl = std::make_shared(); - std::shared_ptr executor = std::make_shared(NUM_MAX, NUM_MIN); - udmfServiceImpl->OnBind( - { "UdmfServiceStubFuzz", static_cast(IPCSkeleton::GetSelfTokenID()), std::move(executor) }); - QueryOption query = GenerateFuzzQueryOption(provider); - MessageParcel request; - request.WriteInterfaceToken(INTERFACE_TOKEN); - ITypesUtil::Marshal(request, query); - MessageParcel reply; - udmfServiceImpl->OnRemoteRequest(static_cast(UdmfServiceInterfaceCode::GET_BATCH_DATA), request, reply); - udmfServiceImpl->OnBind( - { "UdmfServiceStubFuzz", static_cast(IPCSkeleton::GetSelfTokenID()), nullptr }); - executor = nullptr; -} - -void UpdateDataFuzz(FuzzedDataProvider &provider) -{ - std::shared_ptr udmfServiceImpl = std::make_shared(); - std::shared_ptr executor = std::make_shared(NUM_MAX, NUM_MIN); - udmfServiceImpl->OnBind( - { "UdmfServiceStubFuzz", static_cast(IPCSkeleton::GetSelfTokenID()), std::move(executor) }); - QueryOption query = GenerateFuzzQueryOption(provider); - std::string svalue = provider.ConsumeRandomLengthString(); - UnifiedData data1; - std::shared_ptr obj = std::make_shared(); - obj->value_[UNIFORM_DATA_TYPE] = "general.file-uri"; - obj->value_[FILE_URI_PARAM] = svalue; - obj->value_[FILE_TYPE] = provider.ConsumeRandomLengthString(); - auto record = std::make_shared(FILE_URI, obj); - data1.AddRecord(record); - MessageParcel request; - request.WriteInterfaceToken(INTERFACE_TOKEN); - ITypesUtil::Marshal(request, query, data1); - MessageParcel reply; - udmfServiceImpl->OnRemoteRequest(static_cast(UdmfServiceInterfaceCode::UPDATE_DATA), request, reply); - udmfServiceImpl->OnBind( - { "UdmfServiceStubFuzz", static_cast(IPCSkeleton::GetSelfTokenID()), nullptr }); - executor = nullptr; -} - -void DeleteDataFuzz(FuzzedDataProvider &provider) -{ - std::shared_ptr udmfServiceImpl = std::make_shared(); - std::shared_ptr executor = std::make_shared(NUM_MAX, NUM_MIN); - udmfServiceImpl->OnBind( - { "UdmfServiceStubFuzz", static_cast(IPCSkeleton::GetSelfTokenID()), std::move(executor) }); - QueryOption query = GenerateFuzzQueryOption(provider); - MessageParcel request; - request.WriteInterfaceToken(INTERFACE_TOKEN); - ITypesUtil::Marshal(request, query); - MessageParcel reply; - udmfServiceImpl->OnRemoteRequest(static_cast(UdmfServiceInterfaceCode::DELETE_DATA), request, reply); - udmfServiceImpl->OnBind( - { "UdmfServiceStubFuzz", static_cast(IPCSkeleton::GetSelfTokenID()), nullptr }); - executor = nullptr; -} - -void GetSummaryFuzz(FuzzedDataProvider &provider) -{ - std::shared_ptr udmfServiceImpl = std::make_shared(); - std::shared_ptr executor = std::make_shared(NUM_MAX, NUM_MIN); - udmfServiceImpl->OnBind( - { "UdmfServiceStubFuzz", static_cast(IPCSkeleton::GetSelfTokenID()), std::move(executor) }); - QueryOption query = GenerateFuzzQueryOption(provider); - MessageParcel request; - request.WriteInterfaceToken(INTERFACE_TOKEN); - ITypesUtil::Marshal(request, query); - MessageParcel reply; - udmfServiceImpl->OnRemoteRequest(static_cast(UdmfServiceInterfaceCode::GET_SUMMARY), request, reply); - udmfServiceImpl->OnBind( - { "UdmfServiceStubFuzz", static_cast(IPCSkeleton::GetSelfTokenID()), nullptr }); - executor = nullptr; -} - -void AddPrivilegeDataFuzz(FuzzedDataProvider &provider) -{ - std::shared_ptr udmfServiceImpl = std::make_shared(); - std::shared_ptr executor = std::make_shared(NUM_MAX, NUM_MIN); - udmfServiceImpl->OnBind( - { "UdmfServiceStubFuzz", static_cast(IPCSkeleton::GetSelfTokenID()), std::move(executor) }); - QueryOption query = GenerateFuzzQueryOption(provider); - - Privilege privilege; - privilege.tokenId = 1; - privilege.readPermission = "read"; - privilege.writePermission = "write"; - - MessageParcel request; - request.WriteInterfaceToken(INTERFACE_TOKEN); - ITypesUtil::Marshal(request, query, privilege); - MessageParcel replyUpdate; - udmfServiceImpl->OnRemoteRequest(static_cast(UdmfServiceInterfaceCode::ADD_PRIVILEGE), - request, replyUpdate); - udmfServiceImpl->OnBind( - { "UdmfServiceStubFuzz", static_cast(IPCSkeleton::GetSelfTokenID()), nullptr }); - executor = nullptr; -} - -void SyncDataFuzz(FuzzedDataProvider &provider) -{ - std::shared_ptr udmfServiceImpl = std::make_shared(); - std::shared_ptr executor = std::make_shared(NUM_MAX, NUM_MIN); - udmfServiceImpl->OnBind( - { "UdmfServiceStubFuzz", static_cast(IPCSkeleton::GetSelfTokenID()), std::move(executor) }); - QueryOption query = GenerateFuzzQueryOption(provider); - std::vector devices = { "11", "22" }; - MessageParcel requestUpdate; - requestUpdate.WriteInterfaceToken(INTERFACE_TOKEN); - ITypesUtil::Marshal(requestUpdate, query, devices); - MessageParcel replyUpdate; - udmfServiceImpl->OnRemoteRequest(static_cast(UdmfServiceInterfaceCode::SYNC), - requestUpdate, replyUpdate); - udmfServiceImpl->OnBind( - { "UdmfServiceStubFuzz", static_cast(IPCSkeleton::GetSelfTokenID()), nullptr }); - executor = nullptr; -} - -void IsRemoteDataFuzz(FuzzedDataProvider &provider) -{ - std::shared_ptr udmfServiceImpl = std::make_shared(); - std::shared_ptr executor = std::make_shared(NUM_MAX, NUM_MIN); - udmfServiceImpl->OnBind( - { "UdmfServiceStubFuzz", static_cast(IPCSkeleton::GetSelfTokenID()), std::move(executor) }); - QueryOption query = GenerateFuzzQueryOption(provider); - MessageParcel requestUpdate; - requestUpdate.WriteInterfaceToken(INTERFACE_TOKEN); - ITypesUtil::Marshal(requestUpdate, query); - MessageParcel replyUpdate; - udmfServiceImpl->OnRemoteRequest(static_cast(UdmfServiceInterfaceCode::IS_REMOTE_DATA), - requestUpdate, replyUpdate); - udmfServiceImpl->OnBind( - { "UdmfServiceStubFuzz", static_cast(IPCSkeleton::GetSelfTokenID()), nullptr }); - executor = nullptr; -} - -void ObtainAsynProcessFuzz(FuzzedDataProvider &provider) -{ - std::shared_ptr udmfServiceImpl = std::make_shared(); - std::shared_ptr executor = std::make_shared(NUM_MAX, NUM_MIN); - udmfServiceImpl->OnBind( - { "UdmfServiceStubFuzz", static_cast(IPCSkeleton::GetSelfTokenID()), std::move(executor) }); - std::vector groupId(ID_LEN, '0'); - for (size_t i = 0; i < groupId.size(); ++i) { - groupId[i] = provider.ConsumeIntegralInRange(MINIMUM, MINIMUM); - } - std::string businessUdKey(groupId.begin(), groupId.end()); - AsyncProcessInfo processInfo; - processInfo.businessUdKey = businessUdKey; - MessageParcel requestUpdate; - requestUpdate.WriteInterfaceToken(INTERFACE_TOKEN); - ITypesUtil::Marshal(requestUpdate, processInfo); - MessageParcel replyUpdate; - udmfServiceImpl->OnRemoteRequest(static_cast(UdmfServiceInterfaceCode::OBTAIN_ASYN_PROCESS), - requestUpdate, replyUpdate); - udmfServiceImpl->OnBind( - { "UdmfServiceStubFuzz", static_cast(IPCSkeleton::GetSelfTokenID()), nullptr }); - executor = nullptr; -} - -void ClearAsynProcessFuzz(FuzzedDataProvider &provider) -{ - std::shared_ptr udmfServiceImpl = std::make_shared(); - std::shared_ptr executor = std::make_shared(NUM_MAX, NUM_MIN); - udmfServiceImpl->OnBind( - { "UdmfServiceStubFuzz", static_cast(IPCSkeleton::GetSelfTokenID()), std::move(executor) }); - std::vector groupId(ID_LEN, '0'); - for (size_t i = 0; i < groupId.size(); ++i) { - groupId[i] = provider.ConsumeIntegralInRange(MINIMUM, MINIMUM); - } - std::string businessUdKey(groupId.begin(), groupId.end()); - MessageParcel requestUpdate; - requestUpdate.WriteInterfaceToken(INTERFACE_TOKEN); - ITypesUtil::Marshal(requestUpdate, businessUdKey); - MessageParcel replyUpdate; - udmfServiceImpl->OnRemoteRequest(static_cast(UdmfServiceInterfaceCode::CLEAR_ASYN_PROCESS_BY_KEY), - requestUpdate, replyUpdate); - udmfServiceImpl->OnBind( - { "UdmfServiceStubFuzz", static_cast(IPCSkeleton::GetSelfTokenID()), nullptr }); - executor = nullptr; -} - -void SetDelayInfoFuzz(FuzzedDataProvider &provider) -{ - std::shared_ptr udmfServiceImpl = std::make_shared(); - std::shared_ptr executor = std::make_shared(NUM_MAX, NUM_MIN); - udmfServiceImpl->OnBind( - { "UdmfServiceStubFuzz", static_cast(IPCSkeleton::GetSelfTokenID()), std::move(executor) }); - MessageParcel requestUpdate; - requestUpdate.WriteInterfaceToken(INTERFACE_TOKEN); - DataLoadInfo dataLoadInfo; - dataLoadInfo.recordCount = provider.ConsumeIntegral(); - dataLoadInfo.types.emplace(provider.ConsumeRandomLengthString()); - dataLoadInfo.sequenceKey = provider.ConsumeRandomLengthString(); - ITypesUtil::Marshal(requestUpdate, dataLoadInfo); - sptr iUdmfNotifier = nullptr; - ITypesUtil::Marshal(requestUpdate, iUdmfNotifier); - MessageParcel replyUpdate; - udmfServiceImpl->OnRemoteRequest(static_cast(UdmfServiceInterfaceCode::SET_DELAY_INFO), - requestUpdate, replyUpdate); - udmfServiceImpl->OnBind( - { "UdmfServiceStubFuzz", static_cast(IPCSkeleton::GetSelfTokenID()), nullptr }); - executor = nullptr; -} - -void PushDelayDataFuzz(FuzzedDataProvider &provider) -{ - std::shared_ptr udmfServiceImpl = std::make_shared(); - std::shared_ptr executor = std::make_shared(NUM_MAX, NUM_MIN); - udmfServiceImpl->OnBind( - { "UdmfServiceStubFuzz", static_cast(IPCSkeleton::GetSelfTokenID()), std::move(executor) }); - - MessageParcel requestUpdate; - requestUpdate.WriteInterfaceToken(INTERFACE_TOKEN); - std::string key = provider.ConsumeRandomLengthString(); - ITypesUtil::Marshal(requestUpdate, key); - UnifiedData data; - std::shared_ptr obj = std::make_shared(); - obj->value_[UNIFORM_DATA_TYPE] = "general.file-uri"; - obj->value_[FILE_URI_PARAM] = provider.ConsumeRandomLengthString(); - obj->value_[FILE_TYPE] = provider.ConsumeRandomLengthString(); - auto record = std::make_shared(FILE_URI, obj); - data.AddRecord(record); - ITypesUtil::Marshal(requestUpdate, data); - - MessageParcel replyUpdate; - udmfServiceImpl->OnRemoteRequest(static_cast(UdmfServiceInterfaceCode::SET_DELAY_DATA), - requestUpdate, replyUpdate); - udmfServiceImpl->OnBind( - { "UdmfServiceStubFuzz", static_cast(IPCSkeleton::GetSelfTokenID()), nullptr }); - executor = nullptr; -} - -void GetDataIfAvailableFuzz(FuzzedDataProvider &provider) -{ - std::shared_ptr udmfServiceImpl = std::make_shared(); - std::shared_ptr executor = std::make_shared(NUM_MAX, NUM_MIN); - udmfServiceImpl->OnBind( - { "UdmfServiceStubFuzz", static_cast(IPCSkeleton::GetSelfTokenID()), std::move(executor) }); - - MessageParcel requestUpdate; - requestUpdate.WriteInterfaceToken(INTERFACE_TOKEN); - std::string key = provider.ConsumeRandomLengthString(); - ITypesUtil::Marshal(requestUpdate, key); - DataLoadInfo dataLoadInfo; - dataLoadInfo.recordCount = provider.ConsumeIntegral(); - dataLoadInfo.types.emplace(provider.ConsumeRandomLengthString()); - dataLoadInfo.sequenceKey = provider.ConsumeRandomLengthString(); - ITypesUtil::Marshal(requestUpdate, dataLoadInfo); - sptr iUdmfNotifier = nullptr; - ITypesUtil::Marshal(requestUpdate, iUdmfNotifier); - - MessageParcel replyUpdate; - udmfServiceImpl->OnRemoteRequest(static_cast(UdmfServiceInterfaceCode::GET_DELAY_DATA), - requestUpdate, replyUpdate); - udmfServiceImpl->OnBind( - { "UdmfServiceStubFuzz", static_cast(IPCSkeleton::GetSelfTokenID()), nullptr }); - executor = nullptr; -} - -void OnGetAppShareOptionFuzz(FuzzedDataProvider &provider) -{ - std::shared_ptr udmfServiceImpl = std::make_shared(); - std::shared_ptr executor = std::make_shared(NUM_MAX, NUM_MIN); - udmfServiceImpl->OnBind( - { "UdmfServiceStubFuzz", static_cast(IPCSkeleton::GetSelfTokenID()), std::move(executor) }); - - MessageParcel requestUpdate; - std::vector remainingData = provider.ConsumeRemainingBytes(); - requestUpdate.WriteInterfaceToken(INTERFACE_TOKEN); - requestUpdate.WriteBuffer(static_cast(remainingData.data()), remainingData.size()); - requestUpdate.RewindRead(0); - CustomOption option = {.intention = Intention::UD_INTENTION_DRAG}; - std::string intention = UD_INTENTION_MAP.at(option.intention); - ITypesUtil::Marshal(requestUpdate, intention); - - MessageParcel replyUpdate; - udmfServiceImpl->OnRemoteRequest(static_cast(UdmfServiceInterfaceCode::GET_APP_SHARE_OPTION), - requestUpdate, replyUpdate); - udmfServiceImpl->OnBind( - { "UdmfServiceStubFuzz", static_cast(IPCSkeleton::GetSelfTokenID()), nullptr }); - executor = nullptr; -} - -void CheckDragParamsFuzz(FuzzedDataProvider &provider) -{ - std::shared_ptr udmfServiceImpl = std::make_shared(); - std::string intention = provider.ConsumeRandomLengthString(); - std::string bundleName = provider.ConsumeRandomLengthString(); - std::vector groupId(ID_LEN, '0'); - for (size_t i = 0; i < groupId.size(); ++i) { - groupId[i] = provider.ConsumeIntegralInRange(MINIMUM, MAXIMUM); - } - std::string groupIdStr(groupId.begin(), groupId.end()); - UnifiedKey udKey(intention, bundleName, groupIdStr); - QueryOption query; - udmfServiceImpl->CheckDragParams(udKey, query); -} - -void IsPermissionInCacheFuzz(FuzzedDataProvider &provider) -{ - std::shared_ptr udmfServiceImpl = std::make_shared(); - QueryOption query = GenerateFuzzQueryOption(provider); - udmfServiceImpl->IsPermissionInCache(query); -} - -void IsReadAndKeepFuzz(FuzzedDataProvider &provider) -{ - std::shared_ptr udmfServiceImpl = std::make_shared(); - Privilege privilege; - privilege.tokenId = provider.ConsumeIntegral(); - privilege.readPermission = "read"; - privilege.writePermission = "write"; - Privilege privilege2; - privilege2.tokenId = provider.ConsumeIntegral(); - privilege2.readPermission = "readAndKeep"; - privilege2.writePermission = "write"; - std::vector privileges = { privilege, privilege2 }; - QueryOption query = GenerateFuzzQueryOption(provider); - udmfServiceImpl->IsReadAndKeep(privileges, query); -} - -void ProcessUriFuzz(FuzzedDataProvider &provider) -{ - std::shared_ptr udmfServiceImpl = std::make_shared(); - QueryOption query = GenerateFuzzQueryOption(provider); - UnifiedData data; - std::shared_ptr obj = std::make_shared(); - obj->value_[UNIFORM_DATA_TYPE] = "general.file-uri"; - obj->value_[FILE_URI_PARAM] = provider.ConsumeRandomLengthString(); - obj->value_[FILE_TYPE] = provider.ConsumeRandomLengthString(); - auto record = std::make_shared(FILE_URI, obj); - data.AddRecord(record); - udmfServiceImpl->ProcessUri(query, data); -} - -void ProcessCrossDeviceDataFuzz(FuzzedDataProvider &provider) -{ - std::shared_ptr udmfServiceImpl = std::make_shared(); - uint32_t tokenId = provider.ConsumeIntegral(); - UnifiedData data; - std::shared_ptr obj = std::make_shared(); - obj->value_[UNIFORM_DATA_TYPE] = "general.file-uri"; - obj->value_[FILE_URI_PARAM] = provider.ConsumeRandomLengthString(); - obj->value_[FILE_TYPE] = provider.ConsumeRandomLengthString(); - auto record = std::make_shared(FILE_URI, obj); - data.AddRecord(record); - std::vector uris; - udmfServiceImpl->ProcessCrossDeviceData(tokenId, data, uris); -} - -void ResolveAutoLaunchFuzz(FuzzedDataProvider &provider) -{ - std::shared_ptr udmfServiceImpl = std::make_shared(); - std::shared_ptr executor = std::make_shared(NUM_MAX, NUM_MIN); - udmfServiceImpl->OnBind( - { "UdmfServiceStubFuzz", static_cast(IPCSkeleton::GetSelfTokenID()), std::move(executor) }); - auto identifier = provider.ConsumeRandomLengthString(); - UdmfServiceImpl::DBLaunchParam param; - param.userId = provider.ConsumeRandomLengthString(); - param.appId = provider.ConsumeRandomLengthString(); - param.storeId = provider.ConsumeRandomLengthString(); - param.path = provider.ConsumeRandomLengthString(); - udmfServiceImpl->ResolveAutoLaunch(identifier, param); - udmfServiceImpl->OnBind( - { "UdmfServiceStubFuzz", static_cast(IPCSkeleton::GetSelfTokenID()), nullptr }); - executor = nullptr; -} - -void HasDatahubPriviledgeFuzz(FuzzedDataProvider &provider) -{ - std::shared_ptr udmfServiceImpl = std::make_shared(); - auto bundleName = provider.ConsumeRandomLengthString(); - udmfServiceImpl->HasDatahubPriviledge(bundleName); -} - -void OnUserChangeFuzz(FuzzedDataProvider &provider) -{ - std::shared_ptr udmfServiceImpl = std::make_shared(); - uint32_t code = provider.ConsumeIntegral(); - auto user = provider.ConsumeRandomLengthString(); - auto account = provider.ConsumeRandomLengthString(); - udmfServiceImpl->OnUserChange(code, user, account); -} - -void IsNeedTransferDeviceTypeFuzz(FuzzedDataProvider &provider) -{ - std::shared_ptr udmfServiceImpl = std::make_shared(); - QueryOption query = GenerateFuzzQueryOption(provider); - udmfServiceImpl->IsNeedTransferDeviceType(query); -} - -void CheckAddPrivilegePermissionFuzz(FuzzedDataProvider &provider) -{ - std::shared_ptr udmfServiceImpl = std::make_shared(); - std::string intention = provider.ConsumeRandomLengthString(); - std::string bundleName = provider.ConsumeRandomLengthString(); - std::vector groupId(ID_LEN, '0'); - for (size_t i = 0; i < groupId.size(); ++i) { - groupId[i] = provider.ConsumeIntegralInRange(MINIMUM, MAXIMUM); - } - std::string groupIdStr(groupId.begin(), groupId.end()); - UnifiedKey udKey(intention, bundleName, groupIdStr); - std::string processName = provider.ConsumeRandomLengthString(); - QueryOption query = GenerateFuzzQueryOption(provider); - udmfServiceImpl->CheckAddPrivilegePermission(udKey, processName, query); -} - -void ProcessDataFuzz(FuzzedDataProvider &provider) -{ - std::shared_ptr udmfServiceImpl = std::make_shared(); - QueryOption query = GenerateFuzzQueryOption(provider); - UnifiedData data; - std::shared_ptr obj = std::make_shared(); - obj->value_[UNIFORM_DATA_TYPE] = "general.file-uri"; - obj->value_[FILE_URI_PARAM] = provider.ConsumeRandomLengthString(); - obj->value_[FILE_TYPE] = provider.ConsumeRandomLengthString(); - auto record = std::make_shared(FILE_URI, obj); - data.AddRecord(record); - std::vector dataSet = { data }; - udmfServiceImpl->ProcessData(query, dataSet); -} - -void VerifyIntentionPermissionFuzz(FuzzedDataProvider &provider) -{ - std::shared_ptr udmfServiceImpl = std::make_shared(); - std::shared_ptr executor = std::make_shared(NUM_MAX, NUM_MIN); - udmfServiceImpl->OnBind( - { "UdmfServiceStubFuzz", static_cast(IPCSkeleton::GetSelfTokenID()), std::move(executor) }); - QueryOption query = GenerateFuzzQueryOption(provider); - UnifiedData data; - std::string intention = provider.ConsumeRandomLengthString(); - std::string bundleName = provider.ConsumeRandomLengthString(); - std::vector groupId(ID_LEN); - for (size_t i = 0; i < groupId.size(); ++i) { - groupId[i] = provider.ConsumeIntegralInRange(MINIMUM, MAXIMUM); - } - std::string groupIdStr(groupId.begin(), groupId.end()); - UnifiedKey udKey(intention, bundleName, groupIdStr); - CheckerManager::CheckInfo info; - info.tokenId = provider.ConsumeIntegral(); - udmfServiceImpl->VerifyIntentionPermission(query, data, udKey, info); - Runtime runtime; - data.SetRuntime(runtime); - udmfServiceImpl->VerifyIntentionPermission(query, data, udKey, info); - udmfServiceImpl->OnBind( - { "UdmfServiceStubFuzz", static_cast(IPCSkeleton::GetSelfTokenID()), nullptr }); - executor = nullptr; -} - -void IsFileMangerIntentionFuzz(FuzzedDataProvider &provider) -{ - std::shared_ptr udmfServiceImpl = std::make_shared(); - auto intention = provider.ConsumeRandomLengthString(); - udmfServiceImpl->IsFileMangerIntention(intention); -} - -void CheckAppIdFuzz(FuzzedDataProvider &provider) -{ - std::shared_ptr udmfServiceImpl = std::make_shared(); - std::string intention = provider.ConsumeRandomLengthString(); - std::string bundleName = provider.ConsumeRandomLengthString(); - std::string appId = provider.ConsumeRandomLengthString(); - std::string groupId = provider.ConsumeRandomLengthString(); - uint32_t tokenid = provider.ConsumeIntegral(); - Privilege privilege; - privilege.tokenId = tokenid; - UnifiedData data; - std::shared_ptr obj = std::make_shared(); - obj->value_[UNIFORM_DATA_TYPE] = "general.file-uri"; - obj->value_[FILE_URI_PARAM] = provider.ConsumeRandomLengthString(); - obj->value_[FILE_TYPE] = provider.ConsumeRandomLengthString(); - auto record = std::make_shared(FILE_URI, obj); - data.AddRecord(record); - UnifiedKey key(intention, bundleName, groupId); - std::shared_ptr runtime = std::make_shared(); - runtime->key = key; - runtime->privileges.emplace_back(privilege); - runtime->sourcePackage = bundleName; - runtime->createPackage = bundleName; - runtime->recordTotalNum = static_cast(data.GetRecords().size()); - runtime->tokenId = tokenid; - runtime->appId = appId; - udmfServiceImpl->CheckAppId(runtime, bundleName); -} - -void CheckDeleteDataPermissionFuzz(FuzzedDataProvider &provider) -{ - std::shared_ptr udmfServiceImpl = std::make_shared(); - std::string bundleName = provider.ConsumeRandomLengthString(); - std::string appId = provider.ConsumeRandomLengthString(); - uint32_t tokenid = provider.ConsumeIntegral(); - Privilege privilege; - privilege.tokenId = tokenid; - UnifiedData data; - std::shared_ptr obj = std::make_shared(); - obj->value_[UNIFORM_DATA_TYPE] = "general.file-uri"; - obj->value_[FILE_URI_PARAM] = provider.ConsumeRandomLengthString(); - obj->value_[FILE_TYPE] = provider.ConsumeRandomLengthString(); - auto record = std::make_shared(FILE_URI, obj); - data.AddRecord(record); - std::vector groupId(ID_LEN, '0'); - for (size_t i = 0; i < groupId.size(); ++i) { - groupId[i] = provider.ConsumeIntegralInRange(MINIMUM, MAXIMUM); - } - std::string groupIdStr(groupId.begin(), groupId.end()); - UnifiedKey udKey = UnifiedKey("drag", "com.test.demo", groupIdStr); - std::shared_ptr runtime = std::make_shared(); - runtime->key = udKey; - runtime->privileges.emplace_back(privilege); - runtime->sourcePackage = bundleName; - runtime->createPackage = bundleName; - runtime->recordTotalNum = static_cast(data.GetRecords().size()); - runtime->tokenId = tokenid; - runtime->appId = appId; - QueryOption query; - query.key = udKey.GetUnifiedKey(); - query.intention = Intention::UD_INTENTION_DRAG; - query.tokenId = provider.ConsumeIntegral(); - udmfServiceImpl->CheckDeleteDataPermission(appId, runtime, query); -} - -void StoreSyncFuzz(FuzzedDataProvider &provider) -{ - std::shared_ptr udmfServiceImpl = std::make_shared(); - std::vector groupId(ID_LEN, '0'); - for (size_t i = 0; i < groupId.size(); ++i) { - groupId[i] = provider.ConsumeIntegralInRange(MINIMUM, MAXIMUM); - } - std::string groupIdStr(groupId.begin(), groupId.end()); - UnifiedKey key = UnifiedKey("drag", "com.test.demo", groupIdStr); - QueryOption query; - query.key = key.GetUnifiedKey(); - query.intention = Intention::UD_INTENTION_DRAG; - query.tokenId = provider.ConsumeIntegral(); - std::vector devices = { "11", "22" }; - udmfServiceImpl->StoreSync(key, query, devices); -} - -void SetAppShareOptionFuzz(FuzzedDataProvider &provider) -{ - std::shared_ptr udmfServiceImpl = std::make_shared(); - std::shared_ptr executor = std::make_shared(NUM_MAX, NUM_MIN); - udmfServiceImpl->OnBind( - { "UdmfServiceStubFuzz", static_cast(IPCSkeleton::GetSelfTokenID()), std::move(executor) }); - - MessageParcel requestUpdate; - std::vector remainingData = provider.ConsumeRemainingBytes(); - requestUpdate.WriteInterfaceToken(INTERFACE_TOKEN); - requestUpdate.WriteBuffer(static_cast(remainingData.data()), remainingData.size()); - requestUpdate.RewindRead(0); - CustomOption option = {.intention = Intention::UD_INTENTION_DRAG}; - std::string intention = UD_INTENTION_MAP.at(option.intention); - ITypesUtil::Marshal(requestUpdate, intention); - - MessageParcel replyUpdate; - udmfServiceImpl->OnRemoteRequest(static_cast(UdmfServiceInterfaceCode::SET_APP_SHARE_OPTION), - requestUpdate, replyUpdate); - udmfServiceImpl->OnBind( - { "UdmfServiceStubFuzz", static_cast(IPCSkeleton::GetSelfTokenID()), nullptr }); - executor = nullptr; -} - -void RemoveAppShareOptionFuzz(FuzzedDataProvider &provider) -{ - std::shared_ptr udmfServiceImpl = std::make_shared(); - std::shared_ptr executor = std::make_shared(NUM_MAX, NUM_MIN); - udmfServiceImpl->OnBind( - { "UdmfServiceStubFuzz", static_cast(IPCSkeleton::GetSelfTokenID()), std::move(executor) }); - - MessageParcel requestUpdate; - std::vector remainingData = provider.ConsumeRemainingBytes(); - requestUpdate.WriteInterfaceToken(INTERFACE_TOKEN); - requestUpdate.WriteBuffer(static_cast(remainingData.data()), remainingData.size()); - requestUpdate.RewindRead(0); - CustomOption option = {.intention = Intention::UD_INTENTION_DRAG}; - std::string intention = UD_INTENTION_MAP.at(option.intention); - ITypesUtil::Marshal(requestUpdate, intention); - - MessageParcel replyUpdate; - udmfServiceImpl->OnRemoteRequest(static_cast(UdmfServiceInterfaceCode::REMOVE_APP_SHARE_OPTION), - requestUpdate, replyUpdate); - udmfServiceImpl->OnBind( - { "UdmfServiceStubFuzz", static_cast(IPCSkeleton::GetSelfTokenID()), nullptr }); - executor = nullptr; -} - -void QueryDataCommonFuzz(FuzzedDataProvider &provider) -{ - std::shared_ptr udmfServiceImpl = std::make_shared(); - std::vector groupId(ID_LEN, '0'); - for (size_t i = 0; i < groupId.size(); ++i) { - groupId[i] = provider.ConsumeIntegralInRange(MINIMUM, MAXIMUM); - } - std::string groupIdStr(groupId.begin(), groupId.end()); - UnifiedKey udKey = UnifiedKey("drag", "com.test.demo", groupIdStr); - QueryOption query; - query.key = udKey.GetUnifiedKey(); - query.intention = Intention::UD_INTENTION_DRAG; - query.tokenId = provider.ConsumeIntegral(); - UnifiedData data; - std::shared_ptr obj = std::make_shared(); - obj->value_[UNIFORM_DATA_TYPE] = "general.file-uri"; - obj->value_[FILE_URI_PARAM] = provider.ConsumeRandomLengthString(); - obj->value_[FILE_TYPE] = provider.ConsumeRandomLengthString(); - auto record = std::make_shared(FILE_URI, obj); - data.AddRecord(record); - std::shared_ptr store; - std::vector dataSet = { data }; - udmfServiceImpl->QueryDataCommon(query, dataSet, store); -} - -void ClearAsynProcessByKeyFuzz(FuzzedDataProvider &provider) -{ - std::shared_ptr udmfServiceImpl = std::make_shared(); - std::shared_ptr executor = std::make_shared(NUM_MAX, NUM_MIN); - udmfServiceImpl->OnBind( - { "UdmfServiceStubFuzz", static_cast(IPCSkeleton::GetSelfTokenID()), std::move(executor) }); - - MessageParcel requestUpdate; - std::vector remainingData = provider.ConsumeRemainingBytes(); - requestUpdate.WriteInterfaceToken(INTERFACE_TOKEN); - requestUpdate.WriteBuffer(static_cast(remainingData.data()), remainingData.size()); - requestUpdate.RewindRead(0); - std::string businessUdKey = provider.ConsumeRandomLengthString(); - ITypesUtil::Marshal(requestUpdate, businessUdKey); - - MessageParcel replyUpdate; - udmfServiceImpl->OnRemoteRequest(static_cast(UdmfServiceInterfaceCode::CLEAR_ASYN_PROCESS_BY_KEY), - requestUpdate, replyUpdate); - udmfServiceImpl->OnBind( - { "UdmfServiceStubFuzz", static_cast(IPCSkeleton::GetSelfTokenID()), nullptr }); - executor = nullptr; -} - -void TransferToEntriesIfNeedFuzz(FuzzedDataProvider &provider) -{ - std::shared_ptr udmfServiceImpl = std::make_shared(); - std::vector groupId(ID_LEN, '0'); - for (size_t i = 0; i < groupId.size(); ++i) { - groupId[i] = provider.ConsumeIntegralInRange(MINIMUM, MAXIMUM); - } - std::string groupIdStr(groupId.begin(), groupId.end()); - UnifiedKey udKey = UnifiedKey("drag", "com.test.demo", groupIdStr); - QueryOption query; - query.key = udKey.GetUnifiedKey(); - query.intention = Intention::UD_INTENTION_DRAG; - query.tokenId = provider.ConsumeIntegral(); - UnifiedData data; - std::shared_ptr obj = std::make_shared(); - obj->value_[UNIFORM_DATA_TYPE] = "general.file-uri"; - obj->value_[FILE_URI_PARAM] = provider.ConsumeRandomLengthString(); - obj->value_[FILE_TYPE] = provider.ConsumeRandomLengthString(); - std::shared_ptr obj1 = std::make_shared(); - obj1->value_[UNIFORM_DATA_TYPE] = "general.image-uri"; - obj1->value_[FILE_URI_PARAM] = provider.ConsumeRandomLengthString(); - obj1->value_[FILE_TYPE] = provider.ConsumeRandomLengthString(); - std::shared_ptr obj2 = std::make_shared(); - obj2->value_[UNIFORM_DATA_TYPE] = "general.txt-uri"; - obj2->value_[FILE_URI_PARAM] = provider.ConsumeRandomLengthString(); - obj2->value_[FILE_TYPE] = provider.ConsumeRandomLengthString(); - std::shared_ptr obj3 = std::make_shared(); - obj3->value_[UNIFORM_DATA_TYPE] = "general.html-uri"; - obj3->value_[FILE_URI_PARAM] = provider.ConsumeRandomLengthString(); - obj3->value_[FILE_TYPE] = provider.ConsumeRandomLengthString(); - auto record = std::make_shared(FILE_URI, obj); - auto record1 = std::make_shared(FILE_URI, obj1); - auto record2 = std::make_shared(FILE_URI, obj2); - auto record3 = std::make_shared(FILE_URI, obj3); - data.AddRecord(record); - data.AddRecord(record1); - data.AddRecord(record2); - data.AddRecord(record3); - udmfServiceImpl->TransferToEntriesIfNeed(query, data); -} - -void IsValidOptionsNonDragFuzz(FuzzedDataProvider &provider) -{ - std::shared_ptr udmfServiceImpl = std::make_shared(); - std::vector groupId(ID_LEN, '0'); - for (size_t i = 0; i < groupId.size(); ++i) { - groupId[i] = provider.ConsumeIntegralInRange(MINIMUM, MAXIMUM); - } - std::string groupIdStr(groupId.begin(), groupId.end()); - UnifiedKey key = UnifiedKey("drag", "com.test.demo", groupIdStr); - CustomOption option = {.intention = Intention::UD_INTENTION_DRAG}; - std::string intention = UD_INTENTION_MAP.at(option.intention); - udmfServiceImpl->IsValidOptionsNonDrag(key, intention); -} - -void CloseStoreWhenCorruptedFuzz(FuzzedDataProvider &provider) -{ - std::shared_ptr udmfServiceImpl = std::make_shared(); - std::string intention = provider.ConsumeRandomLengthString(); - int32_t status = provider.ConsumeIntegral(); - udmfServiceImpl->CloseStoreWhenCorrupted(intention, status); -} - -void HandleDbErrorFuzz(FuzzedDataProvider &provider) -{ - std::shared_ptr udmfServiceImpl = std::make_shared(); - std::string intention = provider.ConsumeRandomLengthString(); - int32_t status = provider.ConsumeIntegral(); - udmfServiceImpl->HandleDbError(intention, status); -} - -void BuildMetaFuzz(FuzzedDataProvider &provider) -{ - std::shared_ptr udmfServiceImpl = std::make_shared(); - std::string storeId = provider.ConsumeRandomLengthString(); - int userId = provider.ConsumeIntegral(); - udmfServiceImpl->BuildMeta(storeId, userId); -} - -void ProcessResultFuzz(FuzzedDataProvider &provider) -{ - std::shared_ptr udmfServiceImpl = std::make_shared(); - std::map results; - std::string key = provider.ConsumeRandomLengthString(); - int32_t value = provider.ConsumeIntegral(); - results.emplace(std::make_pair(key, value)); - udmfServiceImpl->ProcessResult(results); -} - -void RegisterAsyncProcessInfoFuzz(FuzzedDataProvider &provider) -{ - std::shared_ptr udmfServiceImpl = std::make_shared(); - std::string businessUdKey = provider.ConsumeRandomLengthString(); - udmfServiceImpl->RegisterAsyncProcessInfo(businessUdKey); -} - -void IsNeedMetaSyncFuzz(FuzzedDataProvider &provider) -{ - std::shared_ptr udmfServiceImpl = std::make_shared(); - DistributedData::StoreMetaData meta; - uint8_t len = provider.ConsumeIntegral(); - std::vector uuids(len); - for (int i = 0; i < len; i++) { - std::string uuid = provider.ConsumeRandomLengthString(); - uuids[i] = uuid; - } - udmfServiceImpl->IsNeedMetaSync(meta, uuids); -} - -void VerifyDataAccessPermissionFuzz(FuzzedDataProvider &provider) -{ - std::shared_ptr udmfServiceImpl = std::make_shared(); - std::shared_ptr runtime = std::make_shared(); - std::vector groupId(ID_LEN, '0'); - for (size_t i = 0; i < groupId.size(); ++i) { - groupId[i] = provider.ConsumeIntegralInRange(MINIMUM, MAXIMUM); - } - std::string groupIdStr(groupId.begin(), groupId.end()); - UnifiedKey udKey = UnifiedKey("drag", "com.test.demo", groupIdStr); - QueryOption query; - query.key = udKey.GetUnifiedKey(); - query.intention = Intention::UD_INTENTION_DRAG; - query.tokenId = provider.ConsumeIntegral(); - UnifiedData data; - std::shared_ptr obj = std::make_shared(); - obj->value_[UNIFORM_DATA_TYPE] = "general.file-uri"; - obj->value_[FILE_URI_PARAM] = provider.ConsumeRandomLengthString(); - obj->value_[FILE_TYPE] = provider.ConsumeRandomLengthString(); - auto record = std::make_shared(FILE_URI, obj); - data.AddRecord(record); - udmfServiceImpl->VerifyDataAccessPermission(runtime, query, data); -} - -void HandleDelayDataCallbackFuzz(FuzzedDataProvider &provider) -{ - std::shared_ptr udmfServiceImpl = std::make_shared(); - DelayGetDataInfo delayGetDataInfo; - UnifiedData unifiedData; - std::shared_ptr obj = std::make_shared(); - obj->value_[UNIFORM_DATA_TYPE] = "general.file-uri"; - obj->value_[FILE_URI_PARAM] = provider.ConsumeRandomLengthString(); - obj->value_[FILE_TYPE] = provider.ConsumeRandomLengthString(); - auto record = std::make_shared(FILE_URI, obj); - unifiedData.AddRecord(record); - std::string key = provider.ConsumeRandomLengthString(); - udmfServiceImpl->HandleDelayDataCallback(delayGetDataInfo, unifiedData, key); -} -} - -/* Fuzzer entry point */ -extern "C" int LLVMFuzzerInitialize(int *argc, char ***argv) -{ - OHOS::Security::AccessToken::AccessTokenID tokenId = - OHOS::Security::AccessToken::AccessTokenKit::GetHapTokenID(100, "com.ohos.dlpmanager", 0); - SetSelfTokenID(tokenId); - return 0; -} - -/* Fuzzer entry point */ -extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) -{ - FuzzedDataProvider provider(data, size); - OHOS::OnRemoteRequestFuzz(provider); - OHOS::SetDataFuzz(provider); - OHOS::GetDataFuzz(provider); - - OHOS::GetBatchDataFuzz(provider); - OHOS::UpdateDataFuzz(provider); - OHOS::DeleteDataFuzz(provider); - - OHOS::GetSummaryFuzz(provider); - OHOS::AddPrivilegeDataFuzz(provider); - OHOS::SyncDataFuzz(provider); - - OHOS::IsRemoteDataFuzz(provider); - OHOS::ObtainAsynProcessFuzz(provider); - OHOS::ClearAsynProcessFuzz(provider); - - OHOS::SetDelayInfoFuzz(provider); - OHOS::PushDelayDataFuzz(provider); - OHOS::GetDataIfAvailableFuzz(provider); - OHOS::OnGetAppShareOptionFuzz(provider); - OHOS::CheckDragParamsFuzz(provider); - OHOS::IsPermissionInCacheFuzz(provider); - OHOS::IsReadAndKeepFuzz(provider); - OHOS::ProcessUriFuzz(provider); - OHOS::ProcessCrossDeviceDataFuzz(provider); - OHOS::ResolveAutoLaunchFuzz(provider); - OHOS::HasDatahubPriviledgeFuzz(provider); - OHOS::OnUserChangeFuzz(provider); - OHOS::IsNeedTransferDeviceTypeFuzz(provider); - OHOS::CheckAddPrivilegePermissionFuzz(provider); - OHOS::ProcessDataFuzz(provider); - OHOS::VerifyIntentionPermissionFuzz(provider); - OHOS::IsFileMangerIntentionFuzz(provider); - OHOS::CheckAppIdFuzz(provider); - OHOS::CheckDeleteDataPermissionFuzz(provider); - OHOS::StoreSyncFuzz(provider); - OHOS::SetAppShareOptionFuzz(provider); - OHOS::RemoveAppShareOptionFuzz(provider); - OHOS::QueryDataCommonFuzz(provider); - OHOS::ClearAsynProcessByKeyFuzz(provider); - OHOS::TransferToEntriesIfNeedFuzz(provider); - OHOS::IsValidOptionsNonDragFuzz(provider); - OHOS::CloseStoreWhenCorruptedFuzz(provider); - OHOS::HandleDbErrorFuzz(provider); - OHOS::BuildMetaFuzz(provider); - OHOS::ProcessResultFuzz(provider); - OHOS::RegisterAsyncProcessInfoFuzz(provider); - OHOS::IsNeedMetaSyncFuzz(provider); - OHOS::VerifyDataAccessPermissionFuzz(provider); - OHOS::HandleDelayDataCallbackFuzz(provider); - return 0; -} \ No newline at end of file diff --git a/services/distributeddataservice/service/test/fuzztest/udmfserviceasynprocess_fuzzer/BUILD.gn b/services/distributeddataservice/service/test/fuzztest/udmfserviceasynprocess_fuzzer/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..43f56847d8408bc5905bfcc0b025ef678d1c4fb4 --- /dev/null +++ b/services/distributeddataservice/service/test/fuzztest/udmfserviceasynprocess_fuzzer/BUILD.gn @@ -0,0 +1,80 @@ +# 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("UdmfServiceAsynProcessFuzzTest") { + module_out_path = "datamgr_service/datamgr_service" + + include_dirs = [ + "${data_service_path}/framework/include", + "${data_service_path}/service/matrix/include", + "${data_service_path}/service/udmf/lifecycle", + "${data_service_path}/service/udmf/permission", + "${data_service_path}/service/udmf/preprocess", + "${data_service_path}/service/udmf/store", + "${data_service_path}/service/udmf", + ] + + fuzz_config_file = + "${data_service_path}/service/test/fuzztest/udmfserviceasynprocess_fuzzer" + + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + "-fno-access-control" + ] + + sources = [ "udmfserviceasynprocess_fuzzer.cpp" ] + + deps = [ + "${data_service_path}/adapter/account:distributeddata_account", + "${data_service_path}/adapter/communicator:distributeddata_communicator", + "${data_service_path}/adapter/dfx:distributeddata_dfx", + "${data_service_path}/framework:distributeddatasvcfwk", + "${data_service_path}/service/bootstrap:distributeddata_bootstrap", + "${data_service_path}/service/matrix:distributeddata_matrix", + "${data_service_path}/service/udmf:udmf_server", + ] + + external_deps = [ + "ability_base:zuri", + "ability_runtime:uri_permission_mgr", + "access_token:libaccesstoken_sdk", + "access_token:libtoken_setproc", + "bundle_framework:appexecfwk_base", + "bundle_framework:appexecfwk_core", + "c_utils:utils", + "hilog:libhilog", + "hisysevent:libhisysevent", + "ipc:ipc_core", + "kv_store:distributeddata_inner", + "kv_store:distributeddata_mgr", + "kv_store:distributeddb", + "samgr:samgr_proxy", + "udmf:udmf_client", + ] +} + +############################################################################### +group("fuzztest") { + testonly = true + + deps = [ ":UdmfServiceAsynProcessFuzzTest" ] +} +############################################################################### \ No newline at end of file diff --git a/services/distributeddataservice/service/test/fuzztest/udmfservice_fuzzer/corpus/init b/services/distributeddataservice/service/test/fuzztest/udmfserviceasynprocess_fuzzer/corpus/init similarity index 92% rename from services/distributeddataservice/service/test/fuzztest/udmfservice_fuzzer/corpus/init rename to services/distributeddataservice/service/test/fuzztest/udmfserviceasynprocess_fuzzer/corpus/init index 2b595da0c26af63ffb2d5f4132c086b2e5986fce..7ade8a0faafeaedba7241e7d4a97b8e1f9691932 100644 --- a/services/distributeddataservice/service/test/fuzztest/udmfservice_fuzzer/corpus/init +++ b/services/distributeddataservice/service/test/fuzztest/udmfserviceasynprocess_fuzzer/corpus/init @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023 Huawei Device Co., Ltd. + * 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 diff --git a/services/distributeddataservice/service/test/fuzztest/udmfservice_fuzzer/project.xml b/services/distributeddataservice/service/test/fuzztest/udmfserviceasynprocess_fuzzer/project.xml similarity index 95% rename from services/distributeddataservice/service/test/fuzztest/udmfservice_fuzzer/project.xml rename to services/distributeddataservice/service/test/fuzztest/udmfserviceasynprocess_fuzzer/project.xml index 3fdba3e8b151bbb9026792021977b81e8a1851a6..a37a23b1533f07ab59744732b0f46b2b5fd958d8 100644 --- a/services/distributeddataservice/service/test/fuzztest/udmfservice_fuzzer/project.xml +++ b/services/distributeddataservice/service/test/fuzztest/udmfserviceasynprocess_fuzzer/project.xml @@ -1,5 +1,5 @@ - + + + + 1000 + + 300 + + 4096 + + \ No newline at end of file diff --git a/services/distributeddataservice/service/test/fuzztest/udmfservicecheckkeyandintention_fuzzer/udmfservicecheckkeyandintention_fuzzer.cpp b/services/distributeddataservice/service/test/fuzztest/udmfservicecheckkeyandintention_fuzzer/udmfservicecheckkeyandintention_fuzzer.cpp new file mode 100644 index 0000000000000000000000000000000000000000..81955733baddf80466f2c1aa1eeaf0541efffd8e --- /dev/null +++ b/services/distributeddataservice/service/test/fuzztest/udmfservicecheckkeyandintention_fuzzer/udmfservicecheckkeyandintention_fuzzer.cpp @@ -0,0 +1,119 @@ +/* + * 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 "udmfservicecheckkeyandintention_fuzzer.h" + +#include "accesstoken_kit.h" +#include "distributeddata_udmf_ipc_interface_code.h" +#include "itypes_util.h" +#include "ipc_skeleton.h" +#include "message_parcel.h" +#include "securec.h" +#include "token_setproc.h" +#include "udmf_service_impl.h" +#include "udmf_types_util.h" + +using namespace OHOS::UDMF; + +namespace OHOS { +static constexpr int ID_LEN = 32; +static constexpr int MINIMUM = 48; +static constexpr int MAXIMUM = 121; + +void CheckDragParamsFuzz(FuzzedDataProvider &provider) +{ + std::shared_ptr udmfServiceImpl = std::make_shared(); + std::string intention = provider.ConsumeRandomLengthString(); + std::string bundleName = provider.ConsumeRandomLengthString(); + std::vector groupId(ID_LEN, '0'); + for (size_t i = 0; i < groupId.size(); ++i) { + groupId[i] = provider.ConsumeIntegralInRange(MINIMUM, MAXIMUM); + } + std::string groupIdStr(groupId.begin(), groupId.end()); + UnifiedKey udKey(intention, bundleName, groupIdStr); + QueryOption query; + udmfServiceImpl->CheckDragParams(udKey, query); +} + +void IsFileMangerIntentionFuzz(FuzzedDataProvider &provider) +{ + std::shared_ptr udmfServiceImpl = std::make_shared(); + auto intention = provider.ConsumeRandomLengthString(); + udmfServiceImpl->IsFileMangerIntention(intention); +} + +void CheckAppIdFuzz(FuzzedDataProvider &provider) +{ + std::shared_ptr udmfServiceImpl = std::make_shared(); + std::string intention = provider.ConsumeRandomLengthString(); + std::string bundleName = provider.ConsumeRandomLengthString(); + std::string groupId = provider.ConsumeRandomLengthString(); + Privilege privilege; + privilege.tokenId = provider.ConsumeIntegral(); + UnifiedData data; + std::shared_ptr obj = std::make_shared(); + obj->value_[UNIFORM_DATA_TYPE] = "general.file-uri"; + obj->value_[FILE_URI_PARAM] = provider.ConsumeRandomLengthString(); + obj->value_[FILE_TYPE] = provider.ConsumeRandomLengthString(); + auto record = std::make_shared(FILE_URI, obj); + data.AddRecord(record); + UnifiedKey key(intention, bundleName, groupId); + std::shared_ptr runtime = std::make_shared(); + runtime->key = key; + runtime->privileges.emplace_back(privilege); + runtime->sourcePackage = bundleName; + runtime->createPackage = bundleName; + runtime->recordTotalNum = static_cast(data.GetRecords().size()); + runtime->tokenId = provider.ConsumeIntegral(); + runtime->appId = provider.ConsumeRandomLengthString(); + udmfServiceImpl->CheckAppId(runtime, bundleName); +} + +void IsValidOptionsNonDragFuzz(FuzzedDataProvider &provider) +{ + std::shared_ptr udmfServiceImpl = std::make_shared(); + std::vector groupId(ID_LEN, '0'); + for (size_t i = 0; i < groupId.size(); ++i) { + groupId[i] = provider.ConsumeIntegralInRange(MINIMUM, MAXIMUM); + } + std::string groupIdStr(groupId.begin(), groupId.end()); + UnifiedKey key = UnifiedKey("drag", "com.test.demo", groupIdStr); + CustomOption option = {.intention = Intention::UD_INTENTION_DRAG}; + std::string intention = UD_INTENTION_MAP.at(option.intention); + udmfServiceImpl->IsValidOptionsNonDrag(key, intention); +} +} + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerInitialize(int *argc, char ***argv) +{ + OHOS::Security::AccessToken::AccessTokenID tokenId = + OHOS::Security::AccessToken::AccessTokenKit::GetHapTokenID(100, "com.ohos.dlpmanager", 0); + SetSelfTokenID(tokenId); + return 0; +} + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + FuzzedDataProvider provider(data, size); + OHOS::CheckDragParamsFuzz(provider); + OHOS::IsFileMangerIntentionFuzz(provider); + OHOS::CheckAppIdFuzz(provider); + OHOS::IsValidOptionsNonDragFuzz(provider); + return 0; +} \ No newline at end of file diff --git a/services/distributeddataservice/service/test/fuzztest/udmfservicecheckkeyandintention_fuzzer/udmfservicecheckkeyandintention_fuzzer.h b/services/distributeddataservice/service/test/fuzztest/udmfservicecheckkeyandintention_fuzzer/udmfservicecheckkeyandintention_fuzzer.h new file mode 100644 index 0000000000000000000000000000000000000000..c04ec80032efbd1bf392bbee8458d859fd2e95e8 --- /dev/null +++ b/services/distributeddataservice/service/test/fuzztest/udmfservicecheckkeyandintention_fuzzer/udmfservicecheckkeyandintention_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 UDMF_SERVICE_CHECK_KEY_AND_INTENTION_FUZZER_H +#define UDMF_SERVICE_CHECK_KEY_AND_INTENTION_FUZZER_H + +#define FUZZ_PROJECT_NAME "udmfservicecheckkeyandintention_fuzzer" + +#endif // UDMF_SERVICE_CHECK_KEY_AND_INTENTION_FUZZER_H \ No newline at end of file diff --git a/services/distributeddataservice/service/test/fuzztest/udmfservicecheckpermission_fuzzer/BUILD.gn b/services/distributeddataservice/service/test/fuzztest/udmfservicecheckpermission_fuzzer/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..2123c0619adcb3d9053a519643b36dedef32c159 --- /dev/null +++ b/services/distributeddataservice/service/test/fuzztest/udmfservicecheckpermission_fuzzer/BUILD.gn @@ -0,0 +1,80 @@ +# 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("UdmfServiceCheckPermissionFuzzTest") { + module_out_path = "datamgr_service/datamgr_service" + + include_dirs = [ + "${data_service_path}/framework/include", + "${data_service_path}/service/matrix/include", + "${data_service_path}/service/udmf/lifecycle", + "${data_service_path}/service/udmf/permission", + "${data_service_path}/service/udmf/preprocess", + "${data_service_path}/service/udmf/store", + "${data_service_path}/service/udmf", + ] + + fuzz_config_file = + "${data_service_path}/service/test/fuzztest/udmfservicecheckpermission_fuzzer" + + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + "-fno-access-control" + ] + + sources = [ "udmfservicecheckpermission_fuzzer.cpp" ] + + deps = [ + "${data_service_path}/adapter/account:distributeddata_account", + "${data_service_path}/adapter/communicator:distributeddata_communicator", + "${data_service_path}/adapter/dfx:distributeddata_dfx", + "${data_service_path}/framework:distributeddatasvcfwk", + "${data_service_path}/service/bootstrap:distributeddata_bootstrap", + "${data_service_path}/service/matrix:distributeddata_matrix", + "${data_service_path}/service/udmf:udmf_server", + ] + + external_deps = [ + "ability_base:zuri", + "ability_runtime:uri_permission_mgr", + "access_token:libaccesstoken_sdk", + "access_token:libtoken_setproc", + "bundle_framework:appexecfwk_base", + "bundle_framework:appexecfwk_core", + "c_utils:utils", + "hilog:libhilog", + "hisysevent:libhisysevent", + "ipc:ipc_core", + "kv_store:distributeddata_inner", + "kv_store:distributeddata_mgr", + "kv_store:distributeddb", + "samgr:samgr_proxy", + "udmf:udmf_client", + ] +} + +############################################################################### +group("fuzztest") { + testonly = true + + deps = [ ":UdmfServiceCheckPermissionFuzzTest" ] +} +############################################################################### \ No newline at end of file diff --git a/services/distributeddataservice/service/test/fuzztest/udmfservicecheckpermission_fuzzer/corpus/init b/services/distributeddataservice/service/test/fuzztest/udmfservicecheckpermission_fuzzer/corpus/init new file mode 100644 index 0000000000000000000000000000000000000000..7ade8a0faafeaedba7241e7d4a97b8e1f9691932 --- /dev/null +++ b/services/distributeddataservice/service/test/fuzztest/udmfservicecheckpermission_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/udmfservicecheckpermission_fuzzer/project.xml b/services/distributeddataservice/service/test/fuzztest/udmfservicecheckpermission_fuzzer/project.xml new file mode 100644 index 0000000000000000000000000000000000000000..a37a23b1533f07ab59744732b0f46b2b5fd958d8 --- /dev/null +++ b/services/distributeddataservice/service/test/fuzztest/udmfservicecheckpermission_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + \ No newline at end of file diff --git a/services/distributeddataservice/service/test/fuzztest/udmfservicecheckpermission_fuzzer/udmfservicecheckpermission_fuzzer.cpp b/services/distributeddataservice/service/test/fuzztest/udmfservicecheckpermission_fuzzer/udmfservicecheckpermission_fuzzer.cpp new file mode 100644 index 0000000000000000000000000000000000000000..3f0945d01a7a2fa7a5b746ee109313141cf8f6e6 --- /dev/null +++ b/services/distributeddataservice/service/test/fuzztest/udmfservicecheckpermission_fuzzer/udmfservicecheckpermission_fuzzer.cpp @@ -0,0 +1,128 @@ +/* + * 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 "udmfservicecheckpermission_fuzzer.h" + +#include "accesstoken_kit.h" +#include "distributeddata_udmf_ipc_interface_code.h" +#include "itypes_util.h" +#include "ipc_skeleton.h" +#include "message_parcel.h" +#include "securec.h" +#include "token_setproc.h" +#include "udmf_service_impl.h" +#include "udmf_types_util.h" + +using namespace OHOS::UDMF; + +namespace OHOS { +static constexpr int ID_LEN = 32; +static constexpr int MINIMUM = 48; +static constexpr int MAXIMUM = 121; + +QueryOption GenerateFuzzQueryOption(FuzzedDataProvider &provider) +{ + std::vector groupId(ID_LEN, '0'); + for (size_t i = 0; i < groupId.size(); ++i) { + groupId[i] = provider.ConsumeIntegralInRange(MINIMUM, MAXIMUM); + } + std::string groupIdStr(groupId.begin(), groupId.end()); + UnifiedKey udKey = UnifiedKey("drag", "com.test.demo", groupIdStr); + QueryOption query; + query.key = udKey.GetUnifiedKey(); + query.intention = Intention::UD_INTENTION_DRAG; + query.tokenId = provider.ConsumeIntegral(); + return query; +} + +void IsPermissionInCacheFuzz(FuzzedDataProvider &provider) +{ + std::shared_ptr udmfServiceImpl = std::make_shared(); + QueryOption query = GenerateFuzzQueryOption(provider); + udmfServiceImpl->IsPermissionInCache(query); +} + +void CheckAddPrivilegePermissionFuzz(FuzzedDataProvider &provider) +{ + std::shared_ptr udmfServiceImpl = std::make_shared(); + std::string intention = provider.ConsumeRandomLengthString(); + std::string bundleName = provider.ConsumeRandomLengthString(); + std::vector groupId(ID_LEN, '0'); + for (size_t i = 0; i < groupId.size(); ++i) { + groupId[i] = provider.ConsumeIntegralInRange(MINIMUM, MAXIMUM); + } + std::string groupIdStr(groupId.begin(), groupId.end()); + UnifiedKey udKey(intention, bundleName, groupIdStr); + std::string processName = provider.ConsumeRandomLengthString(); + QueryOption query = GenerateFuzzQueryOption(provider); + udmfServiceImpl->CheckAddPrivilegePermission(udKey, processName, query); +} + +void CheckDeleteDataPermissionFuzz(FuzzedDataProvider &provider) +{ + std::shared_ptr udmfServiceImpl = std::make_shared(); + std::string bundleName = provider.ConsumeRandomLengthString(); + std::string appId = provider.ConsumeRandomLengthString(); + Privilege privilege; + privilege.tokenId = provider.ConsumeIntegral(); + UnifiedData data; + std::shared_ptr obj = std::make_shared(); + obj->value_[UNIFORM_DATA_TYPE] = "general.file-uri"; + obj->value_[FILE_URI_PARAM] = provider.ConsumeRandomLengthString(); + obj->value_[FILE_TYPE] = provider.ConsumeRandomLengthString(); + auto record = std::make_shared(FILE_URI, obj); + data.AddRecord(record); + std::vector groupId(ID_LEN, '0'); + for (size_t i = 0; i < groupId.size(); ++i) { + groupId[i] = provider.ConsumeIntegralInRange(MINIMUM, MAXIMUM); + } + std::string groupIdStr(groupId.begin(), groupId.end()); + UnifiedKey udKey = UnifiedKey("drag", "com.test.demo", groupIdStr); + std::shared_ptr runtime = std::make_shared(); + runtime->key = udKey; + runtime->privileges.emplace_back(privilege); + runtime->sourcePackage = bundleName; + runtime->createPackage = bundleName; + runtime->recordTotalNum = static_cast(data.GetRecords().size()); + runtime->tokenId = provider.ConsumeIntegral(); + runtime->appId = appId; + QueryOption query; + query.key = udKey.GetUnifiedKey(); + query.intention = Intention::UD_INTENTION_DRAG; + query.tokenId = provider.ConsumeIntegral(); + udmfServiceImpl->CheckDeleteDataPermission(appId, runtime, query); +} +} + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerInitialize(int *argc, char ***argv) +{ + OHOS::Security::AccessToken::AccessTokenID tokenId = + OHOS::Security::AccessToken::AccessTokenKit::GetHapTokenID(100, "com.ohos.dlpmanager", 0); + SetSelfTokenID(tokenId); + return 0; +} + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + FuzzedDataProvider provider(data, size); + OHOS::IsPermissionInCacheFuzz(provider); + OHOS::CheckAddPrivilegePermissionFuzz(provider); + OHOS::CheckDeleteDataPermissionFuzz(provider); + return 0; +} \ No newline at end of file diff --git a/services/distributeddataservice/service/test/fuzztest/udmfservicecheckpermission_fuzzer/udmfservicecheckpermission_fuzzer.h b/services/distributeddataservice/service/test/fuzztest/udmfservicecheckpermission_fuzzer/udmfservicecheckpermission_fuzzer.h new file mode 100644 index 0000000000000000000000000000000000000000..7b0f8684d3f565d6e044e37ce99c5f53b77c05a1 --- /dev/null +++ b/services/distributeddataservice/service/test/fuzztest/udmfservicecheckpermission_fuzzer/udmfservicecheckpermission_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 UDMF_SERVICE_CHECK_PERMISSION_FUZZER_H +#define UDMF_SERVICE_CHECK_PERMISSION_FUZZER_H + +#define FUZZ_PROJECT_NAME "udmfservicecheckpermission_fuzzer" + +#endif // UDMF_SERVICE_CHECK_PERMISSION_FUZZER_H \ No newline at end of file diff --git a/services/distributeddataservice/service/test/fuzztest/udmfservicechecktransferparams_fuzzer/BUILD.gn b/services/distributeddataservice/service/test/fuzztest/udmfservicechecktransferparams_fuzzer/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..acb8fb933e0362943d302f353e6789a8d6f07888 --- /dev/null +++ b/services/distributeddataservice/service/test/fuzztest/udmfservicechecktransferparams_fuzzer/BUILD.gn @@ -0,0 +1,80 @@ +# 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("UdmfServiceCheckTransferParamsFuzzTest") { + module_out_path = "datamgr_service/datamgr_service" + + include_dirs = [ + "${data_service_path}/framework/include", + "${data_service_path}/service/matrix/include", + "${data_service_path}/service/udmf/lifecycle", + "${data_service_path}/service/udmf/permission", + "${data_service_path}/service/udmf/preprocess", + "${data_service_path}/service/udmf/store", + "${data_service_path}/service/udmf", + ] + + fuzz_config_file = + "${data_service_path}/service/test/fuzztest/udmfservicechecktransferparams_fuzzer" + + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + "-fno-access-control" + ] + + sources = [ "udmfservicechecktransferparams_fuzzer.cpp" ] + + deps = [ + "${data_service_path}/adapter/account:distributeddata_account", + "${data_service_path}/adapter/communicator:distributeddata_communicator", + "${data_service_path}/adapter/dfx:distributeddata_dfx", + "${data_service_path}/framework:distributeddatasvcfwk", + "${data_service_path}/service/bootstrap:distributeddata_bootstrap", + "${data_service_path}/service/matrix:distributeddata_matrix", + "${data_service_path}/service/udmf:udmf_server", + ] + + external_deps = [ + "ability_base:zuri", + "ability_runtime:uri_permission_mgr", + "access_token:libaccesstoken_sdk", + "access_token:libtoken_setproc", + "bundle_framework:appexecfwk_base", + "bundle_framework:appexecfwk_core", + "c_utils:utils", + "hilog:libhilog", + "hisysevent:libhisysevent", + "ipc:ipc_core", + "kv_store:distributeddata_inner", + "kv_store:distributeddata_mgr", + "kv_store:distributeddb", + "samgr:samgr_proxy", + "udmf:udmf_client", + ] +} + +############################################################################### +group("fuzztest") { + testonly = true + + deps = [ ":UdmfServiceCheckTransferParamsFuzzTest" ] +} +############################################################################### \ No newline at end of file diff --git a/services/distributeddataservice/service/test/fuzztest/udmfservicechecktransferparams_fuzzer/corpus/init b/services/distributeddataservice/service/test/fuzztest/udmfservicechecktransferparams_fuzzer/corpus/init new file mode 100644 index 0000000000000000000000000000000000000000..7ade8a0faafeaedba7241e7d4a97b8e1f9691932 --- /dev/null +++ b/services/distributeddataservice/service/test/fuzztest/udmfservicechecktransferparams_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/udmfservicechecktransferparams_fuzzer/project.xml b/services/distributeddataservice/service/test/fuzztest/udmfservicechecktransferparams_fuzzer/project.xml new file mode 100644 index 0000000000000000000000000000000000000000..a37a23b1533f07ab59744732b0f46b2b5fd958d8 --- /dev/null +++ b/services/distributeddataservice/service/test/fuzztest/udmfservicechecktransferparams_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + \ No newline at end of file diff --git a/services/distributeddataservice/service/test/fuzztest/udmfservicechecktransferparams_fuzzer/udmfservicechecktransferparams_fuzzer.cpp b/services/distributeddataservice/service/test/fuzztest/udmfservicechecktransferparams_fuzzer/udmfservicechecktransferparams_fuzzer.cpp new file mode 100644 index 0000000000000000000000000000000000000000..86385ba376e992106d1de83b0766d5e059858c43 --- /dev/null +++ b/services/distributeddataservice/service/test/fuzztest/udmfservicechecktransferparams_fuzzer/udmfservicechecktransferparams_fuzzer.cpp @@ -0,0 +1,117 @@ +/* + * 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 "udmfservicechecktransferparams_fuzzer.h" + +#include "accesstoken_kit.h" +#include "distributeddata_udmf_ipc_interface_code.h" +#include "itypes_util.h" +#include "ipc_skeleton.h" +#include "message_parcel.h" +#include "securec.h" +#include "token_setproc.h" +#include "udmf_service_impl.h" +#include "udmf_types_util.h" + +using namespace OHOS::UDMF; + +namespace OHOS { +static constexpr int ID_LEN = 32; +static constexpr int MINIMUM = 48; +static constexpr int MAXIMUM = 121; + +QueryOption GenerateFuzzQueryOption(FuzzedDataProvider &provider) +{ + std::vector groupId(ID_LEN, '0'); + for (size_t i = 0; i < groupId.size(); ++i) { + groupId[i] = provider.ConsumeIntegralInRange(MINIMUM, MAXIMUM); + } + std::string groupIdStr(groupId.begin(), groupId.end()); + UnifiedKey udKey = UnifiedKey("drag", "com.test.demo", groupIdStr); + QueryOption query; + query.key = udKey.GetUnifiedKey(); + query.intention = Intention::UD_INTENTION_DRAG; + query.tokenId = provider.ConsumeIntegral(); + return query; +} + +void IsNeedTransferDeviceTypeFuzz(FuzzedDataProvider &provider) +{ + std::shared_ptr udmfServiceImpl = std::make_shared(); + QueryOption query = GenerateFuzzQueryOption(provider); + udmfServiceImpl->IsNeedTransferDeviceType(query); +} + +void TransferToEntriesIfNeedFuzz(FuzzedDataProvider &provider) +{ + std::shared_ptr udmfServiceImpl = std::make_shared(); + std::vector groupId(ID_LEN, '0'); + for (size_t i = 0; i < groupId.size(); ++i) { + groupId[i] = provider.ConsumeIntegralInRange(MINIMUM, MAXIMUM); + } + std::string groupIdStr(groupId.begin(), groupId.end()); + UnifiedKey udKey = UnifiedKey("drag", "com.test.demo", groupIdStr); + QueryOption query; + query.key = udKey.GetUnifiedKey(); + query.intention = Intention::UD_INTENTION_DRAG; + query.tokenId = provider.ConsumeIntegral(); + UnifiedData data; + std::shared_ptr obj = std::make_shared(); + obj->value_[UNIFORM_DATA_TYPE] = "general.file-uri"; + obj->value_[FILE_URI_PARAM] = provider.ConsumeRandomLengthString(); + obj->value_[FILE_TYPE] = provider.ConsumeRandomLengthString(); + std::shared_ptr obj1 = std::make_shared(); + obj1->value_[UNIFORM_DATA_TYPE] = "general.image-uri"; + obj1->value_[FILE_URI_PARAM] = provider.ConsumeRandomLengthString(); + obj1->value_[FILE_TYPE] = provider.ConsumeRandomLengthString(); + std::shared_ptr obj2 = std::make_shared(); + obj2->value_[UNIFORM_DATA_TYPE] = "general.txt-uri"; + obj2->value_[FILE_URI_PARAM] = provider.ConsumeRandomLengthString(); + obj2->value_[FILE_TYPE] = provider.ConsumeRandomLengthString(); + std::shared_ptr obj3 = std::make_shared(); + obj3->value_[UNIFORM_DATA_TYPE] = "general.html-uri"; + obj3->value_[FILE_URI_PARAM] = provider.ConsumeRandomLengthString(); + obj3->value_[FILE_TYPE] = provider.ConsumeRandomLengthString(); + auto record = std::make_shared(FILE_URI, obj); + auto record1 = std::make_shared(FILE_URI, obj1); + auto record2 = std::make_shared(FILE_URI, obj2); + auto record3 = std::make_shared(FILE_URI, obj3); + data.AddRecord(record); + data.AddRecord(record1); + data.AddRecord(record2); + data.AddRecord(record3); + udmfServiceImpl->TransferToEntriesIfNeed(query, data); +} +} + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerInitialize(int *argc, char ***argv) +{ + OHOS::Security::AccessToken::AccessTokenID tokenId = + OHOS::Security::AccessToken::AccessTokenKit::GetHapTokenID(100, "com.ohos.dlpmanager", 0); + SetSelfTokenID(tokenId); + return 0; +} + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + FuzzedDataProvider provider(data, size); + OHOS::IsNeedTransferDeviceTypeFuzz(provider); + OHOS::TransferToEntriesIfNeedFuzz(provider); + return 0; +} \ No newline at end of file diff --git a/services/distributeddataservice/service/test/fuzztest/udmfservicechecktransferparams_fuzzer/udmfservicechecktransferparams_fuzzer.h b/services/distributeddataservice/service/test/fuzztest/udmfservicechecktransferparams_fuzzer/udmfservicechecktransferparams_fuzzer.h new file mode 100644 index 0000000000000000000000000000000000000000..792bc28e411999056d65f49dd1622c6a5ea41432 --- /dev/null +++ b/services/distributeddataservice/service/test/fuzztest/udmfservicechecktransferparams_fuzzer/udmfservicechecktransferparams_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 UDMF_SERVICE_CHECK_TRANSFER_PAMAMS_FUZZER_H +#define UDMF_SERVICE_CHECK_TRANSFER_PAMAMS_FUZZER_H + +#define FUZZ_PROJECT_NAME "udmfservicechecktransferparams_fuzzer" + +#endif // UDMF_SERVICE_CHECK_TRANSFER_PAMAMS_FUZZER_H \ No newline at end of file diff --git a/services/distributeddataservice/service/test/fuzztest/udmfservice_fuzzer/BUILD.gn b/services/distributeddataservice/service/test/fuzztest/udmfservicedata_fuzzer/BUILD.gn similarity index 91% rename from services/distributeddataservice/service/test/fuzztest/udmfservice_fuzzer/BUILD.gn rename to services/distributeddataservice/service/test/fuzztest/udmfservicedata_fuzzer/BUILD.gn index 398162fcc317b76037c3d3ce7bb6fe90e603c982..3ae3ebc8dd7a64c0a8e9fc77c6d94151920a3a62 100644 --- a/services/distributeddataservice/service/test/fuzztest/udmfservice_fuzzer/BUILD.gn +++ b/services/distributeddataservice/service/test/fuzztest/udmfservicedata_fuzzer/BUILD.gn @@ -1,4 +1,4 @@ -# Copyright (c) 2023 Huawei Device Co., Ltd. +# 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 @@ -16,7 +16,7 @@ import("//build/test.gni") import("//foundation/distributeddatamgr/datamgr_service/datamgr_service.gni") ##############################fuzztest########################################## -ohos_fuzztest("UdmfServiceFuzzTest") { +ohos_fuzztest("UdmfServiceDataFuzzTest") { module_out_path = "datamgr_service/datamgr_service" include_dirs = [ @@ -30,7 +30,7 @@ ohos_fuzztest("UdmfServiceFuzzTest") { ] fuzz_config_file = - "${data_service_path}/service/test/fuzztest/udmfservice_fuzzer" + "${data_service_path}/service/test/fuzztest/udmfservicedata_fuzzer" cflags = [ "-g", @@ -40,7 +40,7 @@ ohos_fuzztest("UdmfServiceFuzzTest") { "-fno-access-control" ] - sources = [ "udmfservice_fuzzer.cpp" ] + sources = [ "udmfservicedata_fuzzer.cpp" ] deps = [ "${data_service_path}/adapter/account:distributeddata_account", @@ -75,6 +75,6 @@ ohos_fuzztest("UdmfServiceFuzzTest") { group("fuzztest") { testonly = true - deps = [ ":UdmfServiceFuzzTest" ] + deps = [ ":UdmfServiceDataFuzzTest" ] } ############################################################################### \ No newline at end of file diff --git a/services/distributeddataservice/service/test/fuzztest/udmfservicedata_fuzzer/corpus/init b/services/distributeddataservice/service/test/fuzztest/udmfservicedata_fuzzer/corpus/init new file mode 100644 index 0000000000000000000000000000000000000000..7ade8a0faafeaedba7241e7d4a97b8e1f9691932 --- /dev/null +++ b/services/distributeddataservice/service/test/fuzztest/udmfservicedata_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/udmfservicedata_fuzzer/project.xml b/services/distributeddataservice/service/test/fuzztest/udmfservicedata_fuzzer/project.xml new file mode 100644 index 0000000000000000000000000000000000000000..a37a23b1533f07ab59744732b0f46b2b5fd958d8 --- /dev/null +++ b/services/distributeddataservice/service/test/fuzztest/udmfservicedata_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + \ No newline at end of file diff --git a/services/distributeddataservice/service/test/fuzztest/udmfservicedata_fuzzer/udmfservicedata_fuzzer.cpp b/services/distributeddataservice/service/test/fuzztest/udmfservicedata_fuzzer/udmfservicedata_fuzzer.cpp new file mode 100644 index 0000000000000000000000000000000000000000..8ca094a00c336c826b9497bc83b10b813c8f3de5 --- /dev/null +++ b/services/distributeddataservice/service/test/fuzztest/udmfservicedata_fuzzer/udmfservicedata_fuzzer.cpp @@ -0,0 +1,156 @@ +/* + * 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 "udmfservicedata_fuzzer.h" + +#include "accesstoken_kit.h" +#include "distributeddata_udmf_ipc_interface_code.h" +#include "itypes_util.h" +#include "ipc_skeleton.h" +#include "message_parcel.h" +#include "securec.h" +#include "token_setproc.h" +#include "udmf_service_impl.h" +#include "udmf_types_util.h" + +using namespace OHOS::UDMF; + +namespace OHOS { +const std::u16string INTERFACE_TOKEN = u"OHOS.UDMF.UdmfService"; +constexpr size_t NUM_MIN = 5; +constexpr size_t NUM_MAX = 12; +static constexpr int ID_LEN = 32; +static constexpr int MINIMUM = 48; +static constexpr int MAXIMUM = 121; + +QueryOption GenerateFuzzQueryOption(FuzzedDataProvider &provider) +{ + std::vector groupId(ID_LEN, '0'); + for (size_t i = 0; i < groupId.size(); ++i) { + groupId[i] = provider.ConsumeIntegralInRange(MINIMUM, MAXIMUM); + } + std::string groupIdStr(groupId.begin(), groupId.end()); + UnifiedKey udKey = UnifiedKey("drag", "com.test.demo", groupIdStr); + QueryOption query; + query.key = udKey.GetUnifiedKey(); + query.intention = Intention::UD_INTENTION_DRAG; + query.tokenId = provider.ConsumeIntegral(); + return query; +} + +void GetBatchDataFuzz(FuzzedDataProvider &provider) +{ + std::shared_ptr udmfServiceImpl = std::make_shared(); + std::shared_ptr executor = std::make_shared(NUM_MAX, NUM_MIN); + udmfServiceImpl->OnBind( + { "UdmfServiceDataFuzzTest", static_cast(IPCSkeleton::GetSelfTokenID()), std::move(executor) }); + QueryOption query = GenerateFuzzQueryOption(provider); + MessageParcel request; + request.WriteInterfaceToken(INTERFACE_TOKEN); + ITypesUtil::Marshal(request, query); + MessageParcel reply; + udmfServiceImpl->OnRemoteRequest(static_cast(UdmfServiceInterfaceCode::GET_BATCH_DATA), request, reply); + udmfServiceImpl->OnBind( + { "UdmfServiceDataFuzzTest", static_cast(IPCSkeleton::GetSelfTokenID()), nullptr }); + executor = nullptr; +} + +void GetSummaryFuzz(FuzzedDataProvider &provider) +{ + std::shared_ptr udmfServiceImpl = std::make_shared(); + std::shared_ptr executor = std::make_shared(NUM_MAX, NUM_MIN); + udmfServiceImpl->OnBind( + { "UdmfServiceDataFuzzTest", static_cast(IPCSkeleton::GetSelfTokenID()), std::move(executor) }); + QueryOption query = GenerateFuzzQueryOption(provider); + MessageParcel request; + request.WriteInterfaceToken(INTERFACE_TOKEN); + ITypesUtil::Marshal(request, query); + MessageParcel reply; + udmfServiceImpl->OnRemoteRequest(static_cast(UdmfServiceInterfaceCode::GET_SUMMARY), request, reply); + udmfServiceImpl->OnBind( + { "UdmfServiceDataFuzzTest", static_cast(IPCSkeleton::GetSelfTokenID()), nullptr }); + executor = nullptr; +} + +void QueryDataCommonFuzz(FuzzedDataProvider &provider) +{ + std::shared_ptr udmfServiceImpl = std::make_shared(); + std::vector groupId(ID_LEN, '0'); + for (size_t i = 0; i < groupId.size(); ++i) { + groupId[i] = provider.ConsumeIntegralInRange(MINIMUM, MAXIMUM); + } + std::string groupIdStr(groupId.begin(), groupId.end()); + UnifiedKey udKey = UnifiedKey("drag", "com.test.demo", groupIdStr); + QueryOption query; + query.key = udKey.GetUnifiedKey(); + query.intention = Intention::UD_INTENTION_DRAG; + query.tokenId = provider.ConsumeIntegral(); + UnifiedData data; + std::shared_ptr obj = std::make_shared(); + obj->value_[UNIFORM_DATA_TYPE] = "general.file-uri"; + obj->value_[FILE_URI_PARAM] = provider.ConsumeRandomLengthString(); + obj->value_[FILE_TYPE] = provider.ConsumeRandomLengthString(); + auto record = std::make_shared(FILE_URI, obj); + data.AddRecord(record); + std::shared_ptr store; + std::vector dataSet = { data }; + udmfServiceImpl->QueryDataCommon(query, dataSet, store); +} + +void RetrieveDataFuzz(FuzzedDataProvider &provider) +{ + std::shared_ptr udmfServiceImpl = std::make_shared(); + UnifiedData unifiedData; + std::shared_ptr obj = std::make_shared(); + obj->value_[UNIFORM_DATA_TYPE] = "general.file-uri"; + obj->value_[FILE_URI_PARAM] = provider.ConsumeRandomLengthString(); + obj->value_[FILE_TYPE] = provider.ConsumeRandomLengthString(); + auto record = std::make_shared(FILE_URI, obj); + unifiedData.AddRecord(record); + std::vector groupId(ID_LEN, '0'); + for (size_t i = 0; i < groupId.size(); ++i) { + groupId[i] = provider.ConsumeIntegralInRange(MINIMUM, MAXIMUM); + } + std::string groupIdStr(groupId.begin(), groupId.end()); + UnifiedKey udKey = UnifiedKey("drag", "com.test.demo", groupIdStr); + QueryOption query; + query.key = udKey.GetUnifiedKey(); + query.intention = Intention::UD_INTENTION_DRAG; + query.tokenId = provider.ConsumeIntegral(); + udmfServiceImpl->RetrieveData(query, unifiedData); +} +} + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerInitialize(int *argc, char ***argv) +{ + OHOS::Security::AccessToken::AccessTokenID tokenId = + OHOS::Security::AccessToken::AccessTokenKit::GetHapTokenID(100, "com.ohos.dlpmanager", 0); + SetSelfTokenID(tokenId); + return 0; +} + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + FuzzedDataProvider provider(data, size); + OHOS::GetBatchDataFuzz(provider); + OHOS::GetSummaryFuzz(provider); + OHOS::QueryDataCommonFuzz(provider); + OHOS::RetrieveDataFuzz(provider); + return 0; +} \ No newline at end of file diff --git a/services/distributeddataservice/service/test/fuzztest/udmfservicedata_fuzzer/udmfservicedata_fuzzer.h b/services/distributeddataservice/service/test/fuzztest/udmfservicedata_fuzzer/udmfservicedata_fuzzer.h new file mode 100644 index 0000000000000000000000000000000000000000..43b88b98b53b838078233240501984f2e562bde7 --- /dev/null +++ b/services/distributeddataservice/service/test/fuzztest/udmfservicedata_fuzzer/udmfservicedata_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 UDMF_SERVICE_DATA_FUZZER_H +#define UDMF_SERVICE_DATA_FUZZER_H + +#define FUZZ_PROJECT_NAME "udmfservicedata_fuzzer" + +#endif // UDMF_SERVICE_DATA_FUZZER_H \ No newline at end of file diff --git a/services/distributeddataservice/service/test/fuzztest/udmfservicedatamanager_fuzzer/BUILD.gn b/services/distributeddataservice/service/test/fuzztest/udmfservicedatamanager_fuzzer/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..4d234951b594e56256cf59f5bfa3f51ef54357c5 --- /dev/null +++ b/services/distributeddataservice/service/test/fuzztest/udmfservicedatamanager_fuzzer/BUILD.gn @@ -0,0 +1,80 @@ +# 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("UdmfServiceDataManagerFuzzTest") { + module_out_path = "datamgr_service/datamgr_service" + + include_dirs = [ + "${data_service_path}/framework/include", + "${data_service_path}/service/matrix/include", + "${data_service_path}/service/udmf/lifecycle", + "${data_service_path}/service/udmf/permission", + "${data_service_path}/service/udmf/preprocess", + "${data_service_path}/service/udmf/store", + "${data_service_path}/service/udmf", + ] + + fuzz_config_file = + "${data_service_path}/service/test/fuzztest/udmfservicedatamanager_fuzzer" + + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + "-fno-access-control" + ] + + sources = [ "udmfservicedatamanager_fuzzer.cpp" ] + + deps = [ + "${data_service_path}/adapter/account:distributeddata_account", + "${data_service_path}/adapter/communicator:distributeddata_communicator", + "${data_service_path}/adapter/dfx:distributeddata_dfx", + "${data_service_path}/framework:distributeddatasvcfwk", + "${data_service_path}/service/bootstrap:distributeddata_bootstrap", + "${data_service_path}/service/matrix:distributeddata_matrix", + "${data_service_path}/service/udmf:udmf_server", + ] + + external_deps = [ + "ability_base:zuri", + "ability_runtime:uri_permission_mgr", + "access_token:libaccesstoken_sdk", + "access_token:libtoken_setproc", + "bundle_framework:appexecfwk_base", + "bundle_framework:appexecfwk_core", + "c_utils:utils", + "hilog:libhilog", + "hisysevent:libhisysevent", + "ipc:ipc_core", + "kv_store:distributeddata_inner", + "kv_store:distributeddata_mgr", + "kv_store:distributeddb", + "samgr:samgr_proxy", + "udmf:udmf_client", + ] +} + +############################################################################### +group("fuzztest") { + testonly = true + + deps = [ ":UdmfServiceDataManagerFuzzTest" ] +} +############################################################################### \ No newline at end of file diff --git a/services/distributeddataservice/service/test/fuzztest/udmfservicedatamanager_fuzzer/corpus/init b/services/distributeddataservice/service/test/fuzztest/udmfservicedatamanager_fuzzer/corpus/init new file mode 100644 index 0000000000000000000000000000000000000000..7ade8a0faafeaedba7241e7d4a97b8e1f9691932 --- /dev/null +++ b/services/distributeddataservice/service/test/fuzztest/udmfservicedatamanager_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/udmfservicedatamanager_fuzzer/project.xml b/services/distributeddataservice/service/test/fuzztest/udmfservicedatamanager_fuzzer/project.xml new file mode 100644 index 0000000000000000000000000000000000000000..a37a23b1533f07ab59744732b0f46b2b5fd958d8 --- /dev/null +++ b/services/distributeddataservice/service/test/fuzztest/udmfservicedatamanager_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + \ No newline at end of file diff --git a/services/distributeddataservice/service/test/fuzztest/udmfservicedatamanager_fuzzer/udmfservicedatamanager_fuzzer.cpp b/services/distributeddataservice/service/test/fuzztest/udmfservicedatamanager_fuzzer/udmfservicedatamanager_fuzzer.cpp new file mode 100644 index 0000000000000000000000000000000000000000..854cd57dfa0870842889a25ab178693823dd2bdf --- /dev/null +++ b/services/distributeddataservice/service/test/fuzztest/udmfservicedatamanager_fuzzer/udmfservicedatamanager_fuzzer.cpp @@ -0,0 +1,169 @@ +/* + * 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 "udmfservicedatamanager_fuzzer.h" + +#include "accesstoken_kit.h" +#include "distributeddata_udmf_ipc_interface_code.h" +#include "itypes_util.h" +#include "ipc_skeleton.h" +#include "message_parcel.h" +#include "securec.h" +#include "token_setproc.h" +#include "udmf_service_impl.h" +#include "udmf_types_util.h" + +using namespace OHOS::UDMF; + +namespace OHOS { +const std::u16string INTERFACE_TOKEN = u"OHOS.UDMF.UdmfService"; +constexpr size_t NUM_MIN = 5; +constexpr size_t NUM_MAX = 12; +static constexpr int ID_LEN = 32; +static constexpr int MINIMUM = 48; +static constexpr int MAXIMUM = 121; + +QueryOption GenerateFuzzQueryOption(FuzzedDataProvider &provider) +{ + std::vector groupId(ID_LEN, '0'); + for (size_t i = 0; i < groupId.size(); ++i) { + groupId[i] = provider.ConsumeIntegralInRange(MINIMUM, MAXIMUM); + } + std::string groupIdStr(groupId.begin(), groupId.end()); + UnifiedKey udKey = UnifiedKey("drag", "com.test.demo", groupIdStr); + QueryOption query; + query.key = udKey.GetUnifiedKey(); + query.intention = Intention::UD_INTENTION_DRAG; + query.tokenId = provider.ConsumeIntegral(); + return query; +} + +void SetDataFuzz(FuzzedDataProvider &provider) +{ + std::shared_ptr udmfServiceImpl = std::make_shared(); + std::shared_ptr executor = std::make_shared(NUM_MAX, NUM_MIN); + udmfServiceImpl->OnBind({ "UdmfServiceDataManagerFuzzTest", + static_cast(IPCSkeleton::GetSelfTokenID()), std::move(executor) }); + CustomOption option1 = {.intention = Intention::UD_INTENTION_DRAG}; + + std::string svalue = provider.ConsumeRandomLengthString(); + UnifiedData data1; + std::shared_ptr obj = std::make_shared(); + obj->value_[UNIFORM_DATA_TYPE] = "general.file-uri"; + obj->value_[FILE_URI_PARAM] = svalue; + obj->value_[FILE_TYPE] = provider.ConsumeRandomLengthString(); + auto record = std::make_shared(FILE_URI, obj); + data1.AddRecord(record); + MessageParcel request; + request.WriteInterfaceToken(INTERFACE_TOKEN); + ITypesUtil::Marshal(request, option1, data1); + MessageParcel reply; + udmfServiceImpl->OnRemoteRequest(static_cast(UdmfServiceInterfaceCode::SET_DATA), request, reply); + udmfServiceImpl->OnBind( + { "UdmfServiceDataManagerFuzzTest", static_cast(IPCSkeleton::GetSelfTokenID()), nullptr }); + executor = nullptr; +} + +void GetDataFuzz(FuzzedDataProvider &provider) +{ + std::shared_ptr udmfServiceImpl = std::make_shared(); + std::shared_ptr executor = std::make_shared(NUM_MAX, NUM_MIN); + udmfServiceImpl->OnBind({ "UdmfServiceDataManagerFuzzTest", + static_cast(IPCSkeleton::GetSelfTokenID()), std::move(executor) }); + QueryOption query = GenerateFuzzQueryOption(provider); + MessageParcel request; + request.WriteInterfaceToken(INTERFACE_TOKEN); + ITypesUtil::Marshal(request, query); + MessageParcel reply; + udmfServiceImpl->OnRemoteRequest(static_cast(UdmfServiceInterfaceCode::GET_DATA), request, reply); + udmfServiceImpl->OnBind( + { "UdmfServiceDataManagerFuzzTest", static_cast(IPCSkeleton::GetSelfTokenID()), nullptr }); + executor = nullptr; +} + +void UpdateDataFuzz(FuzzedDataProvider &provider) +{ + std::shared_ptr udmfServiceImpl = std::make_shared(); + std::shared_ptr executor = std::make_shared(NUM_MAX, NUM_MIN); + udmfServiceImpl->OnBind({ "UdmfServiceDataManagerFuzzTest", + static_cast(IPCSkeleton::GetSelfTokenID()), std::move(executor) }); + std::vector groupId(ID_LEN, '0'); + for (size_t i = 0; i < groupId.size(); ++i) { + groupId[i] = provider.ConsumeIntegralInRange(MINIMUM, MAXIMUM); + } + std::string groupIdStr(groupId.begin(), groupId.end()); + UnifiedKey udKey = UnifiedKey("DataHub", "com.test.demo", groupIdStr); + udKey.intention = Intention::UD_INTENTION_DATA_HUB; + QueryOption query; + query.key = udKey.GetUnifiedKey();\ + query.intention = Intention::UD_INTENTION_DATA_HUB; + query.tokenId = provider.ConsumeIntegral(); + std::string svalue = provider.ConsumeRandomLengthString(); + UnifiedData data1; + std::shared_ptr obj = std::make_shared(); + obj->value_[UNIFORM_DATA_TYPE] = "general.file-uri"; + obj->value_[FILE_URI_PARAM] = svalue; + obj->value_[FILE_TYPE] = provider.ConsumeRandomLengthString(); + auto record = std::make_shared(FILE_URI, obj); + data1.AddRecord(record); + MessageParcel request; + request.WriteInterfaceToken(INTERFACE_TOKEN); + ITypesUtil::Marshal(request, query, data1); + MessageParcel reply; + udmfServiceImpl->OnRemoteRequest(static_cast(UdmfServiceInterfaceCode::UPDATE_DATA), request, reply); + udmfServiceImpl->OnBind( + { "UdmfServiceDataManagerFuzzTest", static_cast(IPCSkeleton::GetSelfTokenID()), nullptr }); + executor = nullptr; +} + +void DeleteDataFuzz(FuzzedDataProvider &provider) +{ + std::shared_ptr udmfServiceImpl = std::make_shared(); + std::shared_ptr executor = std::make_shared(NUM_MAX, NUM_MIN); + udmfServiceImpl->OnBind({ "UdmfServiceDataManagerFuzzTest", + static_cast(IPCSkeleton::GetSelfTokenID()), std::move(executor) }); + QueryOption query = GenerateFuzzQueryOption(provider); + MessageParcel request; + request.WriteInterfaceToken(INTERFACE_TOKEN); + ITypesUtil::Marshal(request, query); + MessageParcel reply; + udmfServiceImpl->OnRemoteRequest(static_cast(UdmfServiceInterfaceCode::DELETE_DATA), request, reply); + udmfServiceImpl->OnBind( + { "UdmfServiceDataManagerFuzzTest", static_cast(IPCSkeleton::GetSelfTokenID()), nullptr }); + executor = nullptr; +} +} + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerInitialize(int *argc, char ***argv) +{ + OHOS::Security::AccessToken::AccessTokenID tokenId = + OHOS::Security::AccessToken::AccessTokenKit::GetHapTokenID(100, "com.ohos.dlpmanager", 0); + SetSelfTokenID(tokenId); + return 0; +} + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + FuzzedDataProvider provider(data, size); + OHOS::SetDataFuzz(provider); + OHOS::GetDataFuzz(provider); + OHOS::UpdateDataFuzz(provider); + OHOS::DeleteDataFuzz(provider); + return 0; +} \ No newline at end of file diff --git a/services/distributeddataservice/service/test/fuzztest/udmfservicedatamanager_fuzzer/udmfservicedatamanager_fuzzer.h b/services/distributeddataservice/service/test/fuzztest/udmfservicedatamanager_fuzzer/udmfservicedatamanager_fuzzer.h new file mode 100644 index 0000000000000000000000000000000000000000..5171605698edbcaaa78951d607f3181928d7a3e3 --- /dev/null +++ b/services/distributeddataservice/service/test/fuzztest/udmfservicedatamanager_fuzzer/udmfservicedatamanager_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 UDMF_SERVICE_DATA_MANAGER_FUZZER_H +#define UDMF_SERVICE_DATA_MANAGER_FUZZER_H + +#define FUZZ_PROJECT_NAME "udmfservicedatamanager_fuzzer" + +#endif // UDMF_SERVICE_DATA_MANAGER_FUZZER_H \ No newline at end of file diff --git a/services/distributeddataservice/service/test/fuzztest/udmfservicedelaydata_fuzzer/BUILD.gn b/services/distributeddataservice/service/test/fuzztest/udmfservicedelaydata_fuzzer/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..d4a298e6d6e9ed7fceaed33b8dee741e3b356bd9 --- /dev/null +++ b/services/distributeddataservice/service/test/fuzztest/udmfservicedelaydata_fuzzer/BUILD.gn @@ -0,0 +1,80 @@ +# 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("UdmfServiceDelayDataFuzzTest") { + module_out_path = "datamgr_service/datamgr_service" + + include_dirs = [ + "${data_service_path}/framework/include", + "${data_service_path}/service/matrix/include", + "${data_service_path}/service/udmf/lifecycle", + "${data_service_path}/service/udmf/permission", + "${data_service_path}/service/udmf/preprocess", + "${data_service_path}/service/udmf/store", + "${data_service_path}/service/udmf", + ] + + fuzz_config_file = + "${data_service_path}/service/test/fuzztest/udmfservicedelaydata_fuzzer" + + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + "-fno-access-control" + ] + + sources = [ "udmfservicedelaydata_fuzzer.cpp" ] + + deps = [ + "${data_service_path}/adapter/account:distributeddata_account", + "${data_service_path}/adapter/communicator:distributeddata_communicator", + "${data_service_path}/adapter/dfx:distributeddata_dfx", + "${data_service_path}/framework:distributeddatasvcfwk", + "${data_service_path}/service/bootstrap:distributeddata_bootstrap", + "${data_service_path}/service/matrix:distributeddata_matrix", + "${data_service_path}/service/udmf:udmf_server", + ] + + external_deps = [ + "ability_base:zuri", + "ability_runtime:uri_permission_mgr", + "access_token:libaccesstoken_sdk", + "access_token:libtoken_setproc", + "bundle_framework:appexecfwk_base", + "bundle_framework:appexecfwk_core", + "c_utils:utils", + "hilog:libhilog", + "hisysevent:libhisysevent", + "ipc:ipc_core", + "kv_store:distributeddata_inner", + "kv_store:distributeddata_mgr", + "kv_store:distributeddb", + "samgr:samgr_proxy", + "udmf:udmf_client", + ] +} + +############################################################################### +group("fuzztest") { + testonly = true + + deps = [ ":UdmfServiceDelayDataFuzzTest" ] +} +############################################################################### \ No newline at end of file diff --git a/services/distributeddataservice/service/test/fuzztest/udmfservicedelaydata_fuzzer/corpus/init b/services/distributeddataservice/service/test/fuzztest/udmfservicedelaydata_fuzzer/corpus/init new file mode 100644 index 0000000000000000000000000000000000000000..7ade8a0faafeaedba7241e7d4a97b8e1f9691932 --- /dev/null +++ b/services/distributeddataservice/service/test/fuzztest/udmfservicedelaydata_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/udmfservicedelaydata_fuzzer/project.xml b/services/distributeddataservice/service/test/fuzztest/udmfservicedelaydata_fuzzer/project.xml new file mode 100644 index 0000000000000000000000000000000000000000..a37a23b1533f07ab59744732b0f46b2b5fd958d8 --- /dev/null +++ b/services/distributeddataservice/service/test/fuzztest/udmfservicedelaydata_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + \ No newline at end of file diff --git a/services/distributeddataservice/service/test/fuzztest/udmfservicedelaydata_fuzzer/udmfservicedelaydata_fuzzer.cpp b/services/distributeddataservice/service/test/fuzztest/udmfservicedelaydata_fuzzer/udmfservicedelaydata_fuzzer.cpp new file mode 100644 index 0000000000000000000000000000000000000000..1a4471a0d068a32f5910b2f737b0ab24fc163714 --- /dev/null +++ b/services/distributeddataservice/service/test/fuzztest/udmfservicedelaydata_fuzzer/udmfservicedelaydata_fuzzer.cpp @@ -0,0 +1,167 @@ +/* + * 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 "udmfservicedelaydata_fuzzer.h" + +#include "accesstoken_kit.h" +#include "distributeddata_udmf_ipc_interface_code.h" +#include "itypes_util.h" +#include "ipc_skeleton.h" +#include "message_parcel.h" +#include "securec.h" +#include "token_setproc.h" +#include "udmf_service_impl.h" +#include "udmf_types_util.h" + +using namespace OHOS::UDMF; + +namespace OHOS { +const std::u16string INTERFACE_TOKEN = u"OHOS.UDMF.UdmfService"; +constexpr size_t NUM_MIN = 5; +constexpr size_t NUM_MAX = 12; +static constexpr int ID_LEN = 32; +static constexpr int MINIMUM = 48; +static constexpr int MAXIMUM = 121; + +QueryOption GenerateFuzzQueryOption(FuzzedDataProvider &provider) +{ + std::vector groupId(ID_LEN, '0'); + for (size_t i = 0; i < groupId.size(); ++i) { + groupId[i] = provider.ConsumeIntegralInRange(MINIMUM, MAXIMUM); + } + std::string groupIdStr(groupId.begin(), groupId.end()); + UnifiedKey udKey = UnifiedKey("drag", "com.test.demo", groupIdStr); + QueryOption query; + query.key = udKey.GetUnifiedKey(); + query.intention = Intention::UD_INTENTION_DRAG; + query.tokenId = provider.ConsumeIntegral(); + return query; +} + +void SetDelayInfoFuzz(FuzzedDataProvider &provider) +{ + std::shared_ptr udmfServiceImpl = std::make_shared(); + std::shared_ptr executor = std::make_shared(NUM_MAX, NUM_MIN); + udmfServiceImpl->OnBind( + { "UdmfServiceDelayDataFuzzTest", static_cast(IPCSkeleton::GetSelfTokenID()), std::move(executor) }); + MessageParcel requestUpdate; + requestUpdate.WriteInterfaceToken(INTERFACE_TOKEN); + DataLoadInfo dataLoadInfo; + dataLoadInfo.recordCount = provider.ConsumeIntegral(); + dataLoadInfo.types.emplace(provider.ConsumeRandomLengthString()); + dataLoadInfo.sequenceKey = provider.ConsumeRandomLengthString(); + ITypesUtil::Marshal(requestUpdate, dataLoadInfo); + sptr iUdmfNotifier = nullptr; + ITypesUtil::Marshal(requestUpdate, iUdmfNotifier); + MessageParcel replyUpdate; + udmfServiceImpl->OnRemoteRequest(static_cast(UdmfServiceInterfaceCode::SET_DELAY_INFO), + requestUpdate, replyUpdate); + udmfServiceImpl->OnBind( + { "UdmfServiceDelayDataFuzzTest", static_cast(IPCSkeleton::GetSelfTokenID()), nullptr }); + executor = nullptr; +} + +void PushDelayDataFuzz(FuzzedDataProvider &provider) +{ + std::shared_ptr udmfServiceImpl = std::make_shared(); + std::shared_ptr executor = std::make_shared(NUM_MAX, NUM_MIN); + udmfServiceImpl->OnBind( + { "UdmfServiceDelayDataFuzzTest", static_cast(IPCSkeleton::GetSelfTokenID()), std::move(executor) }); + + MessageParcel requestUpdate; + requestUpdate.WriteInterfaceToken(INTERFACE_TOKEN); + std::string key = provider.ConsumeRandomLengthString(); + ITypesUtil::Marshal(requestUpdate, key); + UnifiedData data; + std::shared_ptr obj = std::make_shared(); + obj->value_[UNIFORM_DATA_TYPE] = "general.file-uri"; + obj->value_[FILE_URI_PARAM] = provider.ConsumeRandomLengthString(); + obj->value_[FILE_TYPE] = provider.ConsumeRandomLengthString(); + auto record = std::make_shared(FILE_URI, obj); + data.AddRecord(record); + ITypesUtil::Marshal(requestUpdate, data); + + MessageParcel replyUpdate; + udmfServiceImpl->OnRemoteRequest(static_cast(UdmfServiceInterfaceCode::SET_DELAY_DATA), + requestUpdate, replyUpdate); + udmfServiceImpl->OnBind( + { "UdmfServiceDelayDataFuzzTest", static_cast(IPCSkeleton::GetSelfTokenID()), nullptr }); + executor = nullptr; +} + +void GetDataIfAvailableFuzz(FuzzedDataProvider &provider) +{ + std::shared_ptr udmfServiceImpl = std::make_shared(); + std::shared_ptr executor = std::make_shared(NUM_MAX, NUM_MIN); + udmfServiceImpl->OnBind( + { "UdmfServiceDelayDataFuzzTest", static_cast(IPCSkeleton::GetSelfTokenID()), std::move(executor) }); + + MessageParcel requestUpdate; + requestUpdate.WriteInterfaceToken(INTERFACE_TOKEN); + std::string key = provider.ConsumeRandomLengthString(); + ITypesUtil::Marshal(requestUpdate, key); + DataLoadInfo dataLoadInfo; + dataLoadInfo.recordCount = provider.ConsumeIntegral(); + dataLoadInfo.types.emplace(provider.ConsumeRandomLengthString()); + dataLoadInfo.sequenceKey = provider.ConsumeRandomLengthString(); + ITypesUtil::Marshal(requestUpdate, dataLoadInfo); + sptr iUdmfNotifier = nullptr; + ITypesUtil::Marshal(requestUpdate, iUdmfNotifier); + + MessageParcel replyUpdate; + udmfServiceImpl->OnRemoteRequest(static_cast(UdmfServiceInterfaceCode::GET_DELAY_DATA), + requestUpdate, replyUpdate); + udmfServiceImpl->OnBind( + { "UdmfServiceDelayDataFuzzTest", static_cast(IPCSkeleton::GetSelfTokenID()), nullptr }); + executor = nullptr; +} + +void HandleDelayDataCallbackFuzz(FuzzedDataProvider &provider) +{ + std::shared_ptr udmfServiceImpl = std::make_shared(); + DelayGetDataInfo delayGetDataInfo; + UnifiedData unifiedData; + std::shared_ptr obj = std::make_shared(); + obj->value_[UNIFORM_DATA_TYPE] = "general.file-uri"; + obj->value_[FILE_URI_PARAM] = provider.ConsumeRandomLengthString(); + obj->value_[FILE_TYPE] = provider.ConsumeRandomLengthString(); + auto record = std::make_shared(FILE_URI, obj); + unifiedData.AddRecord(record); + std::string key = provider.ConsumeRandomLengthString(); + udmfServiceImpl->HandleDelayDataCallback(delayGetDataInfo, unifiedData, key); +} +} + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerInitialize(int *argc, char ***argv) +{ + OHOS::Security::AccessToken::AccessTokenID tokenId = + OHOS::Security::AccessToken::AccessTokenKit::GetHapTokenID(100, "com.ohos.dlpmanager", 0); + SetSelfTokenID(tokenId); + return 0; +} + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + FuzzedDataProvider provider(data, size); + OHOS::SetDelayInfoFuzz(provider); + OHOS::PushDelayDataFuzz(provider); + OHOS::GetDataIfAvailableFuzz(provider); + OHOS::HandleDelayDataCallbackFuzz(provider); + return 0; +} \ No newline at end of file diff --git a/services/distributeddataservice/service/test/fuzztest/udmfservicedelaydata_fuzzer/udmfservicedelaydata_fuzzer.h b/services/distributeddataservice/service/test/fuzztest/udmfservicedelaydata_fuzzer/udmfservicedelaydata_fuzzer.h new file mode 100644 index 0000000000000000000000000000000000000000..d59a57967c1ef3c8527cc747aad13ec34218b259 --- /dev/null +++ b/services/distributeddataservice/service/test/fuzztest/udmfservicedelaydata_fuzzer/udmfservicedelaydata_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 UDMF_SERVICE_DELAY_DATA_FUZZER_H +#define UDMF_SERVICE_DELAY_DATA_FUZZER_H + +#define FUZZ_PROJECT_NAME "udmfservicedelaydata_fuzzer" + +#endif // UDMF_SERVICE_DELAY_DATA_FUZZER_H \ No newline at end of file diff --git a/services/distributeddataservice/service/test/fuzztest/udmfservicehandleappshareoption_fuzzer/BUILD.gn b/services/distributeddataservice/service/test/fuzztest/udmfservicehandleappshareoption_fuzzer/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..9b3262783ff374bcdf5614df3f293ded53e2a465 --- /dev/null +++ b/services/distributeddataservice/service/test/fuzztest/udmfservicehandleappshareoption_fuzzer/BUILD.gn @@ -0,0 +1,80 @@ +# 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("UdmfServiceHandleAppShareOptionFuzzTest") { + module_out_path = "datamgr_service/datamgr_service" + + include_dirs = [ + "${data_service_path}/framework/include", + "${data_service_path}/service/matrix/include", + "${data_service_path}/service/udmf/lifecycle", + "${data_service_path}/service/udmf/permission", + "${data_service_path}/service/udmf/preprocess", + "${data_service_path}/service/udmf/store", + "${data_service_path}/service/udmf", + ] + + fuzz_config_file = + "${data_service_path}/service/test/fuzztest/udmfservicehandleappshareoption_fuzzer" + + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + "-fno-access-control" + ] + + sources = [ "udmfservicehandleappshareoption_fuzzer.cpp" ] + + deps = [ + "${data_service_path}/adapter/account:distributeddata_account", + "${data_service_path}/adapter/communicator:distributeddata_communicator", + "${data_service_path}/adapter/dfx:distributeddata_dfx", + "${data_service_path}/framework:distributeddatasvcfwk", + "${data_service_path}/service/bootstrap:distributeddata_bootstrap", + "${data_service_path}/service/matrix:distributeddata_matrix", + "${data_service_path}/service/udmf:udmf_server", + ] + + external_deps = [ + "ability_base:zuri", + "ability_runtime:uri_permission_mgr", + "access_token:libaccesstoken_sdk", + "access_token:libtoken_setproc", + "bundle_framework:appexecfwk_base", + "bundle_framework:appexecfwk_core", + "c_utils:utils", + "hilog:libhilog", + "hisysevent:libhisysevent", + "ipc:ipc_core", + "kv_store:distributeddata_inner", + "kv_store:distributeddata_mgr", + "kv_store:distributeddb", + "samgr:samgr_proxy", + "udmf:udmf_client", + ] +} + +############################################################################### +group("fuzztest") { + testonly = true + + deps = [ ":UdmfServiceHandleAppShareOptionFuzzTest" ] +} +############################################################################### \ No newline at end of file diff --git a/services/distributeddataservice/service/test/fuzztest/udmfservicehandleappshareoption_fuzzer/corpus/init b/services/distributeddataservice/service/test/fuzztest/udmfservicehandleappshareoption_fuzzer/corpus/init new file mode 100644 index 0000000000000000000000000000000000000000..7ade8a0faafeaedba7241e7d4a97b8e1f9691932 --- /dev/null +++ b/services/distributeddataservice/service/test/fuzztest/udmfservicehandleappshareoption_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/udmfservicehandleappshareoption_fuzzer/project.xml b/services/distributeddataservice/service/test/fuzztest/udmfservicehandleappshareoption_fuzzer/project.xml new file mode 100644 index 0000000000000000000000000000000000000000..a37a23b1533f07ab59744732b0f46b2b5fd958d8 --- /dev/null +++ b/services/distributeddataservice/service/test/fuzztest/udmfservicehandleappshareoption_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + \ No newline at end of file diff --git a/services/distributeddataservice/service/test/fuzztest/udmfservicehandleappshareoption_fuzzer/udmfservicehandleappshareoption_fuzzer.cpp b/services/distributeddataservice/service/test/fuzztest/udmfservicehandleappshareoption_fuzzer/udmfservicehandleappshareoption_fuzzer.cpp new file mode 100644 index 0000000000000000000000000000000000000000..03f34bce55bc5ba5ed577f3811d86ead8e8caac1 --- /dev/null +++ b/services/distributeddataservice/service/test/fuzztest/udmfservicehandleappshareoption_fuzzer/udmfservicehandleappshareoption_fuzzer.cpp @@ -0,0 +1,128 @@ +/* + * 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 "udmfservicehandleappshareoption_fuzzer.h" + +#include "accesstoken_kit.h" +#include "distributeddata_udmf_ipc_interface_code.h" +#include "itypes_util.h" +#include "ipc_skeleton.h" +#include "message_parcel.h" +#include "securec.h" +#include "token_setproc.h" +#include "udmf_service_impl.h" +#include "udmf_types_util.h" + +using namespace OHOS::UDMF; + +namespace OHOS { +const std::u16string INTERFACE_TOKEN = u"OHOS.UDMF.UdmfService"; +constexpr size_t NUM_MIN = 5; +constexpr size_t NUM_MAX = 12; + +void OnGetAppShareOptionFuzz(FuzzedDataProvider &provider) +{ + std::shared_ptr udmfServiceImpl = std::make_shared(); + std::shared_ptr executor = std::make_shared(NUM_MAX, NUM_MIN); + udmfServiceImpl->OnBind({ "UdmfServiceHandleAppShareOptionFuzzTest", + static_cast(IPCSkeleton::GetSelfTokenID()), std::move(executor) }); + + MessageParcel requestUpdate; + std::vector remainingData = provider.ConsumeRemainingBytes(); + requestUpdate.WriteInterfaceToken(INTERFACE_TOKEN); + requestUpdate.WriteBuffer(static_cast(remainingData.data()), remainingData.size()); + requestUpdate.RewindRead(0); + CustomOption option = {.intention = Intention::UD_INTENTION_DRAG}; + std::string intention = UD_INTENTION_MAP.at(option.intention); + ITypesUtil::Marshal(requestUpdate, intention); + + MessageParcel replyUpdate; + udmfServiceImpl->OnRemoteRequest(static_cast(UdmfServiceInterfaceCode::GET_APP_SHARE_OPTION), + requestUpdate, replyUpdate); + udmfServiceImpl->OnBind( + { "UdmfServiceHandleAppShareOptionFuzzTest", static_cast(IPCSkeleton::GetSelfTokenID()), nullptr }); + executor = nullptr; +} + +void SetAppShareOptionFuzz(FuzzedDataProvider &provider) +{ + std::shared_ptr udmfServiceImpl = std::make_shared(); + std::shared_ptr executor = std::make_shared(NUM_MAX, NUM_MIN); + udmfServiceImpl->OnBind({ "UdmfServiceHandleAppShareOptionFuzzTest", + static_cast(IPCSkeleton::GetSelfTokenID()), std::move(executor) }); + + MessageParcel requestUpdate; + std::vector remainingData = provider.ConsumeRemainingBytes(); + requestUpdate.WriteInterfaceToken(INTERFACE_TOKEN); + requestUpdate.WriteBuffer(static_cast(remainingData.data()), remainingData.size()); + requestUpdate.RewindRead(0); + CustomOption option = {.intention = Intention::UD_INTENTION_DRAG}; + std::string intention = UD_INTENTION_MAP.at(option.intention); + int32_t shareOption = provider.ConsumeIntegral(); + ITypesUtil::Marshal(requestUpdate, intention, shareOption); + + MessageParcel replyUpdate; + udmfServiceImpl->OnRemoteRequest(static_cast(UdmfServiceInterfaceCode::SET_APP_SHARE_OPTION), + requestUpdate, replyUpdate); + udmfServiceImpl->OnBind( + { "UdmfServiceHandleAppShareOptionFuzzTest", static_cast(IPCSkeleton::GetSelfTokenID()), nullptr }); + executor = nullptr; +} + +void RemoveAppShareOptionFuzz(FuzzedDataProvider &provider) +{ + std::shared_ptr udmfServiceImpl = std::make_shared(); + std::shared_ptr executor = std::make_shared(NUM_MAX, NUM_MIN); + udmfServiceImpl->OnBind({ "UdmfServiceHandleAppShareOptionFuzzTest", + static_cast(IPCSkeleton::GetSelfTokenID()), std::move(executor) }); + + MessageParcel requestUpdate; + std::vector remainingData = provider.ConsumeRemainingBytes(); + requestUpdate.WriteInterfaceToken(INTERFACE_TOKEN); + requestUpdate.WriteBuffer(static_cast(remainingData.data()), remainingData.size()); + requestUpdate.RewindRead(0); + CustomOption option = {.intention = Intention::UD_INTENTION_DRAG}; + std::string intention = UD_INTENTION_MAP.at(option.intention); + ITypesUtil::Marshal(requestUpdate, intention); + + MessageParcel replyUpdate; + udmfServiceImpl->OnRemoteRequest(static_cast(UdmfServiceInterfaceCode::REMOVE_APP_SHARE_OPTION), + requestUpdate, replyUpdate); + udmfServiceImpl->OnBind( + { "UdmfServiceHandleAppShareOptionFuzzTest", static_cast(IPCSkeleton::GetSelfTokenID()), nullptr }); + executor = nullptr; +} +} + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerInitialize(int *argc, char ***argv) +{ + OHOS::Security::AccessToken::AccessTokenID tokenId = + OHOS::Security::AccessToken::AccessTokenKit::GetHapTokenID(100, "com.ohos.dlpmanager", 0); + SetSelfTokenID(tokenId); + return 0; +} + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + FuzzedDataProvider provider(data, size); + OHOS::OnGetAppShareOptionFuzz(provider); + OHOS::SetAppShareOptionFuzz(provider); + OHOS::RemoveAppShareOptionFuzz(provider); + return 0; +} \ No newline at end of file diff --git a/services/distributeddataservice/service/test/fuzztest/udmfservicehandleappshareoption_fuzzer/udmfservicehandleappshareoption_fuzzer.h b/services/distributeddataservice/service/test/fuzztest/udmfservicehandleappshareoption_fuzzer/udmfservicehandleappshareoption_fuzzer.h new file mode 100644 index 0000000000000000000000000000000000000000..a223885e2267fbc7caaacdca5295a98400c22870 --- /dev/null +++ b/services/distributeddataservice/service/test/fuzztest/udmfservicehandleappshareoption_fuzzer/udmfservicehandleappshareoption_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 UDMF_SERVICE_HANDLE_APP_SHAREOPTION_FUZZER_H +#define UDMF_SERVICE_HANDLE_APP_SHAREOPTION_FUZZER_H + +#define FUZZ_PROJECT_NAME "UdmfServiceHandleAppShareOptionFuzzTest" + +#endif // UDMF_SERVICE_HANDLE_APP_SHAREOPTION_FUZZER_H \ No newline at end of file diff --git a/services/distributeddataservice/service/test/fuzztest/udmfservicehandledbstatus_fuzzer/BUILD.gn b/services/distributeddataservice/service/test/fuzztest/udmfservicehandledbstatus_fuzzer/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..d16750b838559e43a4f2c09de3b0777cca4af863 --- /dev/null +++ b/services/distributeddataservice/service/test/fuzztest/udmfservicehandledbstatus_fuzzer/BUILD.gn @@ -0,0 +1,80 @@ +# 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("UdmfServiceHandleDbStatusFuzzTest") { + module_out_path = "datamgr_service/datamgr_service" + + include_dirs = [ + "${data_service_path}/framework/include", + "${data_service_path}/service/matrix/include", + "${data_service_path}/service/udmf/lifecycle", + "${data_service_path}/service/udmf/permission", + "${data_service_path}/service/udmf/preprocess", + "${data_service_path}/service/udmf/store", + "${data_service_path}/service/udmf", + ] + + fuzz_config_file = + "${data_service_path}/service/test/fuzztest/udmfservicehandledbstatus_fuzzer" + + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + "-fno-access-control" + ] + + sources = [ "udmfservicehandledbstatus_fuzzer.cpp" ] + + deps = [ + "${data_service_path}/adapter/account:distributeddata_account", + "${data_service_path}/adapter/communicator:distributeddata_communicator", + "${data_service_path}/adapter/dfx:distributeddata_dfx", + "${data_service_path}/framework:distributeddatasvcfwk", + "${data_service_path}/service/bootstrap:distributeddata_bootstrap", + "${data_service_path}/service/matrix:distributeddata_matrix", + "${data_service_path}/service/udmf:udmf_server", + ] + + external_deps = [ + "ability_base:zuri", + "ability_runtime:uri_permission_mgr", + "access_token:libaccesstoken_sdk", + "access_token:libtoken_setproc", + "bundle_framework:appexecfwk_base", + "bundle_framework:appexecfwk_core", + "c_utils:utils", + "hilog:libhilog", + "hisysevent:libhisysevent", + "ipc:ipc_core", + "kv_store:distributeddata_inner", + "kv_store:distributeddata_mgr", + "kv_store:distributeddb", + "samgr:samgr_proxy", + "udmf:udmf_client", + ] +} + +############################################################################### +group("fuzztest") { + testonly = true + + deps = [ ":UdmfServiceHandleDbStatusFuzzTest" ] +} +############################################################################### \ No newline at end of file diff --git a/services/distributeddataservice/service/test/fuzztest/udmfservicehandledbstatus_fuzzer/corpus/init b/services/distributeddataservice/service/test/fuzztest/udmfservicehandledbstatus_fuzzer/corpus/init new file mode 100644 index 0000000000000000000000000000000000000000..7ade8a0faafeaedba7241e7d4a97b8e1f9691932 --- /dev/null +++ b/services/distributeddataservice/service/test/fuzztest/udmfservicehandledbstatus_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/udmfservicehandledbstatus_fuzzer/project.xml b/services/distributeddataservice/service/test/fuzztest/udmfservicehandledbstatus_fuzzer/project.xml new file mode 100644 index 0000000000000000000000000000000000000000..a37a23b1533f07ab59744732b0f46b2b5fd958d8 --- /dev/null +++ b/services/distributeddataservice/service/test/fuzztest/udmfservicehandledbstatus_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + \ No newline at end of file diff --git a/services/distributeddataservice/service/test/fuzztest/udmfservicehandledbstatus_fuzzer/udmfservicehandledbstatus_fuzzer.cpp b/services/distributeddataservice/service/test/fuzztest/udmfservicehandledbstatus_fuzzer/udmfservicehandledbstatus_fuzzer.cpp new file mode 100644 index 0000000000000000000000000000000000000000..5380bf446bd405b17317e7b186b55975f081b92b --- /dev/null +++ b/services/distributeddataservice/service/test/fuzztest/udmfservicehandledbstatus_fuzzer/udmfservicehandledbstatus_fuzzer.cpp @@ -0,0 +1,67 @@ +/* + * 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 "udmfservicehandledbstatus_fuzzer.h" + +#include "accesstoken_kit.h" +#include "distributeddata_udmf_ipc_interface_code.h" +#include "itypes_util.h" +#include "ipc_skeleton.h" +#include "message_parcel.h" +#include "securec.h" +#include "token_setproc.h" +#include "udmf_service_impl.h" +#include "udmf_types_util.h" + +using namespace OHOS::UDMF; + +namespace OHOS { + +void CloseStoreWhenCorruptedFuzz(FuzzedDataProvider &provider) +{ + std::shared_ptr udmfServiceImpl = std::make_shared(); + std::string intention = provider.ConsumeRandomLengthString(); + int32_t status = provider.ConsumeIntegral(); + udmfServiceImpl->CloseStoreWhenCorrupted(intention, status); +} + +void HandleDbErrorFuzz(FuzzedDataProvider &provider) +{ + std::shared_ptr udmfServiceImpl = std::make_shared(); + std::string intention = provider.ConsumeRandomLengthString(); + int32_t status = provider.ConsumeIntegral(); + udmfServiceImpl->HandleDbError(intention, status); +} +} + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerInitialize(int *argc, char ***argv) +{ + OHOS::Security::AccessToken::AccessTokenID tokenId = + OHOS::Security::AccessToken::AccessTokenKit::GetHapTokenID(100, "com.ohos.dlpmanager", 0); + SetSelfTokenID(tokenId); + return 0; +} + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + FuzzedDataProvider provider(data, size); + OHOS::CloseStoreWhenCorruptedFuzz(provider); + OHOS::HandleDbErrorFuzz(provider); + return 0; +} \ No newline at end of file diff --git a/services/distributeddataservice/service/test/fuzztest/udmfservicehandledbstatus_fuzzer/udmfservicehandledbstatus_fuzzer.h b/services/distributeddataservice/service/test/fuzztest/udmfservicehandledbstatus_fuzzer/udmfservicehandledbstatus_fuzzer.h new file mode 100644 index 0000000000000000000000000000000000000000..8f091f52088bb311cfa03dff5ea719e45a8ff2af --- /dev/null +++ b/services/distributeddataservice/service/test/fuzztest/udmfservicehandledbstatus_fuzzer/udmfservicehandledbstatus_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 UDMF_SERVICE_HANDLE_DB_STATUS_FUZZER_H +#define UDMF_SERVICE_HANDLE_DB_STATUS_FUZZER_H + +#define FUZZ_PROJECT_NAME "udmfservicehandledbstatus_fuzzer" + +#endif // UDMF_SERVICE_HANDLE_DB_STATUS_FUZZER_H \ No newline at end of file diff --git a/services/distributeddataservice/service/test/fuzztest/udmfserviceprivilege_fuzzer/BUILD.gn b/services/distributeddataservice/service/test/fuzztest/udmfserviceprivilege_fuzzer/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..49f6e37962c9c08ea104d5a3fca4be92251daa08 --- /dev/null +++ b/services/distributeddataservice/service/test/fuzztest/udmfserviceprivilege_fuzzer/BUILD.gn @@ -0,0 +1,80 @@ +# 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("UdmfServicePrivilegeFuzzTest") { + module_out_path = "datamgr_service/datamgr_service" + + include_dirs = [ + "${data_service_path}/framework/include", + "${data_service_path}/service/matrix/include", + "${data_service_path}/service/udmf/lifecycle", + "${data_service_path}/service/udmf/permission", + "${data_service_path}/service/udmf/preprocess", + "${data_service_path}/service/udmf/store", + "${data_service_path}/service/udmf", + ] + + fuzz_config_file = + "${data_service_path}/service/test/fuzztest/udmfserviceprivilege_fuzzer" + + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + "-fno-access-control" + ] + + sources = [ "udmfserviceprivilege_fuzzer.cpp" ] + + deps = [ + "${data_service_path}/adapter/account:distributeddata_account", + "${data_service_path}/adapter/communicator:distributeddata_communicator", + "${data_service_path}/adapter/dfx:distributeddata_dfx", + "${data_service_path}/framework:distributeddatasvcfwk", + "${data_service_path}/service/bootstrap:distributeddata_bootstrap", + "${data_service_path}/service/matrix:distributeddata_matrix", + "${data_service_path}/service/udmf:udmf_server", + ] + + external_deps = [ + "ability_base:zuri", + "ability_runtime:uri_permission_mgr", + "access_token:libaccesstoken_sdk", + "access_token:libtoken_setproc", + "bundle_framework:appexecfwk_base", + "bundle_framework:appexecfwk_core", + "c_utils:utils", + "hilog:libhilog", + "hisysevent:libhisysevent", + "ipc:ipc_core", + "kv_store:distributeddata_inner", + "kv_store:distributeddata_mgr", + "kv_store:distributeddb", + "samgr:samgr_proxy", + "udmf:udmf_client", + ] +} + +############################################################################### +group("fuzztest") { + testonly = true + + deps = [ ":UdmfServicePrivilegeFuzzTest" ] +} +############################################################################### \ No newline at end of file diff --git a/services/distributeddataservice/service/test/fuzztest/udmfserviceprivilege_fuzzer/corpus/init b/services/distributeddataservice/service/test/fuzztest/udmfserviceprivilege_fuzzer/corpus/init new file mode 100644 index 0000000000000000000000000000000000000000..7ade8a0faafeaedba7241e7d4a97b8e1f9691932 --- /dev/null +++ b/services/distributeddataservice/service/test/fuzztest/udmfserviceprivilege_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/udmfserviceprivilege_fuzzer/project.xml b/services/distributeddataservice/service/test/fuzztest/udmfserviceprivilege_fuzzer/project.xml new file mode 100644 index 0000000000000000000000000000000000000000..a37a23b1533f07ab59744732b0f46b2b5fd958d8 --- /dev/null +++ b/services/distributeddataservice/service/test/fuzztest/udmfserviceprivilege_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + \ No newline at end of file diff --git a/services/distributeddataservice/service/test/fuzztest/udmfserviceprivilege_fuzzer/udmfserviceprivilege_fuzzer.cpp b/services/distributeddataservice/service/test/fuzztest/udmfserviceprivilege_fuzzer/udmfserviceprivilege_fuzzer.cpp new file mode 100644 index 0000000000000000000000000000000000000000..4405507be3b1c092548416e5a09fadbf20b02ff3 --- /dev/null +++ b/services/distributeddataservice/service/test/fuzztest/udmfserviceprivilege_fuzzer/udmfserviceprivilege_fuzzer.cpp @@ -0,0 +1,122 @@ +/* + * 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 "udmfserviceprivilege_fuzzer.h" + +#include "accesstoken_kit.h" +#include "distributeddata_udmf_ipc_interface_code.h" +#include "itypes_util.h" +#include "ipc_skeleton.h" +#include "message_parcel.h" +#include "securec.h" +#include "token_setproc.h" +#include "udmf_service_impl.h" +#include "udmf_types_util.h" + +using namespace OHOS::UDMF; + +namespace OHOS { +const std::u16string INTERFACE_TOKEN = u"OHOS.UDMF.UdmfService"; +constexpr size_t NUM_MIN = 5; +constexpr size_t NUM_MAX = 12; +static constexpr int ID_LEN = 32; +static constexpr int MINIMUM = 48; +static constexpr int MAXIMUM = 121; + +QueryOption GenerateFuzzQueryOption(FuzzedDataProvider &provider) +{ + std::vector groupId(ID_LEN, '0'); + for (size_t i = 0; i < groupId.size(); ++i) { + groupId[i] = provider.ConsumeIntegralInRange(MINIMUM, MAXIMUM); + } + std::string groupIdStr(groupId.begin(), groupId.end()); + UnifiedKey udKey = UnifiedKey("drag", "com.test.demo", groupIdStr); + QueryOption query; + query.key = udKey.GetUnifiedKey(); + query.intention = Intention::UD_INTENTION_DRAG; + query.tokenId = provider.ConsumeIntegral(); + return query; +} + +void AddPrivilegeDataFuzz(FuzzedDataProvider &provider) +{ + std::shared_ptr udmfServiceImpl = std::make_shared(); + std::shared_ptr executor = std::make_shared(NUM_MAX, NUM_MIN); + udmfServiceImpl->OnBind( + { "UdmfServicePrivilegeFuzzTest", static_cast(IPCSkeleton::GetSelfTokenID()), std::move(executor) }); + QueryOption query = GenerateFuzzQueryOption(provider); + + Privilege privilege; + privilege.tokenId = 1; + privilege.readPermission = "read"; + privilege.writePermission = "write"; + + MessageParcel request; + request.WriteInterfaceToken(INTERFACE_TOKEN); + ITypesUtil::Marshal(request, query, privilege); + MessageParcel replyUpdate; + udmfServiceImpl->OnRemoteRequest(static_cast(UdmfServiceInterfaceCode::ADD_PRIVILEGE), + request, replyUpdate); + udmfServiceImpl->OnBind( + { "UdmfServicePrivilegeFuzzTest", static_cast(IPCSkeleton::GetSelfTokenID()), nullptr }); + executor = nullptr; +} + +void IsReadAndKeepFuzz(FuzzedDataProvider &provider) +{ + std::shared_ptr udmfServiceImpl = std::make_shared(); + Privilege privilege; + privilege.tokenId = provider.ConsumeIntegral(); + privilege.readPermission = "read"; + privilege.writePermission = "write"; + Privilege privilege2; + privilege2.tokenId = provider.ConsumeIntegral(); + privilege2.readPermission = "readAndKeep"; + privilege2.writePermission = "write"; + std::vector privileges1 = { privilege, privilege2 }; + QueryOption query = GenerateFuzzQueryOption(provider); + udmfServiceImpl->IsReadAndKeep(privileges1, query); + std::vector privileges2 = { privilege }; + udmfServiceImpl->IsReadAndKeep(privileges2, query); +} + +void HasDatahubPriviledgeFuzz(FuzzedDataProvider &provider) +{ + std::shared_ptr udmfServiceImpl = std::make_shared(); + auto bundleName = provider.ConsumeRandomLengthString(); + udmfServiceImpl->HasDatahubPriviledge(bundleName); +} +} + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerInitialize(int *argc, char ***argv) +{ + OHOS::Security::AccessToken::AccessTokenID tokenId = + OHOS::Security::AccessToken::AccessTokenKit::GetHapTokenID(100, "com.ohos.dlpmanager", 0); + SetSelfTokenID(tokenId); + return 0; +} + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + FuzzedDataProvider provider(data, size); + OHOS::AddPrivilegeDataFuzz(provider); + OHOS::IsReadAndKeepFuzz(provider); + OHOS::HasDatahubPriviledgeFuzz(provider); + return 0; +} \ No newline at end of file diff --git a/services/distributeddataservice/service/test/fuzztest/udmfserviceprivilege_fuzzer/udmfserviceprivilege_fuzzer.h b/services/distributeddataservice/service/test/fuzztest/udmfserviceprivilege_fuzzer/udmfserviceprivilege_fuzzer.h new file mode 100644 index 0000000000000000000000000000000000000000..1e812c56cd23b5a9dc19128a5054ca8013ad8c58 --- /dev/null +++ b/services/distributeddataservice/service/test/fuzztest/udmfserviceprivilege_fuzzer/udmfserviceprivilege_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 UDMF_SERVICE_PRIVILEGE_FUZZER_H +#define UDMF_SERVICE_PRIVILEGE_FUZZER_H + +#define FUZZ_PROJECT_NAME "udmfserviceprivilege_fuzzer" + +#endif // UDMF_SERVICE_PRIVILEGE_FUZZER_H \ No newline at end of file diff --git a/services/distributeddataservice/service/test/fuzztest/udmfserviceprocessdata_fuzzer/BUILD.gn b/services/distributeddataservice/service/test/fuzztest/udmfserviceprocessdata_fuzzer/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..f885101a2887afd7d8f920529e06246e01d34b73 --- /dev/null +++ b/services/distributeddataservice/service/test/fuzztest/udmfserviceprocessdata_fuzzer/BUILD.gn @@ -0,0 +1,80 @@ +# 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("UdmfServiceProcessDataFuzzTest") { + module_out_path = "datamgr_service/datamgr_service" + + include_dirs = [ + "${data_service_path}/framework/include", + "${data_service_path}/service/matrix/include", + "${data_service_path}/service/udmf/lifecycle", + "${data_service_path}/service/udmf/permission", + "${data_service_path}/service/udmf/preprocess", + "${data_service_path}/service/udmf/store", + "${data_service_path}/service/udmf", + ] + + fuzz_config_file = + "${data_service_path}/service/test/fuzztest/udmfserviceprocessdata_fuzzer" + + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + "-fno-access-control" + ] + + sources = [ "udmfserviceprocessdata_fuzzer.cpp" ] + + deps = [ + "${data_service_path}/adapter/account:distributeddata_account", + "${data_service_path}/adapter/communicator:distributeddata_communicator", + "${data_service_path}/adapter/dfx:distributeddata_dfx", + "${data_service_path}/framework:distributeddatasvcfwk", + "${data_service_path}/service/bootstrap:distributeddata_bootstrap", + "${data_service_path}/service/matrix:distributeddata_matrix", + "${data_service_path}/service/udmf:udmf_server", + ] + + external_deps = [ + "ability_base:zuri", + "ability_runtime:uri_permission_mgr", + "access_token:libaccesstoken_sdk", + "access_token:libtoken_setproc", + "bundle_framework:appexecfwk_base", + "bundle_framework:appexecfwk_core", + "c_utils:utils", + "hilog:libhilog", + "hisysevent:libhisysevent", + "ipc:ipc_core", + "kv_store:distributeddata_inner", + "kv_store:distributeddata_mgr", + "kv_store:distributeddb", + "samgr:samgr_proxy", + "udmf:udmf_client", + ] +} + +############################################################################### +group("fuzztest") { + testonly = true + + deps = [ ":UdmfServiceProcessDataFuzzTest" ] +} +############################################################################### \ No newline at end of file diff --git a/services/distributeddataservice/service/test/fuzztest/udmfserviceprocessdata_fuzzer/corpus/init b/services/distributeddataservice/service/test/fuzztest/udmfserviceprocessdata_fuzzer/corpus/init new file mode 100644 index 0000000000000000000000000000000000000000..7ade8a0faafeaedba7241e7d4a97b8e1f9691932 --- /dev/null +++ b/services/distributeddataservice/service/test/fuzztest/udmfserviceprocessdata_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/udmfserviceprocessdata_fuzzer/project.xml b/services/distributeddataservice/service/test/fuzztest/udmfserviceprocessdata_fuzzer/project.xml new file mode 100644 index 0000000000000000000000000000000000000000..a37a23b1533f07ab59744732b0f46b2b5fd958d8 --- /dev/null +++ b/services/distributeddataservice/service/test/fuzztest/udmfserviceprocessdata_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + \ No newline at end of file diff --git a/services/distributeddataservice/service/test/fuzztest/udmfserviceprocessdata_fuzzer/udmfserviceprocessdata_fuzzer.cpp b/services/distributeddataservice/service/test/fuzztest/udmfserviceprocessdata_fuzzer/udmfserviceprocessdata_fuzzer.cpp new file mode 100644 index 0000000000000000000000000000000000000000..e960cdac64e1ed36f2e526aa34623514c44a6af2 --- /dev/null +++ b/services/distributeddataservice/service/test/fuzztest/udmfserviceprocessdata_fuzzer/udmfserviceprocessdata_fuzzer.cpp @@ -0,0 +1,129 @@ +/* + * 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 "udmfserviceprocessdata_fuzzer.h" + +#include "accesstoken_kit.h" +#include "distributeddata_udmf_ipc_interface_code.h" +#include "itypes_util.h" +#include "ipc_skeleton.h" +#include "message_parcel.h" +#include "securec.h" +#include "token_setproc.h" +#include "udmf_service_impl.h" +#include "udmf_types_util.h" + +using namespace OHOS::UDMF; + +namespace OHOS { +static constexpr int ID_LEN = 32; +static constexpr int MINIMUM = 48; +static constexpr int MAXIMUM = 121; + +QueryOption GenerateFuzzQueryOption(FuzzedDataProvider &provider) +{ + std::vector groupId(ID_LEN, '0'); + for (size_t i = 0; i < groupId.size(); ++i) { + groupId[i] = provider.ConsumeIntegralInRange(MINIMUM, MAXIMUM); + } + std::string groupIdStr(groupId.begin(), groupId.end()); + UnifiedKey udKey = UnifiedKey("drag", "com.test.demo", groupIdStr); + QueryOption query; + query.key = udKey.GetUnifiedKey(); + query.intention = Intention::UD_INTENTION_DRAG; + query.tokenId = provider.ConsumeIntegral(); + return query; +} + +void ProcessUriFuzz(FuzzedDataProvider &provider) +{ + std::shared_ptr udmfServiceImpl = std::make_shared(); + QueryOption query = GenerateFuzzQueryOption(provider); + UnifiedData data; + std::shared_ptr obj = std::make_shared(); + obj->value_[UNIFORM_DATA_TYPE] = "general.file-uri"; + obj->value_[FILE_URI_PARAM] = provider.ConsumeRandomLengthString(); + obj->value_[FILE_TYPE] = provider.ConsumeRandomLengthString(); + auto record = std::make_shared(FILE_URI, obj); + data.AddRecord(record); + Runtime runtime; + data.SetRuntime(runtime); + udmfServiceImpl->ProcessUri(query, data); +} + +void ProcessCrossDeviceDataFuzz(FuzzedDataProvider &provider) +{ + std::shared_ptr udmfServiceImpl = std::make_shared(); + uint32_t tokenId = provider.ConsumeIntegral(); + UnifiedData data; + std::shared_ptr obj = std::make_shared(); + obj->value_[UNIFORM_DATA_TYPE] = "general.file-uri"; + obj->value_[FILE_URI_PARAM] = provider.ConsumeRandomLengthString(); + obj->value_[FILE_TYPE] = provider.ConsumeRandomLengthString(); + auto record = std::make_shared(FILE_URI, obj); + data.AddRecord(record); + Runtime runtime; + data.SetRuntime(runtime); + std::vector uris; + udmfServiceImpl->ProcessCrossDeviceData(tokenId, data, uris); +} + +void ProcessDataFuzz(FuzzedDataProvider &provider) +{ + std::shared_ptr udmfServiceImpl = std::make_shared(); + QueryOption query = GenerateFuzzQueryOption(provider); + UnifiedData data; + std::shared_ptr obj = std::make_shared(); + obj->value_[UNIFORM_DATA_TYPE] = "general.file-uri"; + obj->value_[FILE_URI_PARAM] = provider.ConsumeRandomLengthString(); + obj->value_[FILE_TYPE] = provider.ConsumeRandomLengthString(); + auto record = std::make_shared(FILE_URI, obj); + data.AddRecord(record); + std::vector dataSet = { data }; + udmfServiceImpl->ProcessData(query, dataSet); +} + +void ProcessResultFuzz(FuzzedDataProvider &provider) +{ + std::shared_ptr udmfServiceImpl = std::make_shared(); + std::map results; + std::string key = provider.ConsumeRandomLengthString(); + int32_t value = provider.ConsumeIntegral(); + results.emplace(std::make_pair(key, value)); + udmfServiceImpl->ProcessResult(results); +} +} + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerInitialize(int *argc, char ***argv) +{ + OHOS::Security::AccessToken::AccessTokenID tokenId = + OHOS::Security::AccessToken::AccessTokenKit::GetHapTokenID(100, "com.ohos.dlpmanager", 0); + SetSelfTokenID(tokenId); + return 0; +} + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + FuzzedDataProvider provider(data, size); + OHOS::ProcessUriFuzz(provider); + OHOS::ProcessCrossDeviceDataFuzz(provider); + OHOS::ProcessDataFuzz(provider); + OHOS::ProcessResultFuzz(provider); + return 0; +} \ No newline at end of file diff --git a/services/distributeddataservice/service/test/fuzztest/udmfserviceprocessdata_fuzzer/udmfserviceprocessdata_fuzzer.h b/services/distributeddataservice/service/test/fuzztest/udmfserviceprocessdata_fuzzer/udmfserviceprocessdata_fuzzer.h new file mode 100644 index 0000000000000000000000000000000000000000..90c37bf4bfff5846ba18386d9e13396ec0e71ff6 --- /dev/null +++ b/services/distributeddataservice/service/test/fuzztest/udmfserviceprocessdata_fuzzer/udmfserviceprocessdata_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 UDMF_SERVICE_PROCESS_DATAFUZZER_H +#define UDMF_SERVICE_PROCESS_DATAFUZZER_H + +#define FUZZ_PROJECT_NAME "udmfserviceprocessdata_fuzzer" + +#endif // UDMF_SERVICE_PROCESS_DATAFUZZER_H \ No newline at end of file diff --git a/services/distributeddataservice/service/test/fuzztest/udmfserviceremoteinteraction_fuzzer/BUILD.gn b/services/distributeddataservice/service/test/fuzztest/udmfserviceremoteinteraction_fuzzer/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..e453e69c16bf16320ffa41721be0bdc5a9910b3c --- /dev/null +++ b/services/distributeddataservice/service/test/fuzztest/udmfserviceremoteinteraction_fuzzer/BUILD.gn @@ -0,0 +1,80 @@ +# 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("UdmfServiceRemoteInteractionFuzzTest") { + module_out_path = "datamgr_service/datamgr_service" + + include_dirs = [ + "${data_service_path}/framework/include", + "${data_service_path}/service/matrix/include", + "${data_service_path}/service/udmf/lifecycle", + "${data_service_path}/service/udmf/permission", + "${data_service_path}/service/udmf/preprocess", + "${data_service_path}/service/udmf/store", + "${data_service_path}/service/udmf", + ] + + fuzz_config_file = + "${data_service_path}/service/test/fuzztest/udmfserviceremoteinteraction_fuzzer" + + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + "-fno-access-control" + ] + + sources = [ "udmfserviceremoteinteraction_fuzzer.cpp" ] + + deps = [ + "${data_service_path}/adapter/account:distributeddata_account", + "${data_service_path}/adapter/communicator:distributeddata_communicator", + "${data_service_path}/adapter/dfx:distributeddata_dfx", + "${data_service_path}/framework:distributeddatasvcfwk", + "${data_service_path}/service/bootstrap:distributeddata_bootstrap", + "${data_service_path}/service/matrix:distributeddata_matrix", + "${data_service_path}/service/udmf:udmf_server", + ] + + external_deps = [ + "ability_base:zuri", + "ability_runtime:uri_permission_mgr", + "access_token:libaccesstoken_sdk", + "access_token:libtoken_setproc", + "bundle_framework:appexecfwk_base", + "bundle_framework:appexecfwk_core", + "c_utils:utils", + "hilog:libhilog", + "hisysevent:libhisysevent", + "ipc:ipc_core", + "kv_store:distributeddata_inner", + "kv_store:distributeddata_mgr", + "kv_store:distributeddb", + "samgr:samgr_proxy", + "udmf:udmf_client", + ] +} + +############################################################################### +group("fuzztest") { + testonly = true + + deps = [ ":UdmfServiceRemoteInteractionFuzzTest" ] +} +############################################################################### \ No newline at end of file diff --git a/services/distributeddataservice/service/test/fuzztest/udmfserviceremoteinteraction_fuzzer/corpus/init b/services/distributeddataservice/service/test/fuzztest/udmfserviceremoteinteraction_fuzzer/corpus/init new file mode 100644 index 0000000000000000000000000000000000000000..7ade8a0faafeaedba7241e7d4a97b8e1f9691932 --- /dev/null +++ b/services/distributeddataservice/service/test/fuzztest/udmfserviceremoteinteraction_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/udmfserviceremoteinteraction_fuzzer/project.xml b/services/distributeddataservice/service/test/fuzztest/udmfserviceremoteinteraction_fuzzer/project.xml new file mode 100644 index 0000000000000000000000000000000000000000..a37a23b1533f07ab59744732b0f46b2b5fd958d8 --- /dev/null +++ b/services/distributeddataservice/service/test/fuzztest/udmfserviceremoteinteraction_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + \ No newline at end of file diff --git a/services/distributeddataservice/service/test/fuzztest/udmfserviceremoteinteraction_fuzzer/udmfserviceremoteinteraction_fuzzer.cpp b/services/distributeddataservice/service/test/fuzztest/udmfserviceremoteinteraction_fuzzer/udmfserviceremoteinteraction_fuzzer.cpp new file mode 100644 index 0000000000000000000000000000000000000000..5f254cf2f2b71191b065b1f5bc81be86393cd02a --- /dev/null +++ b/services/distributeddataservice/service/test/fuzztest/udmfserviceremoteinteraction_fuzzer/udmfserviceremoteinteraction_fuzzer.cpp @@ -0,0 +1,142 @@ +/* + * 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 "udmfserviceremoteinteraction_fuzzer.h" + +#include "accesstoken_kit.h" +#include "distributeddata_udmf_ipc_interface_code.h" +#include "itypes_util.h" +#include "ipc_skeleton.h" +#include "message_parcel.h" +#include "securec.h" +#include "token_setproc.h" +#include "udmf_service_impl.h" +#include "udmf_types_util.h" + +using namespace OHOS::UDMF; + +namespace OHOS { +const std::u16string INTERFACE_TOKEN = u"OHOS.UDMF.UdmfService"; +constexpr uint32_t CODE_MIN = 0; +constexpr uint32_t CODE_MAX = static_cast(UdmfServiceInterfaceCode::CODE_BUTT) + 1; +constexpr size_t NUM_MIN = 5; +constexpr size_t NUM_MAX = 12; +static constexpr int ID_LEN = 32; +static constexpr int MINIMUM = 48; +static constexpr int MAXIMUM = 121; + +QueryOption GenerateFuzzQueryOption(FuzzedDataProvider &provider) +{ + std::vector groupId(ID_LEN, '0'); + for (size_t i = 0; i < groupId.size(); ++i) { + groupId[i] = provider.ConsumeIntegralInRange(MINIMUM, MAXIMUM); + } + std::string groupIdStr(groupId.begin(), groupId.end()); + UnifiedKey udKey = UnifiedKey("drag", "com.test.demo", groupIdStr); + QueryOption query; + query.key = udKey.GetUnifiedKey(); + query.intention = Intention::UD_INTENTION_DRAG; + query.tokenId = provider.ConsumeIntegral(); + return query; +} + +bool OnRemoteRequestFuzz(FuzzedDataProvider &provider) +{ + std::shared_ptr udmfServiceImpl = std::make_shared(); + std::shared_ptr executor = std::make_shared(NUM_MAX, NUM_MIN); + udmfServiceImpl->OnBind({ "UdmfServiceRemoteInteractionFuzzTest", + static_cast(IPCSkeleton::GetSelfTokenID()), std::move(executor) }); + + uint32_t code = provider.ConsumeIntegralInRange(CODE_MIN, CODE_MAX); + std::vector remainingData = provider.ConsumeRemainingBytes(); + MessageParcel request; + request.WriteInterfaceToken(INTERFACE_TOKEN); + request.WriteBuffer(static_cast(remainingData.data()), remainingData.size()); + request.RewindRead(0); + MessageParcel reply; + udmfServiceImpl->OnRemoteRequest(code, request, reply); + udmfServiceImpl->OnBind( + { "UdmfServiceRemoteInteractionFuzzTest", static_cast(IPCSkeleton::GetSelfTokenID()), nullptr }); + executor = nullptr; + return true; +} + +void IsRemoteDataFuzz(FuzzedDataProvider &provider) +{ + std::shared_ptr udmfServiceImpl = std::make_shared(); + std::shared_ptr executor = std::make_shared(NUM_MAX, NUM_MIN); + udmfServiceImpl->OnBind({ "UdmfServiceRemoteInteractionFuzzTest", + static_cast(IPCSkeleton::GetSelfTokenID()), std::move(executor) }); + QueryOption query = GenerateFuzzQueryOption(provider); + MessageParcel requestUpdate; + requestUpdate.WriteInterfaceToken(INTERFACE_TOKEN); + ITypesUtil::Marshal(requestUpdate, query); + MessageParcel replyUpdate; + udmfServiceImpl->OnRemoteRequest(static_cast(UdmfServiceInterfaceCode::IS_REMOTE_DATA), + requestUpdate, replyUpdate); + udmfServiceImpl->OnBind( + { "UdmfServiceRemoteInteractionFuzzTest", static_cast(IPCSkeleton::GetSelfTokenID()), nullptr }); + executor = nullptr; +} + +void ResolveAutoLaunchFuzz(FuzzedDataProvider &provider) +{ + std::shared_ptr udmfServiceImpl = std::make_shared(); + std::shared_ptr executor = std::make_shared(NUM_MAX, NUM_MIN); + udmfServiceImpl->OnBind({ "UdmfServiceRemoteInteractionFuzzTest", + static_cast(IPCSkeleton::GetSelfTokenID()), std::move(executor) }); + auto identifier = provider.ConsumeRandomLengthString(); + UdmfServiceImpl::DBLaunchParam param; + param.userId = provider.ConsumeRandomLengthString(); + param.appId = provider.ConsumeRandomLengthString(); + param.storeId = provider.ConsumeRandomLengthString(); + param.path = provider.ConsumeRandomLengthString(); + udmfServiceImpl->ResolveAutoLaunch(identifier, param); + udmfServiceImpl->OnBind( + { "UdmfServiceRemoteInteractionFuzzTest", static_cast(IPCSkeleton::GetSelfTokenID()), nullptr }); + executor = nullptr; +} + +void OnUserChangeFuzz(FuzzedDataProvider &provider) +{ + std::shared_ptr udmfServiceImpl = std::make_shared(); + uint32_t code = provider.ConsumeIntegral(); + auto user = provider.ConsumeRandomLengthString(); + auto account = provider.ConsumeRandomLengthString(); + udmfServiceImpl->OnUserChange(code, user, account); +} +} + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerInitialize(int *argc, char ***argv) +{ + OHOS::Security::AccessToken::AccessTokenID tokenId = + OHOS::Security::AccessToken::AccessTokenKit::GetHapTokenID(100, "com.ohos.dlpmanager", 0); + SetSelfTokenID(tokenId); + return 0; +} + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + FuzzedDataProvider provider(data, size); + OHOS::OnRemoteRequestFuzz(provider); + OHOS::IsRemoteDataFuzz(provider); + OHOS::ResolveAutoLaunchFuzz(provider); + OHOS::OnUserChangeFuzz(provider); + return 0; +} \ No newline at end of file diff --git a/services/distributeddataservice/service/test/fuzztest/udmfserviceremoteinteraction_fuzzer/udmfserviceremoteinteraction_fuzzer.h b/services/distributeddataservice/service/test/fuzztest/udmfserviceremoteinteraction_fuzzer/udmfserviceremoteinteraction_fuzzer.h new file mode 100644 index 0000000000000000000000000000000000000000..bd7aa87b65fe6f0546bfdf501a684633c8ed3a40 --- /dev/null +++ b/services/distributeddataservice/service/test/fuzztest/udmfserviceremoteinteraction_fuzzer/udmfserviceremoteinteraction_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 UDMF_SERVICE_REMOTE_INTERACTION_FUZZER_H +#define UDMF_SERVICE_REMOTE_INTERACTION_FUZZER_H + +#define FUZZ_PROJECT_NAME "udmfserviceremoteinteraction_fuzzer" + +#endif // UDMF_SERVICE_REMOTE_INTERACTION_FUZZER_H \ No newline at end of file diff --git a/services/distributeddataservice/service/test/fuzztest/udmfservicesyncandmeta_fuzzer/BUILD.gn b/services/distributeddataservice/service/test/fuzztest/udmfservicesyncandmeta_fuzzer/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..ec28461b29f979e239577c329069c7cd93aeec92 --- /dev/null +++ b/services/distributeddataservice/service/test/fuzztest/udmfservicesyncandmeta_fuzzer/BUILD.gn @@ -0,0 +1,80 @@ +# 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("UdmfServiceSyncAndMetaFuzzTest") { + module_out_path = "datamgr_service/datamgr_service" + + include_dirs = [ + "${data_service_path}/framework/include", + "${data_service_path}/service/matrix/include", + "${data_service_path}/service/udmf/lifecycle", + "${data_service_path}/service/udmf/permission", + "${data_service_path}/service/udmf/preprocess", + "${data_service_path}/service/udmf/store", + "${data_service_path}/service/udmf", + ] + + fuzz_config_file = + "${data_service_path}/service/test/fuzztest/udmfservicesyncandmeta_fuzzer" + + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + "-fno-access-control" + ] + + sources = [ "udmfservicesyncandmeta_fuzzer.cpp" ] + + deps = [ + "${data_service_path}/adapter/account:distributeddata_account", + "${data_service_path}/adapter/communicator:distributeddata_communicator", + "${data_service_path}/adapter/dfx:distributeddata_dfx", + "${data_service_path}/framework:distributeddatasvcfwk", + "${data_service_path}/service/bootstrap:distributeddata_bootstrap", + "${data_service_path}/service/matrix:distributeddata_matrix", + "${data_service_path}/service/udmf:udmf_server", + ] + + external_deps = [ + "ability_base:zuri", + "ability_runtime:uri_permission_mgr", + "access_token:libaccesstoken_sdk", + "access_token:libtoken_setproc", + "bundle_framework:appexecfwk_base", + "bundle_framework:appexecfwk_core", + "c_utils:utils", + "hilog:libhilog", + "hisysevent:libhisysevent", + "ipc:ipc_core", + "kv_store:distributeddata_inner", + "kv_store:distributeddata_mgr", + "kv_store:distributeddb", + "samgr:samgr_proxy", + "udmf:udmf_client", + ] +} + +############################################################################### +group("fuzztest") { + testonly = true + + deps = [ ":UdmfServiceSyncAndMetaFuzzTest" ] +} +############################################################################### \ No newline at end of file diff --git a/services/distributeddataservice/service/test/fuzztest/udmfservicesyncandmeta_fuzzer/corpus/init b/services/distributeddataservice/service/test/fuzztest/udmfservicesyncandmeta_fuzzer/corpus/init new file mode 100644 index 0000000000000000000000000000000000000000..7ade8a0faafeaedba7241e7d4a97b8e1f9691932 --- /dev/null +++ b/services/distributeddataservice/service/test/fuzztest/udmfservicesyncandmeta_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/udmfservicesyncandmeta_fuzzer/project.xml b/services/distributeddataservice/service/test/fuzztest/udmfservicesyncandmeta_fuzzer/project.xml new file mode 100644 index 0000000000000000000000000000000000000000..a37a23b1533f07ab59744732b0f46b2b5fd958d8 --- /dev/null +++ b/services/distributeddataservice/service/test/fuzztest/udmfservicesyncandmeta_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + \ No newline at end of file diff --git a/services/distributeddataservice/service/test/fuzztest/udmfservicesyncandmeta_fuzzer/udmfservicesyncandmeta_fuzzer.cpp b/services/distributeddataservice/service/test/fuzztest/udmfservicesyncandmeta_fuzzer/udmfservicesyncandmeta_fuzzer.cpp new file mode 100644 index 0000000000000000000000000000000000000000..36acaafb8adcadff613b7c2ace895ae10423778c --- /dev/null +++ b/services/distributeddataservice/service/test/fuzztest/udmfservicesyncandmeta_fuzzer/udmfservicesyncandmeta_fuzzer.cpp @@ -0,0 +1,132 @@ +/* + * 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 "udmfservicesyncandmeta_fuzzer.h" + +#include "accesstoken_kit.h" +#include "distributeddata_udmf_ipc_interface_code.h" +#include "itypes_util.h" +#include "ipc_skeleton.h" +#include "message_parcel.h" +#include "securec.h" +#include "token_setproc.h" +#include "udmf_service_impl.h" +#include "udmf_types_util.h" + +using namespace OHOS::UDMF; + +namespace OHOS { +const std::u16string INTERFACE_TOKEN = u"OHOS.UDMF.UdmfService"; +constexpr size_t NUM_MIN = 5; +constexpr size_t NUM_MAX = 12; +static constexpr int ID_LEN = 32; +static constexpr int MINIMUM = 48; +static constexpr int MAXIMUM = 121; + +QueryOption GenerateFuzzQueryOption(FuzzedDataProvider &provider) +{ + std::vector groupId(ID_LEN, '0'); + for (size_t i = 0; i < groupId.size(); ++i) { + groupId[i] = provider.ConsumeIntegralInRange(MINIMUM, MAXIMUM); + } + std::string groupIdStr(groupId.begin(), groupId.end()); + UnifiedKey udKey = UnifiedKey("drag", "com.test.demo", groupIdStr); + QueryOption query; + query.key = udKey.GetUnifiedKey(); + query.intention = Intention::UD_INTENTION_DRAG; + query.tokenId = provider.ConsumeIntegral(); + return query; +} + +void SyncDataFuzz(FuzzedDataProvider &provider) +{ + std::shared_ptr udmfServiceImpl = std::make_shared(); + std::shared_ptr executor = std::make_shared(NUM_MAX, NUM_MIN); + udmfServiceImpl->OnBind({ "UdmfServiceSyncAndMetaFuzzTest", + static_cast(IPCSkeleton::GetSelfTokenID()), std::move(executor) }); + QueryOption query = GenerateFuzzQueryOption(provider); + std::vector devices = { "11", "22" }; + MessageParcel requestUpdate; + requestUpdate.WriteInterfaceToken(INTERFACE_TOKEN); + ITypesUtil::Marshal(requestUpdate, query, devices); + MessageParcel replyUpdate; + udmfServiceImpl->OnRemoteRequest(static_cast(UdmfServiceInterfaceCode::SYNC), + requestUpdate, replyUpdate); + udmfServiceImpl->OnBind( + { "UdmfServiceSyncAndMetaFuzzTest", static_cast(IPCSkeleton::GetSelfTokenID()), nullptr }); + executor = nullptr; +} + +void StoreSyncFuzz(FuzzedDataProvider &provider) +{ + std::shared_ptr udmfServiceImpl = std::make_shared(); + std::vector groupId(ID_LEN, '0'); + for (size_t i = 0; i < groupId.size(); ++i) { + groupId[i] = provider.ConsumeIntegralInRange(MINIMUM, MAXIMUM); + } + std::string groupIdStr(groupId.begin(), groupId.end()); + UnifiedKey key = UnifiedKey("drag", "com.test.demo", groupIdStr); + QueryOption query; + query.key = key.GetUnifiedKey(); + query.intention = Intention::UD_INTENTION_DRAG; + query.tokenId = provider.ConsumeIntegral(); + std::vector devices = { "11", "22" }; + udmfServiceImpl->StoreSync(key, query, devices); +} + +void BuildMetaFuzz(FuzzedDataProvider &provider) +{ + std::shared_ptr udmfServiceImpl = std::make_shared(); + std::string storeId = provider.ConsumeRandomLengthString(); + int userId = provider.ConsumeIntegral(); + udmfServiceImpl->BuildMeta(storeId, userId); +} + +void IsNeedMetaSyncFuzz(FuzzedDataProvider &provider) +{ + std::shared_ptr udmfServiceImpl = std::make_shared(); + DistributedData::StoreMetaData meta; + uint8_t len = provider.ConsumeIntegral(); + std::vector uuids(len); + for (int i = 0; i < len; i++) { + std::string uuid = provider.ConsumeRandomLengthString(); + uuids[i] = uuid; + } + udmfServiceImpl->IsNeedMetaSync(meta, uuids); +} + +} + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerInitialize(int *argc, char ***argv) +{ + OHOS::Security::AccessToken::AccessTokenID tokenId = + OHOS::Security::AccessToken::AccessTokenKit::GetHapTokenID(100, "com.ohos.dlpmanager", 0); + SetSelfTokenID(tokenId); + return 0; +} + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + FuzzedDataProvider provider(data, size); + OHOS::SyncDataFuzz(provider); + OHOS::StoreSyncFuzz(provider); + OHOS::BuildMetaFuzz(provider); + OHOS::IsNeedMetaSyncFuzz(provider); + return 0; +} \ No newline at end of file diff --git a/services/distributeddataservice/service/test/fuzztest/udmfservicesyncandmeta_fuzzer/udmfservicesyncandmeta_fuzzer.h b/services/distributeddataservice/service/test/fuzztest/udmfservicesyncandmeta_fuzzer/udmfservicesyncandmeta_fuzzer.h new file mode 100644 index 0000000000000000000000000000000000000000..6ed4bde29f2f433600fe4967e9a1f156fd544c99 --- /dev/null +++ b/services/distributeddataservice/service/test/fuzztest/udmfservicesyncandmeta_fuzzer/udmfservicesyncandmeta_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 UDMF_SERVICE_SYNC_AND_META_FUZZER_H +#define UDMF_SERVICE_SYNC_AND_META_FUZZER_H + +#define FUZZ_PROJECT_NAME "udmfservicesyncandmeta_fuzzer" + +#endif // UDMF_SERVICE_SYNC_AND_META_FUZZER_H \ No newline at end of file diff --git a/services/distributeddataservice/service/test/fuzztest/udmfserviceverifypermission_fuzzer/BUILD.gn b/services/distributeddataservice/service/test/fuzztest/udmfserviceverifypermission_fuzzer/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..b816b9e73afa1d5d657565b4546ca477525ab6c2 --- /dev/null +++ b/services/distributeddataservice/service/test/fuzztest/udmfserviceverifypermission_fuzzer/BUILD.gn @@ -0,0 +1,80 @@ +# 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("UdmfServiceVerifyPermissionFuzzTest") { + module_out_path = "datamgr_service/datamgr_service" + + include_dirs = [ + "${data_service_path}/framework/include", + "${data_service_path}/service/matrix/include", + "${data_service_path}/service/udmf/lifecycle", + "${data_service_path}/service/udmf/permission", + "${data_service_path}/service/udmf/preprocess", + "${data_service_path}/service/udmf/store", + "${data_service_path}/service/udmf", + ] + + fuzz_config_file = + "${data_service_path}/service/test/fuzztest/udmfserviceverifypermission_fuzzer" + + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + "-fno-access-control" + ] + + sources = [ "udmfserviceverifypermission_fuzzer.cpp" ] + + deps = [ + "${data_service_path}/adapter/account:distributeddata_account", + "${data_service_path}/adapter/communicator:distributeddata_communicator", + "${data_service_path}/adapter/dfx:distributeddata_dfx", + "${data_service_path}/framework:distributeddatasvcfwk", + "${data_service_path}/service/bootstrap:distributeddata_bootstrap", + "${data_service_path}/service/matrix:distributeddata_matrix", + "${data_service_path}/service/udmf:udmf_server", + ] + + external_deps = [ + "ability_base:zuri", + "ability_runtime:uri_permission_mgr", + "access_token:libaccesstoken_sdk", + "access_token:libtoken_setproc", + "bundle_framework:appexecfwk_base", + "bundle_framework:appexecfwk_core", + "c_utils:utils", + "hilog:libhilog", + "hisysevent:libhisysevent", + "ipc:ipc_core", + "kv_store:distributeddata_inner", + "kv_store:distributeddata_mgr", + "kv_store:distributeddb", + "samgr:samgr_proxy", + "udmf:udmf_client", + ] +} + +############################################################################### +group("fuzztest") { + testonly = true + + deps = [ ":UdmfServiceVerifyPermissionFuzzTest" ] +} +############################################################################### \ No newline at end of file diff --git a/services/distributeddataservice/service/test/fuzztest/udmfserviceverifypermission_fuzzer/corpus/init b/services/distributeddataservice/service/test/fuzztest/udmfserviceverifypermission_fuzzer/corpus/init new file mode 100644 index 0000000000000000000000000000000000000000..7ade8a0faafeaedba7241e7d4a97b8e1f9691932 --- /dev/null +++ b/services/distributeddataservice/service/test/fuzztest/udmfserviceverifypermission_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/udmfserviceverifypermission_fuzzer/project.xml b/services/distributeddataservice/service/test/fuzztest/udmfserviceverifypermission_fuzzer/project.xml new file mode 100644 index 0000000000000000000000000000000000000000..a37a23b1533f07ab59744732b0f46b2b5fd958d8 --- /dev/null +++ b/services/distributeddataservice/service/test/fuzztest/udmfserviceverifypermission_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + \ No newline at end of file diff --git a/services/distributeddataservice/service/test/fuzztest/udmfserviceverifypermission_fuzzer/udmfserviceverifypermission_fuzzer.cpp b/services/distributeddataservice/service/test/fuzztest/udmfserviceverifypermission_fuzzer/udmfserviceverifypermission_fuzzer.cpp new file mode 100644 index 0000000000000000000000000000000000000000..1498f4143c4adc891b09a352188ed19b5484c4e1 --- /dev/null +++ b/services/distributeddataservice/service/test/fuzztest/udmfserviceverifypermission_fuzzer/udmfserviceverifypermission_fuzzer.cpp @@ -0,0 +1,157 @@ +/* + * 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 "udmfserviceverifypermission_fuzzer.h" + +#include "accesstoken_kit.h" +#include "distributeddata_udmf_ipc_interface_code.h" +#include "itypes_util.h" +#include "ipc_skeleton.h" +#include "message_parcel.h" +#include "securec.h" +#include "token_setproc.h" +#include "udmf_service_impl.h" +#include "udmf_types_util.h" + +using namespace OHOS::UDMF; + +namespace OHOS { +constexpr size_t NUM_MIN = 5; +constexpr size_t NUM_MAX = 12; +static constexpr int ID_LEN = 32; +static constexpr int MINIMUM = 48; +static constexpr int MAXIMUM = 121; + +QueryOption GenerateFuzzQueryOption(FuzzedDataProvider &provider) +{ + std::vector groupId(ID_LEN, '0'); + for (size_t i = 0; i < groupId.size(); ++i) { + groupId[i] = provider.ConsumeIntegralInRange(MINIMUM, MAXIMUM); + } + std::string groupIdStr(groupId.begin(), groupId.end()); + UnifiedKey udKey = UnifiedKey("drag", "com.test.demo", groupIdStr); + QueryOption query; + query.key = udKey.GetUnifiedKey(); + query.intention = Intention::UD_INTENTION_DRAG; + query.tokenId = provider.ConsumeIntegral(); + return query; +} + +void VerifyIntentionPermissionFuzz(FuzzedDataProvider &provider) +{ + std::shared_ptr udmfServiceImpl = std::make_shared(); + std::shared_ptr executor = std::make_shared(NUM_MAX, NUM_MIN); + udmfServiceImpl->OnBind({ "UdmfServiceVerifyPermissionFuzzTest", + static_cast(IPCSkeleton::GetSelfTokenID()), std::move(executor) }); + QueryOption query = GenerateFuzzQueryOption(provider); + UnifiedData data; + std::string intention = provider.ConsumeRandomLengthString(); + std::string bundleName = provider.ConsumeRandomLengthString(); + std::vector groupId(ID_LEN); + for (size_t i = 0; i < groupId.size(); ++i) { + groupId[i] = provider.ConsumeIntegralInRange(MINIMUM, MAXIMUM); + } + std::string groupIdStr(groupId.begin(), groupId.end()); + UnifiedKey udKey(intention, bundleName, groupIdStr); + CheckerManager::CheckInfo info; + info.tokenId = provider.ConsumeIntegral(); + Runtime runtime; + data.SetRuntime(runtime); + udmfServiceImpl->VerifyIntentionPermission(query, data, udKey, info); + udmfServiceImpl->OnBind( + { "UdmfServiceVerifyPermissionFuzzTest", static_cast(IPCSkeleton::GetSelfTokenID()), nullptr }); + executor = nullptr; +} + +void VerifyDataAccessPermissionFuzz(FuzzedDataProvider &provider) +{ + std::shared_ptr udmfServiceImpl = std::make_shared(); + std::shared_ptr runtime = std::make_shared(); + std::vector groupId(ID_LEN, '0'); + for (size_t i = 0; i < groupId.size(); ++i) { + groupId[i] = provider.ConsumeIntegralInRange(MINIMUM, MAXIMUM); + } + std::string groupIdStr(groupId.begin(), groupId.end()); + UnifiedKey udKey = UnifiedKey("drag", "com.test.demo", groupIdStr); + QueryOption query; + query.key = udKey.GetUnifiedKey(); + query.intention = Intention::UD_INTENTION_DRAG; + query.tokenId = provider.ConsumeIntegral(); + UnifiedData data; + std::shared_ptr obj = std::make_shared(); + obj->value_[UNIFORM_DATA_TYPE] = "general.file-uri"; + obj->value_[FILE_URI_PARAM] = provider.ConsumeRandomLengthString(); + obj->value_[FILE_TYPE] = provider.ConsumeRandomLengthString(); + auto record = std::make_shared(FILE_URI, obj); + data.AddRecord(record); + udmfServiceImpl->VerifyDataAccessPermission(runtime, query, data); +} + +void VerifyUpdatePermissionFuzz(FuzzedDataProvider &provider) +{ + std::shared_ptr udmfServiceImpl = std::make_shared(); + std::vector groupId(ID_LEN, '0'); + for (size_t i = 0; i < groupId.size(); ++i) { + groupId[i] = provider.ConsumeIntegralInRange(MINIMUM, MAXIMUM); + } + std::string groupIdStr(groupId.begin(), groupId.end()); + UnifiedKey udKey = UnifiedKey("drag", "com.test.demo", groupIdStr); + QueryOption query; + query.key = udKey.GetUnifiedKey(); + query.intention = Intention::UD_INTENTION_DRAG; + query.tokenId = provider.ConsumeIntegral(); + UnifiedData unifiedData; + std::shared_ptr obj = std::make_shared(); + obj->value_[UNIFORM_DATA_TYPE] = "general.file-uri"; + obj->value_[FILE_URI_PARAM] = provider.ConsumeRandomLengthString(); + obj->value_[FILE_TYPE] = provider.ConsumeRandomLengthString(); + auto record = std::make_shared(FILE_URI, obj); + unifiedData.AddRecord(record); + Runtime runtime; + unifiedData.SetRuntime(runtime); + std::string bundleName = provider.ConsumeRandomLengthString(); + udmfServiceImpl->VerifyUpdatePermission(query, unifiedData, bundleName); +} + +void VerifyPermissionFuzz(FuzzedDataProvider &provider) +{ + std::shared_ptr udmfServiceImpl = std::make_shared(); + std::string permission = provider.ConsumeRandomLengthString(); + uint32_t callerTokenId = provider.ConsumeIntegral(); + udmfServiceImpl->VerifyPermission(permission, callerTokenId); +} +} + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerInitialize(int *argc, char ***argv) +{ + OHOS::Security::AccessToken::AccessTokenID tokenId = + OHOS::Security::AccessToken::AccessTokenKit::GetHapTokenID(100, "com.ohos.dlpmanager", 0); + SetSelfTokenID(tokenId); + return 0; +} + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + FuzzedDataProvider provider(data, size); + OHOS::VerifyIntentionPermissionFuzz(provider); + OHOS::VerifyDataAccessPermissionFuzz(provider); + OHOS::VerifyUpdatePermissionFuzz(provider); + OHOS::VerifyPermissionFuzz(provider); + return 0; +} \ No newline at end of file diff --git a/services/distributeddataservice/service/test/fuzztest/udmfserviceverifypermission_fuzzer/udmfserviceverifypermission_fuzzer.h b/services/distributeddataservice/service/test/fuzztest/udmfserviceverifypermission_fuzzer/udmfserviceverifypermission_fuzzer.h new file mode 100644 index 0000000000000000000000000000000000000000..e369192bee20c5815f275c0ff8f8c4d49d5e8dc0 --- /dev/null +++ b/services/distributeddataservice/service/test/fuzztest/udmfserviceverifypermission_fuzzer/udmfserviceverifypermission_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 UDMF_SERVICE_VERIFY_PERMISSION_FUZZER_H +#define UDMF_SERVICE_VERIFY_PERMISSION_FUZZER_H + +#define FUZZ_PROJECT_NAME "udmfserviceverifypermission_fuzzer" + +#endif // UDMF_SERVICE_VERIFY_PERMISSION_FUZZER_H \ No newline at end of file