diff --git a/services/distributeddataservice/service/data_share/sys_event_subscriber.cpp b/services/distributeddataservice/service/data_share/sys_event_subscriber.cpp index deb855590590804fe15d36ca2a5c8d06cd094ddd..4e09c271c0adc686f04ee842ca16fd7e47a647fa 100644 --- a/services/distributeddataservice/service/data_share/sys_event_subscriber.cpp +++ b/services/distributeddataservice/service/data_share/sys_event_subscriber.cpp @@ -47,7 +47,7 @@ void SysEventSubscriber::OnReceiveEvent(const EventFwk::CommonEventData& event) std::string bundleName = want.GetElement().GetBundleName(); int32_t userId = want.GetIntParam(USER_ID, -1); int32_t appIndex = want.GetIntParam(APP_INDEX, 0); - int32_t tokenId = want.GetIntParam(ACCESS_TOKEN_ID, -1); + uint32_t tokenId = static_cast(want.GetIntParam(ACCESS_TOKEN_ID, 0)); // when application updated, the tokenId in event's want is 0, so use other way to get tokenId if (tokenId == 0) { tokenId = Security::AccessToken::AccessTokenKit::GetHapTokenID(userId, bundleName, appIndex); @@ -70,7 +70,7 @@ void SysEventSubscriber::OnBMSReady() } void SysEventSubscriber::OnAppInstall(const std::string &bundleName, - int32_t userId, int32_t appIndex, int32_t tokenId, bool isCrossAppSharedConfig) + int32_t userId, int32_t appIndex, uint32_t tokenId, bool isCrossAppSharedConfig) { ZLOGI("%{public}s installed, userId: %{public}d, appIndex: %{public}d, tokenId: %{public}d", bundleName.c_str(), userId, appIndex, tokenId); @@ -80,7 +80,7 @@ void SysEventSubscriber::OnAppInstall(const std::string &bundleName, } void SysEventSubscriber::OnAppUpdate(const std::string &bundleName, - int32_t userId, int32_t appIndex, int32_t tokenId, bool isCrossAppSharedConfig) + int32_t userId, int32_t appIndex, uint32_t tokenId, bool isCrossAppSharedConfig) { ZLOGI("%{public}s updated, userId: %{public}d, appIndex: %{public}d, tokenId: %{public}d", bundleName.c_str(), userId, appIndex, tokenId); @@ -90,7 +90,7 @@ void SysEventSubscriber::OnAppUpdate(const std::string &bundleName, } void SysEventSubscriber::OnAppUninstall(const std::string &bundleName, - int32_t userId, int32_t appIndex, int32_t tokenId, bool isCrossAppSharedConfig) + int32_t userId, int32_t appIndex, uint32_t tokenId, bool isCrossAppSharedConfig) { ZLOGI("%{public}s uninstalled, userId: %{public}d, appIndex: %{public}d, tokenId: %{public}d", bundleName.c_str(), userId, appIndex, tokenId); diff --git a/services/distributeddataservice/service/data_share/sys_event_subscriber.h b/services/distributeddataservice/service/data_share/sys_event_subscriber.h index 71e11bd017fa5129504b7bdff164a77427311f43..2a00f77d7e2aee8f2806f61d2de2662f1e97a5bc 100644 --- a/services/distributeddataservice/service/data_share/sys_event_subscriber.h +++ b/services/distributeddataservice/service/data_share/sys_event_subscriber.h @@ -24,17 +24,17 @@ class SysEventSubscriber : public EventFwk::CommonEventSubscriber { public: using SysEventCallback = void (SysEventSubscriber::*)(); using InstallEventCallback = void (SysEventSubscriber::*)(const std::string &bundleName, - int32_t userId, int32_t appIndex, int32_t tokenId, bool isCrossAppSharedConfig); + int32_t userId, int32_t appIndex, uint32_t tokenId, bool isCrossAppSharedConfig); explicit SysEventSubscriber(const EventFwk::CommonEventSubscribeInfo &info); ~SysEventSubscriber() {} void OnReceiveEvent(const EventFwk::CommonEventData& event) override; void OnBMSReady(); void OnAppInstall(const std::string &bundleName, - int32_t userId, int32_t appIndex, int32_t tokenId, bool isCrossAppSharedConfig); + int32_t userId, int32_t appIndex, uint32_t tokenId, bool isCrossAppSharedConfig); void OnAppUpdate(const std::string &bundleName, - int32_t userId, int32_t appIndex, int32_t tokenId, bool isCrossAppSharedConfig); + int32_t userId, int32_t appIndex, uint32_t tokenId, bool isCrossAppSharedConfig); void OnAppUninstall(const std::string &bundleName, - int32_t userId, int32_t appIndex, int32_t tokenId, bool isCrossAppSharedConfig); + int32_t userId, int32_t appIndex, uint32_t tokenId, bool isCrossAppSharedConfig); private: void NotifyDataShareReady(); diff --git a/services/distributeddataservice/service/test/fuzztest/datashareserviceimpl_fuzzer/datashareserviceimpl_fuzzer.cpp b/services/distributeddataservice/service/test/fuzztest/datashareserviceimpl_fuzzer/datashareserviceimpl_fuzzer.cpp index 20736a7e794d4317bebc0aab684efeafda4a44c7..83644b248371376d72cb6b254448f89af95edfc3 100644 --- a/services/distributeddataservice/service/test/fuzztest/datashareserviceimpl_fuzzer/datashareserviceimpl_fuzzer.cpp +++ b/services/distributeddataservice/service/test/fuzztest/datashareserviceimpl_fuzzer/datashareserviceimpl_fuzzer.cpp @@ -221,6 +221,143 @@ void AutoLaunchFuzz(FuzzedDataProvider &provider) DistributedData::RemoteChangeEvent event(evtId, std::move(dataInfo)); dataShareServiceImpl->AutoLaunch(event); } + +void UpdateExFuzz(FuzzedDataProvider &provider) +{ + std::shared_ptr dataShareServiceImpl = std::make_shared(); + std::string uri = provider.ConsumeRandomLengthString(); + std::string extUri = provider.ConsumeRandomLengthString(); + DataSharePredicates predicates; + DataShareValuesBucket valuesBucket; + std::string key1 = provider.ConsumeRandomLengthString(); + std::string key2 = provider.ConsumeRandomLengthString(); + std::string key3 = provider.ConsumeRandomLengthString(); + std::string key4 = provider.ConsumeRandomLengthString(); + int valueInt = provider.ConsumeIntegral(); + float valueFloat = provider.ConsumeFloatingPoint(); + std::string valueStr = provider.ConsumeRandomLengthString(); + bool valueBool = provider.ConsumeBool(); + valuesBucket.valuesMap[key1] = valueInt; + valuesBucket.valuesMap[key2] = valueFloat; + valuesBucket.valuesMap[key3] = valueStr; + valuesBucket.valuesMap[key4] = valueBool; + dataShareServiceImpl->UpdateEx(uri, extUri, predicates, valuesBucket); +} + +void DeleteExFuzz(FuzzedDataProvider &provider) +{ + std::shared_ptr dataShareServiceImpl = std::make_shared(); + std::string uri = provider.ConsumeRandomLengthString(); + std::string extUri = provider.ConsumeRandomLengthString(); + DataSharePredicates predicates; + dataShareServiceImpl->DeleteEx(uri, extUri, predicates); +} + +void DelTemplateFuzz(FuzzedDataProvider &provider) +{ + std::shared_ptr dataShareServiceImpl = std::make_shared(); + std::string uri = provider.ConsumeRandomLengthString(); + int64_t subscriberId = provider.ConsumeIntegral(); + dataShareServiceImpl->DelTemplate(uri, subscriberId); +} + +void PublishFuzz(FuzzedDataProvider &provider) +{ + std::shared_ptr dataShareServiceImpl = std::make_shared(); + Data data; + std::string bundleNameOfProvider = provider.ConsumeRandomLengthString(); + dataShareServiceImpl->Publish(data, bundleNameOfProvider); +} + +void SubscribeRdbDataFuzz(FuzzedDataProvider &provider) +{ + std::shared_ptr dataShareServiceImpl = std::make_shared(); + uint8_t len = provider.ConsumeIntegral(); + std::vector uris(len); + for (int i = 0; i < len; i++) { + std::string uri = provider.ConsumeRandomLengthString(); + uris[i] = uri; + } + TemplateId id; + id.subscriberId_ = provider.ConsumeIntegral(); + id.bundleName_ = provider.ConsumeRandomLengthString(); + sptr observer; + dataShareServiceImpl->SubscribeRdbData(uris, id, observer); +} + +void EnableRdbSubsFuzz(FuzzedDataProvider &provider) +{ + std::shared_ptr dataShareServiceImpl = std::make_shared(); + uint8_t len = provider.ConsumeIntegral(); + std::vector uris(len); + for (int i = 0; i < len; i++) { + std::string uri = provider.ConsumeRandomLengthString(); + uris[i] = uri; + } + TemplateId id; + id.subscriberId_ = provider.ConsumeIntegral(); + id.bundleName_ = provider.ConsumeRandomLengthString(); + dataShareServiceImpl->EnableRdbSubs(uris, id); +} + +void SubscribePublishedDataFuzz(FuzzedDataProvider &provider) +{ + std::shared_ptr dataShareServiceImpl = std::make_shared(); + uint8_t len = provider.ConsumeIntegral(); + std::vector uris(len); + for (int i = 0; i < len; i++) { + std::string uri = provider.ConsumeRandomLengthString(); + uris[i] = uri; + } + int64_t subscriberId = provider.ConsumeIntegral(); + sptr observer; + dataShareServiceImpl->SubscribePublishedData(uris, subscriberId, observer); +} + +void DisablePubSubsFuzz(FuzzedDataProvider &provider) +{ + std::shared_ptr dataShareServiceImpl = std::make_shared(); + uint8_t len = provider.ConsumeIntegral(); + std::vector uris(len); + for (int i = 0; i < len; i++) { + std::string uri = provider.ConsumeRandomLengthString(); + uris[i] = uri; + } + int64_t subscriberId = provider.ConsumeIntegral(); + dataShareServiceImpl->DisablePubSubs(uris, subscriberId); +} + +void SaveLaunchInfoFuzz(FuzzedDataProvider &provider) +{ + std::shared_ptr dataShareServiceImpl = std::make_shared(); + std::string userId = provider.ConsumeRandomLengthString(); + std::string deviceId = provider.ConsumeRandomLengthString(); + std::string bundleName = provider.ConsumeRandomLengthString(); + dataShareServiceImpl->SaveLaunchInfo(bundleName, userId, deviceId); +} + +void OnConnectDoneFuzz(FuzzedDataProvider &provider) +{ + std::shared_ptr dataShareServiceImpl = std::make_shared(); + dataShareServiceImpl->OnConnectDone(); +} + +void DataShareStaticOnAppUpdate(FuzzedDataProvider &provider) +{ + DataShareServiceImpl::DataShareStatic dataShareStatic; + std::string bundleName = provider.ConsumeRandomLengthString(); + int32_t user = provider.ConsumeIntegral(); + int32_t index = provider.ConsumeIntegral(); + dataShareStatic.OnAppUpdate(bundleName, user, index); +} + +void EnableSilentProxyFuzz(FuzzedDataProvider &provider) +{ + std::shared_ptr dataShareServiceImpl = std::make_shared(); + std::string uri = provider.ConsumeRandomLengthString(); + bool enable = provider.ConsumeBool(); + dataShareServiceImpl->EnableSilentProxy(uri, enable); +} } // namespace OHOS /* Fuzzer entry point */ @@ -246,5 +383,17 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) OHOS::DataShareStaticOnAppUninstall(provider); OHOS::AllowCleanDataLaunchAppFuzz(provider); OHOS::AutoLaunchFuzz(provider); + OHOS::UpdateExFuzz(provider); + OHOS::DeleteExFuzz(provider); + OHOS::DelTemplateFuzz(provider); + OHOS::PublishFuzz(provider); + OHOS::SubscribeRdbDataFuzz(provider); + OHOS::EnableRdbSubsFuzz(provider); + OHOS::SubscribePublishedDataFuzz(provider); + OHOS::DisablePubSubsFuzz(provider); + OHOS::SaveLaunchInfoFuzz(provider); + OHOS::OnConnectDoneFuzz(provider); + OHOS::DataShareStaticOnAppUpdate(provider); + OHOS::EnableSilentProxyFuzz(provider); return 0; } \ No newline at end of file