From 4a99d172e46c9b1671eb944e6480b42eb618d209 Mon Sep 17 00:00:00 2001 From: wufarong Date: Wed, 2 Jul 2025 21:13:59 +0800 Subject: [PATCH] =?UTF-8?q?fuzz=E7=94=A8=E4=BE=8B=E8=A1=A5=E5=85=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: wufarong Change-Id: Ifed1b3f5d2201a7c6114e4d197e4d9a27967abd6 --- ...service_cancelasbundlewithagent_fuzzer.cpp | 15 +++++++++++++- ..._getalldistribuedenabledbundles_fuzzer.cpp | 20 ++++++++++++++++++- .../service_getdonotdisturbprofile_fuzzer.cpp | 18 +++++++++++++++-- .../service_getslotbybundle_fuzzer.cpp | 11 +++++++--- ..._isneedsilentindonotdisturbmode_fuzzer.cpp | 14 ++++++++++++- ...icationsenabledforspecialbundle_fuzzer.cpp | 17 +++++++++++++++- ...service_setsmartreminderenabled_fuzzer.cpp | 14 ++++++++++++- .../mock_notification_donotdisturb_profile.h | 2 +- .../mock/mock_notification_slot.h | 13 +++++------- 9 files changed, 105 insertions(+), 19 deletions(-) diff --git a/test/fuzztest/advancednotificationservice/servicecancelasbundlewithagent_fuzzer/service_cancelasbundlewithagent_fuzzer.cpp b/test/fuzztest/advancednotificationservice/servicecancelasbundlewithagent_fuzzer/service_cancelasbundlewithagent_fuzzer.cpp index 6e1dab8d7..fb6911a84 100644 --- a/test/fuzztest/advancednotificationservice/servicecancelasbundlewithagent_fuzzer/service_cancelasbundlewithagent_fuzzer.cpp +++ b/test/fuzztest/advancednotificationservice/servicecancelasbundlewithagent_fuzzer/service_cancelasbundlewithagent_fuzzer.cpp @@ -18,11 +18,18 @@ #include "advanced_notification_service.h" #include "ans_permission_def.h" #include "mock_notification_request.h" +#include "mock_notification_bundle_option.h" namespace OHOS { namespace Notification { bool DoSomethingInterestingWithMyAPI(FuzzedDataProvider *fuzzData) { + auto service = AdvancedNotificationService::GetInstance(); + service->InitPublishProcess(); + service->CreateDialogManager(); + sptr bundleOption = ObjectBuilder::Build(fuzzData); + int32_t intData = fuzzData->ConsumeIntegral(); + service->CancelAsBundleWithAgent(bundleOption, intData); return true; } } @@ -33,6 +40,12 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { /* Run your code on data */ FuzzedDataProvider fdp(data, size); + std::vector requestPermission = { + OHOS::Notification::OHOS_PERMISSION_NOTIFICATION_CONTROLLER, + OHOS::Notification::OHOS_PERMISSION_NOTIFICATION_AGENT_CONTROLLER, + OHOS::Notification::OHOS_PERMISSION_SET_UNREMOVABLE_NOTIFICATION + }; + MockRandomToken(&fdp, requestPermission); OHOS::Notification::DoSomethingInterestingWithMyAPI(&fdp); return 0; -} +} \ No newline at end of file diff --git a/test/fuzztest/advancednotificationservice/servicegetalldistribuedenabledbundles_fuzzer/service_getalldistribuedenabledbundles_fuzzer.cpp b/test/fuzztest/advancednotificationservice/servicegetalldistribuedenabledbundles_fuzzer/service_getalldistribuedenabledbundles_fuzzer.cpp index effe2d044..ae2d3e67a 100644 --- a/test/fuzztest/advancednotificationservice/servicegetalldistribuedenabledbundles_fuzzer/service_getalldistribuedenabledbundles_fuzzer.cpp +++ b/test/fuzztest/advancednotificationservice/servicegetalldistribuedenabledbundles_fuzzer/service_getalldistribuedenabledbundles_fuzzer.cpp @@ -18,11 +18,23 @@ #include "advanced_notification_service.h" #include "ans_permission_def.h" #include "mock_notification_request.h" +#include "mock_notification_bundle_option.h" namespace OHOS { namespace Notification { bool DoSomethingInterestingWithMyAPI(FuzzedDataProvider *fuzzData) { + auto service = AdvancedNotificationService::GetInstance(); + service->InitPublishProcess(); + service->CreateDialogManager(); + std::string stringData = fuzzData->ConsumeRandomLengthString(); + std::vector bundelOptions; + int32_t bundleNum = fuzzData->ConsumeIntegral(); + for (int i = 0; i < bundleNum; i++) { + NotificationBundleOption bundleOption = *(ObjectBuilder::Build(fuzzData)); + bundelOptions.emplace_back(bundleOption); + } + service->GetAllDistribuedEnabledBundles(stringData, bundelOptions); return true; } } @@ -33,6 +45,12 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { /* Run your code on data */ FuzzedDataProvider fdp(data, size); + std::vector requestPermission = { + OHOS::Notification::OHOS_PERMISSION_NOTIFICATION_CONTROLLER, + OHOS::Notification::OHOS_PERMISSION_NOTIFICATION_AGENT_CONTROLLER, + OHOS::Notification::OHOS_PERMISSION_SET_UNREMOVABLE_NOTIFICATION + }; + MockRandomToken(&fdp, requestPermission); OHOS::Notification::DoSomethingInterestingWithMyAPI(&fdp); return 0; -} +} \ No newline at end of file diff --git a/test/fuzztest/advancednotificationservice/servicegetdonotdisturbprofile_fuzzer/service_getdonotdisturbprofile_fuzzer.cpp b/test/fuzztest/advancednotificationservice/servicegetdonotdisturbprofile_fuzzer/service_getdonotdisturbprofile_fuzzer.cpp index 589fe2098..dcdedbddc 100644 --- a/test/fuzztest/advancednotificationservice/servicegetdonotdisturbprofile_fuzzer/service_getdonotdisturbprofile_fuzzer.cpp +++ b/test/fuzztest/advancednotificationservice/servicegetdonotdisturbprofile_fuzzer/service_getdonotdisturbprofile_fuzzer.cpp @@ -16,13 +16,21 @@ #include #include "advanced_notification_service.h" +#include "mock_notification_donotdisturb_profile.h" #include "ans_permission_def.h" -#include "mock_notification_request.h" namespace OHOS { namespace Notification { bool DoSomethingInterestingWithMyAPI(FuzzedDataProvider *fuzzData) { + auto service = AdvancedNotificationService::GetInstance(); + service->InitPublishProcess(); + service->CreateDialogManager(); + + int64_t intData = fuzzData->ConsumeIntegral(); + sptr profile = ObjectBuilder::Build(fuzzData); + service->GetDoNotDisturbProfile(intData, profile); + return true; } } @@ -33,6 +41,12 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { /* Run your code on data */ FuzzedDataProvider fdp(data, size); + std::vector requestPermission = { + OHOS::Notification::OHOS_PERMISSION_NOTIFICATION_CONTROLLER, + OHOS::Notification::OHOS_PERMISSION_NOTIFICATION_AGENT_CONTROLLER, + OHOS::Notification::OHOS_PERMISSION_SET_UNREMOVABLE_NOTIFICATION + }; + MockRandomToken(&fdp, requestPermission); OHOS::Notification::DoSomethingInterestingWithMyAPI(&fdp); return 0; -} +} \ No newline at end of file diff --git a/test/fuzztest/advancednotificationservice/servicegetslotbybundle_fuzzer/service_getslotbybundle_fuzzer.cpp b/test/fuzztest/advancednotificationservice/servicegetslotbybundle_fuzzer/service_getslotbybundle_fuzzer.cpp index a3c1b6d23..cf381c8dc 100644 --- a/test/fuzztest/advancednotificationservice/servicegetslotbybundle_fuzzer/service_getslotbybundle_fuzzer.cpp +++ b/test/fuzztest/advancednotificationservice/servicegetslotbybundle_fuzzer/service_getslotbybundle_fuzzer.cpp @@ -18,15 +18,19 @@ #include "advanced_notification_service.h" #include "ans_permission_def.h" #include "mock_notification_bundle_option.h" +#include "mock_notification_slot.h" namespace OHOS { namespace Notification { bool DoSomethingInterestingWithMyAPI(FuzzedDataProvider *fuzzData) { - auto service = AdvancedNotificationService::GetInstance(); + auto service = AdvancedNotificationService::GetInstance(); + service->InitPublishProcess(); + service->CreateDialogManager(); sptr bundleOption = ObjectBuilder::Build(fuzzData); - std::vector> slots; - service->GetSlotsByBundle(bundleOption, slots); + sptr slot = ObjectBuilder::Build(fuzzData); + int32_t intData = fuzzData->ConsumeIntegral(); + service->GetSlotByBundle(bundleOption, intData, slot); return true; } } @@ -46,3 +50,4 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) OHOS::Notification::DoSomethingInterestingWithMyAPI(&fdp); return 0; } + diff --git a/test/fuzztest/advancednotificationservice/serviceisneedsilentindonotdisturbmode_fuzzer/service_isneedsilentindonotdisturbmode_fuzzer.cpp b/test/fuzztest/advancednotificationservice/serviceisneedsilentindonotdisturbmode_fuzzer/service_isneedsilentindonotdisturbmode_fuzzer.cpp index 7dc3a1027..919803bb2 100644 --- a/test/fuzztest/advancednotificationservice/serviceisneedsilentindonotdisturbmode_fuzzer/service_isneedsilentindonotdisturbmode_fuzzer.cpp +++ b/test/fuzztest/advancednotificationservice/serviceisneedsilentindonotdisturbmode_fuzzer/service_isneedsilentindonotdisturbmode_fuzzer.cpp @@ -23,6 +23,12 @@ namespace OHOS { namespace Notification { bool DoSomethingInterestingWithMyAPI(FuzzedDataProvider *fuzzData) { + auto service = AdvancedNotificationService::GetInstance(); + service->InitPublishProcess(); + service->CreateDialogManager(); + std::string stringData = fuzzData->ConsumeRandomLengthString(); + int32_t intData = fuzzData->ConsumeIntegral(); + service->IsNeedSilentInDoNotDisturbMode(stringData, intData); return true; } } @@ -33,6 +39,12 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { /* Run your code on data */ FuzzedDataProvider fdp(data, size); + std::vector requestPermission = { + OHOS::Notification::OHOS_PERMISSION_NOTIFICATION_CONTROLLER, + OHOS::Notification::OHOS_PERMISSION_NOTIFICATION_AGENT_CONTROLLER, + OHOS::Notification::OHOS_PERMISSION_SET_UNREMOVABLE_NOTIFICATION + }; + MockRandomToken(&fdp, requestPermission); OHOS::Notification::DoSomethingInterestingWithMyAPI(&fdp); return 0; -} +} \ No newline at end of file diff --git a/test/fuzztest/advancednotificationservice/servicesetnotificationsenabledforspecialbundle_fuzzer/service_setnotificationsenabledforspecialbundle_fuzzer.cpp b/test/fuzztest/advancednotificationservice/servicesetnotificationsenabledforspecialbundle_fuzzer/service_setnotificationsenabledforspecialbundle_fuzzer.cpp index cd56aa1b5..6a1597a2e 100644 --- a/test/fuzztest/advancednotificationservice/servicesetnotificationsenabledforspecialbundle_fuzzer/service_setnotificationsenabledforspecialbundle_fuzzer.cpp +++ b/test/fuzztest/advancednotificationservice/servicesetnotificationsenabledforspecialbundle_fuzzer/service_setnotificationsenabledforspecialbundle_fuzzer.cpp @@ -18,11 +18,20 @@ #include "advanced_notification_service.h" #include "ans_permission_def.h" #include "mock_notification_request.h" +#include "mock_notification_bundle_option.h" namespace OHOS { namespace Notification { bool DoSomethingInterestingWithMyAPI(FuzzedDataProvider *fuzzData) { + auto service = AdvancedNotificationService::GetInstance(); + service->InitPublishProcess(); + service->CreateDialogManager(); + std::string stringData = fuzzData->ConsumeRandomLengthString(); + sptr bundleOption = ObjectBuilder::Build(fuzzData); + bool enabled = fuzzData->ConsumeBool(); + bool updateUnEnableTime = fuzzData->ConsumeBool(); + service->SetNotificationsEnabledForSpecialBundle(stringData, bundleOption, enabled, updateUnEnableTime); return true; } } @@ -33,6 +42,12 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { /* Run your code on data */ FuzzedDataProvider fdp(data, size); + std::vector requestPermission = { + OHOS::Notification::OHOS_PERMISSION_NOTIFICATION_CONTROLLER, + OHOS::Notification::OHOS_PERMISSION_NOTIFICATION_AGENT_CONTROLLER, + OHOS::Notification::OHOS_PERMISSION_SET_UNREMOVABLE_NOTIFICATION + }; + MockRandomToken(&fdp, requestPermission); OHOS::Notification::DoSomethingInterestingWithMyAPI(&fdp); return 0; -} +} \ No newline at end of file diff --git a/test/fuzztest/advancednotificationservice/servicesetsmartreminderenabled_fuzzer/service_setsmartreminderenabled_fuzzer.cpp b/test/fuzztest/advancednotificationservice/servicesetsmartreminderenabled_fuzzer/service_setsmartreminderenabled_fuzzer.cpp index 84d14dac4..a2c718f49 100644 --- a/test/fuzztest/advancednotificationservice/servicesetsmartreminderenabled_fuzzer/service_setsmartreminderenabled_fuzzer.cpp +++ b/test/fuzztest/advancednotificationservice/servicesetsmartreminderenabled_fuzzer/service_setsmartreminderenabled_fuzzer.cpp @@ -23,6 +23,12 @@ namespace OHOS { namespace Notification { bool DoSomethingInterestingWithMyAPI(FuzzedDataProvider *fuzzData) { + auto service = AdvancedNotificationService::GetInstance(); + service->InitPublishProcess(); + service->CreateDialogManager(); + std::string stringData = fuzzData->ConsumeRandomLengthString(); + bool enabled = fuzzData->ConsumeBool(); + service->SetSmartReminderEnabled(stringData, enabled); return true; } } @@ -33,6 +39,12 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { /* Run your code on data */ FuzzedDataProvider fdp(data, size); + std::vector requestPermission = { + OHOS::Notification::OHOS_PERMISSION_NOTIFICATION_CONTROLLER, + OHOS::Notification::OHOS_PERMISSION_NOTIFICATION_AGENT_CONTROLLER, + OHOS::Notification::OHOS_PERMISSION_SET_UNREMOVABLE_NOTIFICATION + }; + MockRandomToken(&fdp, requestPermission); OHOS::Notification::DoSomethingInterestingWithMyAPI(&fdp); return 0; -} +} \ No newline at end of file diff --git a/test/fuzztest/fuzz_common_base/mock/mock_notification_donotdisturb_profile.h b/test/fuzztest/fuzz_common_base/mock/mock_notification_donotdisturb_profile.h index c79f2b1df..5d211b8de 100644 --- a/test/fuzztest/fuzz_common_base/mock/mock_notification_donotdisturb_profile.h +++ b/test/fuzztest/fuzz_common_base/mock/mock_notification_donotdisturb_profile.h @@ -17,7 +17,7 @@ #define MOCK_NOTIFICATION_DONOT_DISTURB_PROFILE_BUILDER_H #include "mock_fuzz_object.h" -#include "notification_bundle_option.h" +#include "mock_notification_bundle_option.h" #include "notification_do_not_disturb_profile.h" namespace OHOS { diff --git a/test/fuzztest/fuzz_common_base/mock/mock_notification_slot.h b/test/fuzztest/fuzz_common_base/mock/mock_notification_slot.h index 73bde459a..c9ea81046 100644 --- a/test/fuzztest/fuzz_common_base/mock/mock_notification_slot.h +++ b/test/fuzztest/fuzz_common_base/mock/mock_notification_slot.h @@ -24,7 +24,6 @@ namespace Notification { constexpr uint32_t MAX_SLOT_TYPE = 5; constexpr uint32_t MAX_STR_LENGTH = 20; constexpr uint32_t MAX_FLAGS = 63; -constexpr uint32_t MAX_VISIBLENESS_STATUS = 2; template <> NotificationSlot* ObjectBuilder::Build(FuzzedDataProvider *fdp) @@ -36,17 +35,15 @@ NotificationSlot* ObjectBuilder::Build(FuzzedDataProvider *fdp slot->SetDescription(fdp->ConsumeRandomLengthString(MAX_STR_LENGTH)); slot->SetLedLightColor(fdp->ConsumeIntegral()); slot->SetLevel(static_cast( - dp->ConsumeIntegralInRange(0, MAX_SLOT_TYPE))); - slot->SetSlotFlags(dp->ConsumeIntegralInRange(0, MAX_FLAGS)); - slot->SetVisibleness(static_cast( - fdp->ConsumeIntegralInRange(0, VISIBLENESS_STATUS))); + fdp->ConsumeIntegralInRange(0, MAX_SLOT_TYPE))); + slot->SetSlotFlags(fdp->ConsumeIntegralInRange(0, MAX_FLAGS)); slot->EnableBypassDnd(fdp->ConsumeBool()); slot->EnableBadge(fdp->ConsumeBool()); slot->SetEnable(fdp->ConsumeBool()); slot->SetForceControl(fdp->ConsumeBool()); - slot->SetAuthorizedStatus(dp->ConsumeIntegralInRange(0, 1)); - slot->SetAuthHintCnt(dp->ConsumeIntegralInRange(0, 1)); - slot->SetReminderMode(dp->ConsumeIntegralInRange(0, MAX_FLAGS)); + slot->SetAuthorizedStatus(fdp->ConsumeIntegralInRange(0, 1)); + slot->SetAuthHintCnt(fdp->ConsumeIntegralInRange(0, 1)); + slot->SetReminderMode(fdp->ConsumeIntegralInRange(0, MAX_FLAGS)); ANS_LOGE("Build mock veriables"); return slot; -- Gitee