From a1f699c75b51c3f08a41ae2f55d4049869984eef Mon Sep 17 00:00:00 2001 From: gaojiaqi Date: Thu, 15 May 2025 19:38:56 +0800 Subject: [PATCH 1/2] update fuzz test Signed-off-by: gaojiaqi --- .../reminderdatamanagercancel_fuzzer/BUILD.gn | 66 ++++++ .../corpus/init | 1 + .../project.xml | 25 +++ .../reminderdatamanagercancel_fuzzer.cpp | 58 ++++++ .../reminderdatamanagercancel_fuzzer.h | 23 +++ .../reminderdatamanagerevent_fuzzer/BUILD.gn | 66 ++++++ .../corpus/init | 1 + .../project.xml | 25 +++ .../reminderdatamanagerevent_fuzzer.cpp | 189 ++++++++++++++++++ .../reminderdatamanagerevent_fuzzer.h | 23 +++ .../reminderhelper_fuzzer/corpus/init | 14 +- .../reminderhelper_fuzzer.cpp | 2 +- .../reminderrequest_fuzzer/corpus/init | 14 +- .../reminderrequestalarm_fuzzer/corpus/init | 14 +- .../reminderrequestannex_fuzzer/corpus/init | 14 +- .../reminderrequestannex_fuzzer.cpp | 4 +- .../corpus/init | 14 +- .../reminderrequestannexthree_fuzzer.cpp | 2 +- .../corpus/init | 14 +- .../corpus/init | 14 +- .../reminderrequestcontinuate_fuzzer.cpp | 1 - .../reminderrequesttimer_fuzzer/corpus/init | 14 +- .../reminderrequesttimer_fuzzer.cpp | 2 +- .../reminderservice_fuzzer/corpus/init | 14 +- .../reminderstoreDeleteBase_fuzzer/BUILD.gn | 59 ++++++ .../corpus/init | 1 + .../project.xml | 25 +++ .../reminderstoredeletebase_fuzzer.cpp | 45 +++++ .../reminderstoredeletebase_fuzzer.h | 23 +++ .../reminderstoreDelete_fuzzer/BUILD.gn | 59 ++++++ .../reminderstoreDelete_fuzzer/corpus/init | 1 + .../reminderstoreDelete_fuzzer/project.xml | 25 +++ .../reminderstoredelete_fuzzer.cpp | 46 +++++ .../reminderstoredelete_fuzzer.h | 23 +++ .../reminderstoreannex_fuzzer/corpus/init | 14 +- 35 files changed, 799 insertions(+), 136 deletions(-) create mode 100644 test/fuzztest/reminderdatamanagercancel_fuzzer/BUILD.gn create mode 100644 test/fuzztest/reminderdatamanagercancel_fuzzer/corpus/init create mode 100644 test/fuzztest/reminderdatamanagercancel_fuzzer/project.xml create mode 100644 test/fuzztest/reminderdatamanagercancel_fuzzer/reminderdatamanagercancel_fuzzer.cpp create mode 100644 test/fuzztest/reminderdatamanagercancel_fuzzer/reminderdatamanagercancel_fuzzer.h create mode 100644 test/fuzztest/reminderdatamanagerevent_fuzzer/BUILD.gn create mode 100644 test/fuzztest/reminderdatamanagerevent_fuzzer/corpus/init create mode 100644 test/fuzztest/reminderdatamanagerevent_fuzzer/project.xml create mode 100644 test/fuzztest/reminderdatamanagerevent_fuzzer/reminderdatamanagerevent_fuzzer.cpp create mode 100644 test/fuzztest/reminderdatamanagerevent_fuzzer/reminderdatamanagerevent_fuzzer.h create mode 100644 test/fuzztest/reminderstoreDeleteBase_fuzzer/BUILD.gn create mode 100644 test/fuzztest/reminderstoreDeleteBase_fuzzer/corpus/init create mode 100644 test/fuzztest/reminderstoreDeleteBase_fuzzer/project.xml create mode 100644 test/fuzztest/reminderstoreDeleteBase_fuzzer/reminderstoredeletebase_fuzzer.cpp create mode 100644 test/fuzztest/reminderstoreDeleteBase_fuzzer/reminderstoredeletebase_fuzzer.h create mode 100644 test/fuzztest/reminderstoreDelete_fuzzer/BUILD.gn create mode 100644 test/fuzztest/reminderstoreDelete_fuzzer/corpus/init create mode 100644 test/fuzztest/reminderstoreDelete_fuzzer/project.xml create mode 100644 test/fuzztest/reminderstoreDelete_fuzzer/reminderstoredelete_fuzzer.cpp create mode 100644 test/fuzztest/reminderstoreDelete_fuzzer/reminderstoredelete_fuzzer.h diff --git a/test/fuzztest/reminderdatamanagercancel_fuzzer/BUILD.gn b/test/fuzztest/reminderdatamanagercancel_fuzzer/BUILD.gn new file mode 100644 index 000000000..f02a8b996 --- /dev/null +++ b/test/fuzztest/reminderdatamanagercancel_fuzzer/BUILD.gn @@ -0,0 +1,66 @@ +# Copyright (c) 2024 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +#####################hydra-fuzz################### +import("//base/notification/distributed_notification_service/notification.gni") +import("//build/config/features.gni") +import("//build/test.gni") + +##############################fuzztest########################################## +ohos_fuzztest("ReminderDataManagerCancelFuzzTest") { + module_out_path = service_fuzz_test_path + fuzz_config_file = + "${component_path}/test/fuzztest/reminderdatamanagercancel_fuzzer" + + include_dirs = [ + "${component_path}/test/fuzztest/fuzz_common_base", + "${component_path}/services/reminder/include", + ] + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + "-Dprivate=public", + "-Dprotected=public", + ] + sources = [ "reminderdatamanagercancel_fuzzer.cpp" ] + + deps = [ + "${component_path}/test/fuzztest/fuzz_common_base:fuzz_common_base", + "${frameworks_module_reminder_path}:reminder_innerkits", + "${services_path}/reminder:libreminder_static", + ] + + external_deps = [ + "ability_base:want", + "ability_base:zuri", + "bundle_framework:appexecfwk_base", + "bundle_framework:appexecfwk_core", + "c_utils:utils", + "data_share:datashare_common", + "ffrt:libffrt", + "hilog:libhilog", + "image_framework:image_native", + "kv_store:distributeddata_inner", + "relational_store:native_rdb", + "time_service:time_client", + ] +} + +############################################################################### +group("fuzztest") { + testonly = true + deps = [ ":ReminderDataManagerCancelFuzzTest" ] +} +############################################################################### diff --git a/test/fuzztest/reminderdatamanagercancel_fuzzer/corpus/init b/test/fuzztest/reminderdatamanagercancel_fuzzer/corpus/init new file mode 100644 index 000000000..b8e924d67 --- /dev/null +++ b/test/fuzztest/reminderdatamanagercancel_fuzzer/corpus/init @@ -0,0 +1 @@ +com.test.test060000000100DDC528600000000300000002000000010000000 \ No newline at end of file diff --git a/test/fuzztest/reminderdatamanagercancel_fuzzer/project.xml b/test/fuzztest/reminderdatamanagercancel_fuzzer/project.xml new file mode 100644 index 000000000..7133b2b92 --- /dev/null +++ b/test/fuzztest/reminderdatamanagercancel_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/test/fuzztest/reminderdatamanagercancel_fuzzer/reminderdatamanagercancel_fuzzer.cpp b/test/fuzztest/reminderdatamanagercancel_fuzzer/reminderdatamanagercancel_fuzzer.cpp new file mode 100644 index 000000000..922680004 --- /dev/null +++ b/test/fuzztest/reminderdatamanagercancel_fuzzer/reminderdatamanagercancel_fuzzer.cpp @@ -0,0 +1,58 @@ +/* + * 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 "reminder_data_manager.h" +#include "reminder_request_timer.h" +#include "reminderdatamanagercancel_fuzzer.h" +#include + +namespace OHOS { + bool DoSomethingInteresting(FuzzedDataProvider* fdp) + { + Notification::ReminderDataManager::InitInstance(); + auto manager = Notification::ReminderDataManager::GetInstance(); + + int32_t userId = fdp->ConsumeIntegral(); + int32_t uid = fdp->ConsumeIntegral(); + int32_t reminderId = fdp->ConsumeIntegral(); + uint64_t date = fdp->ConsumeIntegral(); + uint8_t type = fdp->ConsumeIntegral() % 2; + int32_t callingUid = fdp->ConsumeIntegral(); + bool value = fdp->ConsumeBool(); + std::string bundleName = fdp->ConsumeRandomLengthString(); + manager->CancelAllReminders(bundleName, userId, uid); + manager->CancelReminder(reminderId, callingUid); + manager->CheckExcludeDateParam(reminderId, callingUid); + manager->AddExcludeDate(reminderId, date, callingUid); + manager->DelExcludeDates(reminderId, callingUid); + std::vector dates; + manager->GetExcludeDates(reminderId, callingUid, dates); + std::vector reminders; + manager->GetValidReminders(callingUid, reminders); + manager->OnUserRemove(userId); + manager->OnUserSwitch(userId); + manager->OnProcessDiedLocked(callingUid); + return true; + } +} + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data */ + FuzzedDataProvider fdp(data, size); + OHOS::DoSomethingInteresting(&fdp); + return 0; +} diff --git a/test/fuzztest/reminderdatamanagercancel_fuzzer/reminderdatamanagercancel_fuzzer.h b/test/fuzztest/reminderdatamanagercancel_fuzzer/reminderdatamanagercancel_fuzzer.h new file mode 100644 index 000000000..6f667a2eb --- /dev/null +++ b/test/fuzztest/reminderdatamanagercancel_fuzzer/reminderdatamanagercancel_fuzzer.h @@ -0,0 +1,23 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef TEST_FUZZTEST_REMINDERDATAMANAGER_FUZZER_REMINDERDATAMANAGERCANCEL_FUZZER_H +#define TEST_FUZZTEST_REMINDERDATAMANAGER_FUZZER_REMINDERDATAMANAGERCANCEL_FUZZER_H + +#include "fuzz_common_base.h" + +#define FUZZ_PROJECT_NAME "reminderdatamanagercancel_fuzzer" + +#endif // TEST_FUZZTEST_REMINDERDATAMANAGER_FUZZER_REMINDERDATAMANAGERCANCEL_FUZZER_H \ No newline at end of file diff --git a/test/fuzztest/reminderdatamanagerevent_fuzzer/BUILD.gn b/test/fuzztest/reminderdatamanagerevent_fuzzer/BUILD.gn new file mode 100644 index 000000000..dff74f5df --- /dev/null +++ b/test/fuzztest/reminderdatamanagerevent_fuzzer/BUILD.gn @@ -0,0 +1,66 @@ +# Copyright (c) 2024 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +#####################hydra-fuzz################### +import("//base/notification/distributed_notification_service/notification.gni") +import("//build/config/features.gni") +import("//build/test.gni") + +##############################fuzztest########################################## +ohos_fuzztest("ReminderDataManagerEventFuzzTest") { + module_out_path = service_fuzz_test_path + fuzz_config_file = + "${component_path}/test/fuzztest/reminderdatamanagerevent_fuzzer" + + include_dirs = [ + "${component_path}/test/fuzztest/fuzz_common_base", + "${component_path}/services/reminder/include", + ] + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + "-Dprivate=public", + "-Dprotected=public", + ] + sources = [ "reminderdatamanagerevent_fuzzer.cpp" ] + + deps = [ + "${component_path}/test/fuzztest/fuzz_common_base:fuzz_common_base", + "${frameworks_module_reminder_path}:reminder_innerkits", + "${services_path}/reminder:libreminder_static", + ] + + external_deps = [ + "ability_base:want", + "ability_base:zuri", + "bundle_framework:appexecfwk_base", + "bundle_framework:appexecfwk_core", + "c_utils:utils", + "data_share:datashare_common", + "ffrt:libffrt", + "hilog:libhilog", + "image_framework:image_native", + "kv_store:distributeddata_inner", + "relational_store:native_rdb", + "time_service:time_client", + ] +} + +############################################################################### +group("fuzztest") { + testonly = true + deps = [ ":ReminderDataManagerEventFuzzTest" ] +} +############################################################################### diff --git a/test/fuzztest/reminderdatamanagerevent_fuzzer/corpus/init b/test/fuzztest/reminderdatamanagerevent_fuzzer/corpus/init new file mode 100644 index 000000000..c86439057 --- /dev/null +++ b/test/fuzztest/reminderdatamanagerevent_fuzzer/corpus/init @@ -0,0 +1 @@ +6749326A54377050307053307552367A4F34704A060000000100DDC528600000000300000002000000010000000 \ No newline at end of file diff --git a/test/fuzztest/reminderdatamanagerevent_fuzzer/project.xml b/test/fuzztest/reminderdatamanagerevent_fuzzer/project.xml new file mode 100644 index 000000000..7133b2b92 --- /dev/null +++ b/test/fuzztest/reminderdatamanagerevent_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/test/fuzztest/reminderdatamanagerevent_fuzzer/reminderdatamanagerevent_fuzzer.cpp b/test/fuzztest/reminderdatamanagerevent_fuzzer/reminderdatamanagerevent_fuzzer.cpp new file mode 100644 index 000000000..16cb60883 --- /dev/null +++ b/test/fuzztest/reminderdatamanagerevent_fuzzer/reminderdatamanagerevent_fuzzer.cpp @@ -0,0 +1,189 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "reminder_data_manager.h" +#include "reminder_request_timer.h" +#include "reminderdatamanagerevent_fuzzer.h" +#include + +namespace OHOS { + bool DoSomethingInterestingWithManager(FuzzedDataProvider* fdp) + { + Notification::ReminderDataManager::InitInstance(); + auto manager = Notification::ReminderDataManager::GetInstance(); + + int32_t userId = fdp->ConsumeIntegral(); + int32_t uid = fdp->ConsumeIntegral(); + int32_t reminderId = fdp->ConsumeIntegral(); + uint64_t date = fdp->ConsumeIntegral(); + uint8_t type = fdp->ConsumeIntegral() % 2; + int32_t callingUid = fdp->ConsumeIntegral(); + bool value = fdp->ConsumeBool(); + std::string bundleName = fdp->ConsumeRandomLengthString(); + + EventFwk::Want want; + want.SetParam(Notification::ReminderRequest::PARAM_REMINDER_ID, reminderId); + manager->CloseReminder(want, value); + manager->RefreshRemindersDueToSysTimeChange(type); + manager->ShouldAlert(reminder); + manager->ShowActiveReminder(want); + manager->SnoozeReminder(want); + manager->HandleCustomButtonClick(want); + manager->ClickReminder(want); + manager->TerminateAlerting(want); + return true; + } + + bool DoSomethingInterestingWithReminder(FuzzedDataProvider* fdp) + { + std::string bundleName = fdp->ConsumeRandomLengthString(); + int32_t userId = fdp->ConsumeIntegral(); + int32_t uid = fdp->ConsumeIntegral(); + int32_t reminderId = fdp->ConsumeIntegral(); + bool value = fdp->ConsumeBool(); + int32_t callingUid = fdp->ConsumeIntegral(); + constexpr uint64_t seconds = 1200; + sptr reminder = new Notification::ReminderRequestTimer(seconds); + auto manager = Notification::ReminderDataManager::GetInstance(); + + manager->CancelAllReminders(userId); + manager->CheckUpdateConditions(reminder, Notification::ReminderRequest::ActionButtonType::INVALID, + reminder->GetActionButtons()); + manager->CancelRemindersImplLocked(bundleName, userId, uid, value); + manager->CloseRemindersByGroupId(reminderId, bundleName, bundleName); + manager->CancelNotification(reminder); + manager->CheckReminderLimitExceededLocked(callingUid, reminder); + std::vector> reminders; + manager->GetImmediatelyShowRemindersLocked(reminders); + manager->AddToShowedReminders(reminder); + + manager->IsAllowedNotify(reminder); + manager->PlaySoundAndVibrationLocked(reminder); + manager->PlaySoundAndVibration(reminder); + manager->StopSoundAndVibrationLocked(reminder); + manager->StopSoundAndVibration(reminder); + manager->RemoveFromShowedReminders(reminder); + manager->RemoveReminderLocked(reminderId, false); + manager->SetActiveReminder(reminder); + manager->SetAlertingReminder(reminder); + manager->ShowActiveReminderExtendLocked(reminder, reminders); + + std::vector> extensionReminders; + std::vector> immediatelyReminders; + manager->PublishReminder(reminder, callingUid); + manager->FindReminderRequestLocked(reminderId, false); + manager->HandleImmediatelyShow(immediatelyReminders, value); + int8_t type = fdp->ConsumeIntegral(); + manager->HandleExtensionReminder(extensionReminders, type); + manager->HandleSameNotificationIdShowing(reminder); + manager->IsBelongToSameApp(uid, uid); + manager->CheckIsSameApp(reminder, uid); + manager->ShowReminder(reminder, value, value, value, value); + return true; + } + + bool DoSomethingInteresting1(FuzzedDataProvider* fdp) + { + std::string bundleName = fdp->ConsumeRandomLengthString(); + int32_t id = fdp->ConsumeIntegral(); + int64_t ts = fdp->ConsumeIntegral(); + int32_t reminderId = fdp->ConsumeIntegral(); + bool value = fdp->ConsumeBool(); + int32_t callingUid = fdp->ConsumeIntegral(); + constexpr uint64_t seconds = 1200; + sptr reminder = new Notification::ReminderRequestTimer(seconds); + auto manager = Notification::ReminderDataManager::GetInstance(); + std::map> remindersMap; + manager->OnDataShareUpdate(remindersMap); + manager->HandleAutoDeleteReminder(id, id, ts); + + std::vector> reminders; + manager->UpdateReminderLanguageLocked(id, reminders); + manager->InitShareReminders(value); + manager->UpdateAppDatabase(reminder, Notification::ReminderRequest::ActionButtonType::CLOSE); + DataShare::DataSharePredicates predicates; + std::vector equalToVector; + manager->GenPredicates(predicates, equalToVector); + DataShare::DataShareValuesBucket valuesBucket; + manager->GenValuesBucket(valuesBucket, equalToVector); + manager->CloseReminder(reminder, value); + Notification::ReminderDataManager::TimerType t = Notification::ReminderDataManager::TimerType::ALERTING_TIMER; + manager->CreateTimerInfo(t, reminder); + auto sharedTimerInfo = std::make_shared(); + manager->InitTimerInfo(sharedTimerInfo, reminder, t); + manager->HandleSysTimeChange(reminder); + manager->IsMatched(reminder, id, id, value); + manager->ResetStates(t); + return true; + } + + bool DoSomethingInteresting2(FuzzedDataProvider* fdp) + { + constexpr uint16_t MAX_SECOND = 5; + std::string bundleName = fdp->ConsumeRandomLengthString(); + std::string uri = fdp->ConsumeRandomLengthString(); + int32_t id = fdp->ConsumeIntegral(); + int8_t val = fdp->ConsumeIntegral(); + uint16_t second = fdp->ConsumeIntegral() % MAX_SECOND + 1; + int64_t ts = fdp->ConsumeIntegral(); + int32_t reminderId = fdp->ConsumeIntegral(); + bool value = fdp->ConsumeBool(); + int32_t callingUid = fdp->ConsumeIntegral(); + constexpr uint64_t seconds = 1200; + sptr reminder = new Notification::ReminderRequestTimer(seconds); + auto manager = Notification::ReminderDataManager::GetInstance(); + manager->IsMatchedForGroupIdAndPkgName(reminder, bundleName, uri); + manager->StartExtensionAbility(reminder, 0); + int32_t count = 0; + manager->AsyncStartExtensionAbility(reminder, id, val, count); + manager->SnoozeReminderImpl(reminder); + Notification::ReminderDataManager::TimerType t = Notification::ReminderDataManager::TimerType::ALERTING_TIMER; + manager->StartTimerLocked(reminder, t); + manager->StartTimer(reminder, t); + manager->StopAlertingReminder(reminder); + manager->StopTimer(t); + manager->StopTimerLocked(t); + manager->TerminateAlerting(reminder, uri); + manager->TerminateAlerting(second, reminder); + manager->UpdateAndSaveReminderLocked(reminder); + Notification::ReminderDataManager::cmp(reminder, reminder); + manager->CheckNeedNotifyStatus(reminder, Notification::ReminderRequest::ActionButtonType::INVALID); + manager->GetFullPath(uri); + manager->IsActionButtonDataShareValid(reminder, static_cast(id)); + manager->GetResourceMgr(bundleName, id); + Global::Resource::ResourceManager::RawFileDescriptor desc; + manager->GetCustomRingFileDesc(reminder, desc); + manager->CloseCustomRingFileDesc(id, uri); + manager->ReportSysEvent(reminder); + std::map> reminders; + manager->UpdateShareReminders(reminders); + std::unordered_map limits; + int32_t totalCount = 0; + manager->CheckShowLimit(limits, totalCount, reminder); + return true; + } +} + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data */ + FuzzedDataProvider fdp(data, size); + OHOS::DoSomethingInterestingWithManager(&fdp); + OHOS::DoSomethingInterestingWithReminder(&fdp); + OHOS::DoSomethingInteresting1(&fdp); + OHOS::DoSomethingInteresting2(&fdp); + return 0; +} diff --git a/test/fuzztest/reminderdatamanagerevent_fuzzer/reminderdatamanagerevent_fuzzer.h b/test/fuzztest/reminderdatamanagerevent_fuzzer/reminderdatamanagerevent_fuzzer.h new file mode 100644 index 000000000..91f91b6b6 --- /dev/null +++ b/test/fuzztest/reminderdatamanagerevent_fuzzer/reminderdatamanagerevent_fuzzer.h @@ -0,0 +1,23 @@ +/* + * Copyright (c) 2024 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef TEST_FUZZTEST_REMINDERDATAMANAGER_FUZZER_REMINDERDATAMANAGEREVENT_FUZZER_H +#define TEST_FUZZTEST_REMINDERDATAMANAGER_FUZZER_REMINDERDATAMANAGEREVENT_FUZZER_H + +#include "fuzz_common_base.h" + +#define FUZZ_PROJECT_NAME "reminderdatamanagerevent_fuzzer" + +#endif // TEST_FUZZTEST_REMINDERDATAMANAGER_FUZZER_REMINDERDATAMANAGEREVENT_FUZZER_H \ No newline at end of file diff --git a/test/fuzztest/reminderhelper_fuzzer/corpus/init b/test/fuzztest/reminderhelper_fuzzer/corpus/init index 1b910144f..14bec243d 100644 --- a/test/fuzztest/reminderhelper_fuzzer/corpus/init +++ b/test/fuzztest/reminderhelper_fuzzer/corpus/init @@ -1,13 +1 @@ -# Copyright (c) 2022 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 +1000000000000000100000006154306D4239744A316448357742327248307247 \ No newline at end of file diff --git a/test/fuzztest/reminderhelper_fuzzer/reminderhelper_fuzzer.cpp b/test/fuzztest/reminderhelper_fuzzer/reminderhelper_fuzzer.cpp index 0badeeea5..14389d7cb 100644 --- a/test/fuzztest/reminderhelper_fuzzer/reminderhelper_fuzzer.cpp +++ b/test/fuzztest/reminderhelper_fuzzer/reminderhelper_fuzzer.cpp @@ -32,7 +32,7 @@ namespace OHOS { std::vector validReminders; validReminders.emplace_back(valid); Notification::ReminderHelper::GetValidReminders(validReminders); - uint64_t excludeDate = static_cast(reminderId); + uint64_t excludeDate = fdp->ConsumeIntegral(); Notification::ReminderHelper::AddExcludeDate(reminderId, excludeDate); Notification::ReminderHelper::DelExcludeDates(reminderId); std::vector dates; diff --git a/test/fuzztest/reminderrequest_fuzzer/corpus/init b/test/fuzztest/reminderrequest_fuzzer/corpus/init index 1b910144f..6dd3d7d94 100644 --- a/test/fuzztest/reminderrequest_fuzzer/corpus/init +++ b/test/fuzztest/reminderrequest_fuzzer/corpus/init @@ -1,13 +1 @@ -# Copyright (c) 2022 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 +101000000000000000100000000000000010000000000000001000000000000000100000000000000010100010000000674630765133764C336E5637624233664E316651 \ No newline at end of file diff --git a/test/fuzztest/reminderrequestalarm_fuzzer/corpus/init b/test/fuzztest/reminderrequestalarm_fuzzer/corpus/init index 1b910144f..3ba845cfe 100644 --- a/test/fuzztest/reminderrequestalarm_fuzzer/corpus/init +++ b/test/fuzztest/reminderrequestalarm_fuzzer/corpus/init @@ -1,13 +1 @@ -# Copyright (c) 2022 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 +1010101010 \ No newline at end of file diff --git a/test/fuzztest/reminderrequestannex_fuzzer/corpus/init b/test/fuzztest/reminderrequestannex_fuzzer/corpus/init index 1b910144f..e21041f65 100644 --- a/test/fuzztest/reminderrequestannex_fuzzer/corpus/init +++ b/test/fuzztest/reminderrequestannex_fuzzer/corpus/init @@ -1,13 +1 @@ -# Copyright (c) 2022 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 +10000000000000001000000000000000101010000000664B39635538705A33764C357047377158327751 \ No newline at end of file diff --git a/test/fuzztest/reminderrequestannex_fuzzer/reminderrequestannex_fuzzer.cpp b/test/fuzztest/reminderrequestannex_fuzzer/reminderrequestannex_fuzzer.cpp index 03a0f77aa..86fd5808b 100644 --- a/test/fuzztest/reminderrequestannex_fuzzer/reminderrequestannex_fuzzer.cpp +++ b/test/fuzztest/reminderrequestannex_fuzzer/reminderrequestannex_fuzzer.cpp @@ -27,7 +27,7 @@ namespace OHOS { reminderRequest.SetSnoozeTimes(snoozeTimes); uint8_t snooziTimes = fdp->ConsumeIntegral(); reminderRequest.SetSnoozeTimesDynamic(snooziTimes); - uint64_t timeIntervalInSeconds = 1; + uint64_t timeIntervalInSeconds = fdp->ConsumeIntegral(); reminderRequest.SetTimeInterval(timeIntervalInSeconds); reminderRequest.SetTitle(stringData); reminderRequest.SetTriggerTimeInMilli(timeIntervalInSeconds); @@ -44,7 +44,7 @@ namespace OHOS { reminderRequest.GetReminderTimeInMilli(); reminderRequest.SetReminderId(reminderId); reminderRequest.SetReminderTimeInMilli(timeIntervalInSeconds); - uint64_t ringDurationInSeconds = 0; + uint64_t ringDurationInSeconds = fdp->ConsumeIntegral(); reminderRequest.SetRingDuration(ringDurationInSeconds); reminderRequest.GetSlotType(); reminderRequest.GetSnoozeContent(); diff --git a/test/fuzztest/reminderrequestannexthree_fuzzer/corpus/init b/test/fuzztest/reminderrequestannexthree_fuzzer/corpus/init index 1b910144f..7a606b61b 100644 --- a/test/fuzztest/reminderrequestannexthree_fuzzer/corpus/init +++ b/test/fuzztest/reminderrequestannexthree_fuzzer/corpus/init @@ -1,13 +1 @@ -# Copyright (c) 2022 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 +10100000000000000010000000 \ No newline at end of file diff --git a/test/fuzztest/reminderrequestannexthree_fuzzer/reminderrequestannexthree_fuzzer.cpp b/test/fuzztest/reminderrequestannexthree_fuzzer/reminderrequestannexthree_fuzzer.cpp index 06db4eb59..a328085b2 100644 --- a/test/fuzztest/reminderrequestannexthree_fuzzer/reminderrequestannexthree_fuzzer.cpp +++ b/test/fuzztest/reminderrequestannexthree_fuzzer/reminderrequestannexthree_fuzzer.cpp @@ -23,7 +23,7 @@ namespace OHOS { int32_t reminderId = fdp->ConsumeIntegral(); Notification::ReminderRequest reminderRequest(reminderId); reminderRequest.GetTitle(); - uint64_t showTime = 2; + uint64_t showTime = fdp->ConsumeIntegral(); reminderRequest.ReminderRequest::GetShowTime(showTime); Notification::ReminderRequest::TimeTransferType type = Notification::ReminderRequest::TimeTransferType::YEAR; int32_t cTime = static_cast(fdp->ConsumeIntegral()); diff --git a/test/fuzztest/reminderrequestcalendar_fuzzer/corpus/init b/test/fuzztest/reminderrequestcalendar_fuzzer/corpus/init index 1b910144f..01a8e0bd5 100644 --- a/test/fuzztest/reminderrequestcalendar_fuzzer/corpus/init +++ b/test/fuzztest/reminderrequestcalendar_fuzzer/corpus/init @@ -1,13 +1 @@ -# Copyright (c) 2022 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 +10101001101101010 \ No newline at end of file diff --git a/test/fuzztest/reminderrequestcontinuate_fuzzer/corpus/init b/test/fuzztest/reminderrequestcontinuate_fuzzer/corpus/init index 1b910144f..3b906d1ab 100644 --- a/test/fuzztest/reminderrequestcontinuate_fuzzer/corpus/init +++ b/test/fuzztest/reminderrequestcontinuate_fuzzer/corpus/init @@ -1,13 +1 @@ -# Copyright (c) 2022 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 +10000000 \ No newline at end of file diff --git a/test/fuzztest/reminderrequestcontinuate_fuzzer/reminderrequestcontinuate_fuzzer.cpp b/test/fuzztest/reminderrequestcontinuate_fuzzer/reminderrequestcontinuate_fuzzer.cpp index 08fa581b0..cfbfb4bc5 100644 --- a/test/fuzztest/reminderrequestcontinuate_fuzzer/reminderrequestcontinuate_fuzzer.cpp +++ b/test/fuzztest/reminderrequestcontinuate_fuzzer/reminderrequestcontinuate_fuzzer.cpp @@ -20,7 +20,6 @@ namespace OHOS { bool DoSomethingInterestingWithMyAPI(FuzzedDataProvider* fdp) { - std::string stringData = fdp->ConsumeRandomLengthString(); int32_t reminderId = fdp->ConsumeIntegral(); Notification::ReminderRequest reminderRequest(reminderId); reminderRequest.SerializeButtonInfo(); diff --git a/test/fuzztest/reminderrequesttimer_fuzzer/corpus/init b/test/fuzztest/reminderrequesttimer_fuzzer/corpus/init index 1b910144f..7dac61a86 100644 --- a/test/fuzztest/reminderrequesttimer_fuzzer/corpus/init +++ b/test/fuzztest/reminderrequesttimer_fuzzer/corpus/init @@ -1,13 +1 @@ -# Copyright (c) 2022 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 +06E4C30724B366151366254366A45336A43377257A000000000000000 \ No newline at end of file diff --git a/test/fuzztest/reminderrequesttimer_fuzzer/reminderrequesttimer_fuzzer.cpp b/test/fuzztest/reminderrequesttimer_fuzzer/reminderrequesttimer_fuzzer.cpp index a38eb921e..893a2f565 100644 --- a/test/fuzztest/reminderrequesttimer_fuzzer/reminderrequesttimer_fuzzer.cpp +++ b/test/fuzztest/reminderrequesttimer_fuzzer/reminderrequesttimer_fuzzer.cpp @@ -20,7 +20,7 @@ namespace OHOS { bool DoSomethingInterestingWithMyAPI(FuzzedDataProvider* fdp) { - uint64_t countDownTimeInSeconds = 0; + uint64_t countDownTimeInSeconds = fdp->ConsumeIntegral(); std::string stringData = fdp->ConsumeRandomLengthString(); Notification::ReminderRequestTimer reminderRequestTimer(countDownTimeInSeconds); reminderRequestTimer.GetInitInfo(); diff --git a/test/fuzztest/reminderservice_fuzzer/corpus/init b/test/fuzztest/reminderservice_fuzzer/corpus/init index d6a927d54..d6a4df573 100644 --- a/test/fuzztest/reminderservice_fuzzer/corpus/init +++ b/test/fuzztest/reminderservice_fuzzer/corpus/init @@ -1,13 +1 @@ -# 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. -100 \ No newline at end of file +100000000000000010000000100000007A5A366658376A4A386E5A39664D36634C307059 \ No newline at end of file diff --git a/test/fuzztest/reminderstoreDeleteBase_fuzzer/BUILD.gn b/test/fuzztest/reminderstoreDeleteBase_fuzzer/BUILD.gn new file mode 100644 index 000000000..b0316c0cb --- /dev/null +++ b/test/fuzztest/reminderstoreDeleteBase_fuzzer/BUILD.gn @@ -0,0 +1,59 @@ +# Copyright (c) 2022 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("//base/notification/distributed_notification_service/notification.gni") +import("//build/config/features.gni") +import("//build/test.gni") + +##############################fuzztest########################################## +ohos_fuzztest("ReminderStoreDeleteBaseFuzzTest") { + module_out_path = service_fuzz_test_path + fuzz_config_file = "${component_path}/test/fuzztest/reminderstoredeletebase_fuzzer" + + include_dirs = [ + "${component_path}/test/fuzztest/fuzz_common_base", + "${component_path}/services/reminder/include", + ] + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + "-Dprivate=public", + "-Dprotected=public", + ] + sources = [ "reminderstoredeletebase_fuzzer.cpp" ] + + deps = [ + "${component_path}/test/fuzztest/fuzz_common_base:fuzz_common_base", + "${frameworks_module_reminder_path}:reminder_innerkits", + "${services_path}/reminder:libreminder_static", + ] + + external_deps = [ + "ability_base:want", + "ability_base:zuri", + "c_utils:utils", + "hilog:libhilog", + "image_framework:image_native", + "relational_store:native_rdb", + ] +} + +############################################################################### +group("fuzztest") { + testonly = true + deps = [ ":ReminderStoreDeleteBaseFuzzTest" ] +} +############################################################################### diff --git a/test/fuzztest/reminderstoreDeleteBase_fuzzer/corpus/init b/test/fuzztest/reminderstoreDeleteBase_fuzzer/corpus/init new file mode 100644 index 000000000..882c6f8d5 --- /dev/null +++ b/test/fuzztest/reminderstoreDeleteBase_fuzzer/corpus/init @@ -0,0 +1 @@ +100000006749326A54377050307053307552367A4F34704A \ No newline at end of file diff --git a/test/fuzztest/reminderstoreDeleteBase_fuzzer/project.xml b/test/fuzztest/reminderstoreDeleteBase_fuzzer/project.xml new file mode 100644 index 000000000..6e8ad2cfd --- /dev/null +++ b/test/fuzztest/reminderstoreDeleteBase_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/test/fuzztest/reminderstoreDeleteBase_fuzzer/reminderstoredeletebase_fuzzer.cpp b/test/fuzztest/reminderstoreDeleteBase_fuzzer/reminderstoredeletebase_fuzzer.cpp new file mode 100644 index 000000000..f0868236d --- /dev/null +++ b/test/fuzztest/reminderstoreDeleteBase_fuzzer/reminderstoredeletebase_fuzzer.cpp @@ -0,0 +1,45 @@ +/* + * Copyright (c) 2022 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 "reminder_store.h" +#include "reminderstoredeletebase_fuzzer.h" +#include "abs_shared_result_set.h" +#include "reminder_request_alarm.h" +#include "reminder_request_timer.h" +#include "reminder_store_strategy.h" +#include "reminder_request_calendar.h" +#include + +namespace OHOS { + bool DoSomethingInterestingWithMyAPI(FuzzedDataProvider* fdp) + { + Notification::ReminderStore reminderStore; + reminderStore.Init(); + std::string stringData = fdp->ConsumeRandomLengthString(); + int32_t oldVersion = fdp->ConsumeIntegral(); + reminderStore.DeleteUser(oldVersion); + reminderStore.DeleteBase(stringData); + return true; + } +} + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data */ + FuzzedDataProvider fdp(data, size); + OHOS::DoSomethingInterestingWithMyAPI(&fdp); + return 0; +} diff --git a/test/fuzztest/reminderstoreDeleteBase_fuzzer/reminderstoredeletebase_fuzzer.h b/test/fuzztest/reminderstoreDeleteBase_fuzzer/reminderstoredeletebase_fuzzer.h new file mode 100644 index 000000000..17a4e0b3d --- /dev/null +++ b/test/fuzztest/reminderstoreDeleteBase_fuzzer/reminderstoredeletebase_fuzzer.h @@ -0,0 +1,23 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef TEST_FUZZTEST_REMINDERSTORE_FUZZER_REMINDERSTOREDELETEBASE_FUZZER_H +#define TEST_FUZZTEST_REMINDERSTORE_FUZZER_REMINDERSTOREDELETEBASE_FUZZER_H + +#include "fuzz_common_base.h" + +#define FUZZ_PROJECT_NAME "reminderstoredeletebase_fuzzer" + +#endif // TEST_FUZZTEST_REMINDERSTORE_FUZZER_REMINDERSTOREDELETEBASE_FUZZER_H \ No newline at end of file diff --git a/test/fuzztest/reminderstoreDelete_fuzzer/BUILD.gn b/test/fuzztest/reminderstoreDelete_fuzzer/BUILD.gn new file mode 100644 index 000000000..b92bb4601 --- /dev/null +++ b/test/fuzztest/reminderstoreDelete_fuzzer/BUILD.gn @@ -0,0 +1,59 @@ +# Copyright (c) 2022 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("//base/notification/distributed_notification_service/notification.gni") +import("//build/config/features.gni") +import("//build/test.gni") + +##############################fuzztest########################################## +ohos_fuzztest("ReminderStoreDeleteFuzzTest") { + module_out_path = service_fuzz_test_path + fuzz_config_file = "${component_path}/test/fuzztest/reminderstoredelete_fuzzer" + + include_dirs = [ + "${component_path}/test/fuzztest/fuzz_common_base", + "${component_path}/services/reminder/include", + ] + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + "-Dprivate=public", + "-Dprotected=public", + ] + sources = [ "reminderstoredelete_fuzzer.cpp" ] + + deps = [ + "${component_path}/test/fuzztest/fuzz_common_base:fuzz_common_base", + "${frameworks_module_reminder_path}:reminder_innerkits", + "${services_path}/reminder:libreminder_static", + ] + + external_deps = [ + "ability_base:want", + "ability_base:zuri", + "c_utils:utils", + "hilog:libhilog", + "image_framework:image_native", + "relational_store:native_rdb", + ] +} + +############################################################################### +group("fuzztest") { + testonly = true + deps = [ ":ReminderStoreDeleteFuzzTest" ] +} +############################################################################### diff --git a/test/fuzztest/reminderstoreDelete_fuzzer/corpus/init b/test/fuzztest/reminderstoreDelete_fuzzer/corpus/init new file mode 100644 index 000000000..0587b3c58 --- /dev/null +++ b/test/fuzztest/reminderstoreDelete_fuzzer/corpus/init @@ -0,0 +1 @@ +20000000100000006749326A54377050307053307552367A4F34704A \ No newline at end of file diff --git a/test/fuzztest/reminderstoreDelete_fuzzer/project.xml b/test/fuzztest/reminderstoreDelete_fuzzer/project.xml new file mode 100644 index 000000000..6e8ad2cfd --- /dev/null +++ b/test/fuzztest/reminderstoreDelete_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/test/fuzztest/reminderstoreDelete_fuzzer/reminderstoredelete_fuzzer.cpp b/test/fuzztest/reminderstoreDelete_fuzzer/reminderstoredelete_fuzzer.cpp new file mode 100644 index 000000000..6dd8367ea --- /dev/null +++ b/test/fuzztest/reminderstoreDelete_fuzzer/reminderstoredelete_fuzzer.cpp @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2022 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 "reminder_store.h" +#include "reminderstoredelete_fuzzer.h" +#include "abs_shared_result_set.h" +#include "reminder_request_alarm.h" +#include "reminder_request_timer.h" +#include "reminder_store_strategy.h" +#include "reminder_request_calendar.h" +#include + +namespace OHOS { + bool DoSomethingInterestingWithMyAPI(FuzzedDataProvider* fdp) + { + Notification::ReminderStore reminderStore; + reminderStore.Init(); + std::string stringData = fdp->ConsumeRandomLengthString(); + int32_t userId = fdp->ConsumeIntegral(); + int32_t uid = fdp->ConsumeIntegral(); + reminderStore.Delete(uid); + reminderStore.Delete(stringData, userId, uid); + return true; + } +} + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data */ + FuzzedDataProvider fdp(data, size); + OHOS::DoSomethingInterestingWithMyAPI(&fdp); + return 0; +} diff --git a/test/fuzztest/reminderstoreDelete_fuzzer/reminderstoredelete_fuzzer.h b/test/fuzztest/reminderstoreDelete_fuzzer/reminderstoredelete_fuzzer.h new file mode 100644 index 000000000..7cce03b28 --- /dev/null +++ b/test/fuzztest/reminderstoreDelete_fuzzer/reminderstoredelete_fuzzer.h @@ -0,0 +1,23 @@ +/* + * Copyright (c) 2022 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef TEST_FUZZTEST_REMINDERSTORE_FUZZER_REMINDERSTOREDELETE_FUZZER_H +#define TEST_FUZZTEST_REMINDERSTORE_FUZZER_REMINDERSTOREDELETE_FUZZER_H + +#include "fuzz_common_base.h" + +#define FUZZ_PROJECT_NAME "reminderstoredelete_fuzzer" + +#endif // TEST_FUZZTEST_REMINDERSTORE_FUZZER_REMINDERSTOREDELETE_FUZZER_H \ No newline at end of file diff --git a/test/fuzztest/reminderstoreannex_fuzzer/corpus/init b/test/fuzztest/reminderstoreannex_fuzzer/corpus/init index 1b910144f..d3cf3935a 100644 --- a/test/fuzztest/reminderstoreannex_fuzzer/corpus/init +++ b/test/fuzztest/reminderstoreannex_fuzzer/corpus/init @@ -1,13 +1 @@ -# Copyright (c) 2022 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 +7A5A366658376A4A386E5A39664D36634C307059100000007053337A52336152307A4A36645735684C316B447053337A52336152307A4A36645735684C316B44 \ No newline at end of file -- Gitee From b71a2e5a25d78e5360455d4c6031045c038040e6 Mon Sep 17 00:00:00 2001 From: gaojiaqi Date: Tue, 3 Jun 2025 17:22:57 +0800 Subject: [PATCH 2/2] add ring loop param Signed-off-by: gaojiaqi --- frameworks/reminder/src/reminder_request.cpp | 10 ++++++++++ .../test/unittest/reminder_request_test.cpp | 15 +++++++++++++++ interfaces/inner_api/reminder_request.h | 7 +++++++ services/reminder/src/reminder_data_manager.cpp | 2 +- .../reminder/src/reminder_datashare_helper.cpp | 1 + 5 files changed, 34 insertions(+), 1 deletion(-) diff --git a/frameworks/reminder/src/reminder_request.cpp b/frameworks/reminder/src/reminder_request.cpp index 29832cd80..6254c33e4 100644 --- a/frameworks/reminder/src/reminder_request.cpp +++ b/frameworks/reminder/src/reminder_request.cpp @@ -954,6 +954,16 @@ ReminderRequest::RingChannel ReminderRequest::GetRingChannel() const return ringChannel_; } +void ReminderRequest::SetRingLoop(const bool isRingLoop) +{ + isRingLoop_ = isRingLoop; +} + +bool ReminderRequest::IsRingLoop() const +{ + return isRingLoop_; +} + int32_t ReminderRequest::GetUserId() const { return userId_; diff --git a/frameworks/reminder/test/unittest/reminder_request_test.cpp b/frameworks/reminder/test/unittest/reminder_request_test.cpp index 60b27de12..ff0c017af 100644 --- a/frameworks/reminder/test/unittest/reminder_request_test.cpp +++ b/frameworks/reminder/test/unittest/reminder_request_test.cpp @@ -2409,5 +2409,20 @@ HWTEST_F(ReminderRequestTest, ReminderRequestTest_006, Function | SmallTest | Le child.SetRingChannel(ReminderRequest::RingChannel::MEDIA); EXPECT_EQ(child.GetRingChannel(), ReminderRequest::RingChannel::MEDIA); } + +/** + * @tc.name: ReminderRequestTest_007 + * @tc.desc: Test RingLoop parameters. + * @tc.type: FUNC + * @tc.require: issueI8CDH3 + */ +HWTEST_F(ReminderRequestTest, ReminderRequestTest_007, Function | SmallTest | Level1) +{ + ReminderRequestChild child; + child.SetRingLoop(true); + EXPECT_EQ(child.IsRingLoop(), true); + child.SetRingLoop(false); + EXPECT_EQ(child.IsRingLoop(), false); +} } } diff --git a/interfaces/inner_api/reminder_request.h b/interfaces/inner_api/reminder_request.h index e3e414ec4..871350ba7 100644 --- a/interfaces/inner_api/reminder_request.h +++ b/interfaces/inner_api/reminder_request.h @@ -470,6 +470,12 @@ public: void SetRingChannel(const RingChannel channel); RingChannel GetRingChannel() const; + /** + * @brief Set/Get ring loop. + */ + void SetRingLoop(const bool isRingLoop); + bool IsRingLoop() const; + int32_t GetUserId() const; int32_t GetUid() const; @@ -1176,6 +1182,7 @@ private: int32_t uid_ {-1}; bool isSystemApp_ {false}; bool tapDismissed_ {true}; + bool isRingLoop_ {true}; int64_t autoDeletedTime_ {0}; std::string customButtonUri_ {}; std::string customRingUri_ {}; diff --git a/services/reminder/src/reminder_data_manager.cpp b/services/reminder/src/reminder_data_manager.cpp index d458c550c..dfdbdd2c2 100644 --- a/services/reminder/src/reminder_data_manager.cpp +++ b/services/reminder/src/reminder_data_manager.cpp @@ -1644,7 +1644,7 @@ void ReminderDataManager::PlaySoundAndVibration(const sptr &rem (void)format.PutIntValue(Media::PlayerKeys::STREAM_USAGE, STREAM_ALARM); (void)format.PutIntValue(Media::PlayerKeys::RENDERER_FLAG, DEFAULT_VALUE); soundPlayer_->SetParameter(format); - soundPlayer_->SetLooping(true); + soundPlayer_->SetLooping(reminder->IsRingLoop()); soundPlayer_->PrepareAsync(); soundPlayer_->Play(); #endif diff --git a/services/reminder/src/reminder_datashare_helper.cpp b/services/reminder/src/reminder_datashare_helper.cpp index f2b80e605..f3391be91 100644 --- a/services/reminder/src/reminder_datashare_helper.cpp +++ b/services/reminder/src/reminder_datashare_helper.cpp @@ -430,6 +430,7 @@ std::map> ReminderDataShareHelper::CreateRemi void ReminderDataShareHelper::InitNormalInfo(sptr& reminder) { reminder->SetRingDuration(0); + reminder->SetRingLoop(true); reminder->InitUserId(curUserId_); reminder->InitUid(uid_); reminder->InitCreatorUid(dataUid_); -- Gitee