From d6bbf666c9314ecc75e8b0064b95a7674ace4a88 Mon Sep 17 00:00:00 2001 From: songbao1 Date: Tue, 1 Jul 2025 16:52:00 +0800 Subject: [PATCH 1/2] =?UTF-8?q?fuzz=E8=A6=86=E7=9B=96=E7=8E=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: songbao1 --- .../service_cancelgroup_fuzzer.cpp | 4 ++ .../service_canpublishasbundle_fuzzer.cpp | 4 ++ ...service_getenabledforbundleslot_fuzzer.cpp | 11 ++++ ...ice_getenabledforbundleslotself_fuzzer.cpp | 10 ++++ .../service_getslots_fuzzer.cpp | 12 +++++ .../service_issupporttemplate_fuzzer.cpp | 4 ++ ...blishcontinuoustasknotification_fuzzer.cpp | 12 +++++ .../service_removeallnotifications_fuzzer.cpp | 9 ++++ .../service_setbadgenumber_fuzzer.cpp | 9 ++++ .../service_sethashcoderule_fuzzer.cpp | 8 +++ ...ncnotificationenabledwithoutapp_fuzzer.cpp | 10 ++++ .../service_unsubscribe_fuzzer.cpp | 51 ++++++++++++++++++ .../service_updateslots_fuzzer.cpp | 14 +++++ .../mock/mock_notification_slot.h | 52 +++++++++++++++++++ 14 files changed, 210 insertions(+) create mode 100644 test/fuzztest/fuzz_common_base/mock/mock_notification_slot.h diff --git a/test/fuzztest/advancednotificationservice/servicecancelgroup_fuzzer/service_cancelgroup_fuzzer.cpp b/test/fuzztest/advancednotificationservice/servicecancelgroup_fuzzer/service_cancelgroup_fuzzer.cpp index 9e0e85332..e8dadb50c 100644 --- a/test/fuzztest/advancednotificationservice/servicecancelgroup_fuzzer/service_cancelgroup_fuzzer.cpp +++ b/test/fuzztest/advancednotificationservice/servicecancelgroup_fuzzer/service_cancelgroup_fuzzer.cpp @@ -23,6 +23,10 @@ namespace OHOS { namespace Notification { bool DoSomethingInterestingWithMyAPI(FuzzedDataProvider *fuzzData) { + auto service = AdvancedNotificationService::GetInstance(); + std::string groupName = fuzzData->ConsumeRandomLengthString(); + std::string instanceKey = fuzzData->ConsumeRandomLengthString(); + service->CancelGroup(groupName, instanceKey); return true; } } diff --git a/test/fuzztest/advancednotificationservice/servicecanpublishasbundle_fuzzer/service_canpublishasbundle_fuzzer.cpp b/test/fuzztest/advancednotificationservice/servicecanpublishasbundle_fuzzer/service_canpublishasbundle_fuzzer.cpp index a14eb0e92..32c258d9e 100644 --- a/test/fuzztest/advancednotificationservice/servicecanpublishasbundle_fuzzer/service_canpublishasbundle_fuzzer.cpp +++ b/test/fuzztest/advancednotificationservice/servicecanpublishasbundle_fuzzer/service_canpublishasbundle_fuzzer.cpp @@ -23,6 +23,10 @@ namespace OHOS { namespace Notification { bool DoSomethingInterestingWithMyAPI(FuzzedDataProvider *fuzzData) { + auto service = AdvancedNotificationService::GetInstance(); + std::string representativeBundle = fuzzData->ConsumeRandomLengthString(); + bool canPublish; + service->CanPublishAsBundle(representativeBundle, canPublish); return true; } } diff --git a/test/fuzztest/advancednotificationservice/servicegetenabledforbundleslot_fuzzer/service_getenabledforbundleslot_fuzzer.cpp b/test/fuzztest/advancednotificationservice/servicegetenabledforbundleslot_fuzzer/service_getenabledforbundleslot_fuzzer.cpp index 9c1a454e4..1223ab936 100644 --- a/test/fuzztest/advancednotificationservice/servicegetenabledforbundleslot_fuzzer/service_getenabledforbundleslot_fuzzer.cpp +++ b/test/fuzztest/advancednotificationservice/servicegetenabledforbundleslot_fuzzer/service_getenabledforbundleslot_fuzzer.cpp @@ -23,6 +23,11 @@ namespace OHOS { namespace Notification { bool DoSomethingInterestingWithMyAPI(FuzzedDataProvider *fuzzData) { + auto service = AdvancedNotificationService::GetInstance(); + sptr option = ObjectBuilder::Build(fuzzData); + int32_t slotTypeInt = fuzzData->ConsumeIntegralInRange(0, 5); + bool enabled; + service->GetEnabledForBundleSlot(option, slotTypeInt, enabled); return true; } } @@ -33,6 +38,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; } diff --git a/test/fuzztest/advancednotificationservice/servicegetenabledforbundleslotself_fuzzer/service_getenabledforbundleslotself_fuzzer.cpp b/test/fuzztest/advancednotificationservice/servicegetenabledforbundleslotself_fuzzer/service_getenabledforbundleslotself_fuzzer.cpp index e531760e0..dc3d88777 100644 --- a/test/fuzztest/advancednotificationservice/servicegetenabledforbundleslotself_fuzzer/service_getenabledforbundleslotself_fuzzer.cpp +++ b/test/fuzztest/advancednotificationservice/servicegetenabledforbundleslotself_fuzzer/service_getenabledforbundleslotself_fuzzer.cpp @@ -23,6 +23,10 @@ namespace OHOS { namespace Notification { bool DoSomethingInterestingWithMyAPI(FuzzedDataProvider *fuzzData) { + auto service = AdvancedNotificationService::GetInstance(); + bool enable; + int32_t slotTypeInt = fuzzData->ConsumeIntegral(); + service->GetEnabledForBundleSlotSelf(slotTypeInt, enable); return true; } } @@ -33,6 +37,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; } diff --git a/test/fuzztest/advancednotificationservice/servicegetslots_fuzzer/service_getslots_fuzzer.cpp b/test/fuzztest/advancednotificationservice/servicegetslots_fuzzer/service_getslots_fuzzer.cpp index 27524e679..a96cf2452 100644 --- a/test/fuzztest/advancednotificationservice/servicegetslots_fuzzer/service_getslots_fuzzer.cpp +++ b/test/fuzztest/advancednotificationservice/servicegetslots_fuzzer/service_getslots_fuzzer.cpp @@ -18,11 +18,17 @@ #include "advanced_notification_service.h" #include "ans_permission_def.h" #include "mock_notification_request.h" +#include "notification_slot.h" + +#include namespace OHOS { namespace Notification { bool DoSomethingInterestingWithMyAPI(FuzzedDataProvider *fuzzData) { + auto service = AdvancedNotificationService::GetInstance(); + std::vector> slots; + service->GetSlots(slots); 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; } diff --git a/test/fuzztest/advancednotificationservice/serviceissupporttemplate_fuzzer/service_issupporttemplate_fuzzer.cpp b/test/fuzztest/advancednotificationservice/serviceissupporttemplate_fuzzer/service_issupporttemplate_fuzzer.cpp index 4624afca3..4c9b98fe0 100644 --- a/test/fuzztest/advancednotificationservice/serviceissupporttemplate_fuzzer/service_issupporttemplate_fuzzer.cpp +++ b/test/fuzztest/advancednotificationservice/serviceissupporttemplate_fuzzer/service_issupporttemplate_fuzzer.cpp @@ -23,6 +23,10 @@ namespace OHOS { namespace Notification { bool DoSomethingInterestingWithMyAPI(FuzzedDataProvider *fuzzData) { + auto service = AdvancedNotificationService::GetInstance(); + std::string templateName = fuzzData->ConsumeRandomLengthString(); + bool support; + service->IsSupportTemplate(templateName, support); return true; } } diff --git a/test/fuzztest/advancednotificationservice/servicepublishcontinuoustasknotification_fuzzer/service_publishcontinuoustasknotification_fuzzer.cpp b/test/fuzztest/advancednotificationservice/servicepublishcontinuoustasknotification_fuzzer/service_publishcontinuoustasknotification_fuzzer.cpp index e6c52125a..a9ea4ea3a 100644 --- a/test/fuzztest/advancednotificationservice/servicepublishcontinuoustasknotification_fuzzer/service_publishcontinuoustasknotification_fuzzer.cpp +++ b/test/fuzztest/advancednotificationservice/servicepublishcontinuoustasknotification_fuzzer/service_publishcontinuoustasknotification_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(); + sptr request = ObjectBuilder::Build(fuzzData); + service->Publish(stringData, request); 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; } diff --git a/test/fuzztest/advancednotificationservice/serviceremoveallnotifications_fuzzer/service_removeallnotifications_fuzzer.cpp b/test/fuzztest/advancednotificationservice/serviceremoveallnotifications_fuzzer/service_removeallnotifications_fuzzer.cpp index e759156ff..91c833824 100644 --- a/test/fuzztest/advancednotificationservice/serviceremoveallnotifications_fuzzer/service_removeallnotifications_fuzzer.cpp +++ b/test/fuzztest/advancednotificationservice/serviceremoveallnotifications_fuzzer/service_removeallnotifications_fuzzer.cpp @@ -23,6 +23,9 @@ namespace OHOS { namespace Notification { bool DoSomethingInterestingWithMyAPI(FuzzedDataProvider *fuzzData) { + auto service = AdvancedNotificationService::GetInstance(); + sptr option = ObjectBuilder::Build(fuzzData); + service->RemoveAllNotifications(option); return true; } } @@ -33,6 +36,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; } diff --git a/test/fuzztest/advancednotificationservice/servicesetbadgenumber_fuzzer/service_setbadgenumber_fuzzer.cpp b/test/fuzztest/advancednotificationservice/servicesetbadgenumber_fuzzer/service_setbadgenumber_fuzzer.cpp index 1f6c7e0c0..c91dcd072 100644 --- a/test/fuzztest/advancednotificationservice/servicesetbadgenumber_fuzzer/service_setbadgenumber_fuzzer.cpp +++ b/test/fuzztest/advancednotificationservice/servicesetbadgenumber_fuzzer/service_setbadgenumber_fuzzer.cpp @@ -23,6 +23,10 @@ namespace OHOS { namespace Notification { bool DoSomethingInterestingWithMyAPI(FuzzedDataProvider *fuzzData) { + auto service = AdvancedNotificationService::GetInstance(); + + int32_t num = fuzzData->ConsumeIntegral(); + service->SetNotificationBadgeNum(num); return true; } } @@ -33,6 +37,11 @@ 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 + }; OHOS::Notification::DoSomethingInterestingWithMyAPI(&fdp); return 0; } diff --git a/test/fuzztest/advancednotificationservice/servicesethashcoderule_fuzzer/service_sethashcoderule_fuzzer.cpp b/test/fuzztest/advancednotificationservice/servicesethashcoderule_fuzzer/service_sethashcoderule_fuzzer.cpp index f072f76d9..013f10a0f 100644 --- a/test/fuzztest/advancednotificationservice/servicesethashcoderule_fuzzer/service_sethashcoderule_fuzzer.cpp +++ b/test/fuzztest/advancednotificationservice/servicesethashcoderule_fuzzer/service_sethashcoderule_fuzzer.cpp @@ -23,6 +23,9 @@ namespace OHOS { namespace Notification { bool DoSomethingInterestingWithMyAPI(FuzzedDataProvider *fuzzData) { + auto service = AdvancedNotificationService::GetInstance(); + uint32_t type = fuzzData->ConsumeIntegral(); + service->SetHashCodeRule(type); return true; } } @@ -33,6 +36,11 @@ 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 + }; OHOS::Notification::DoSomethingInterestingWithMyAPI(&fdp); return 0; } diff --git a/test/fuzztest/advancednotificationservice/servicesetsyncnotificationenabledwithoutapp_fuzzer/service_setsyncnotificationenabledwithoutapp_fuzzer.cpp b/test/fuzztest/advancednotificationservice/servicesetsyncnotificationenabledwithoutapp_fuzzer/service_setsyncnotificationenabledwithoutapp_fuzzer.cpp index 461f370a0..476e7e0e1 100644 --- a/test/fuzztest/advancednotificationservice/servicesetsyncnotificationenabledwithoutapp_fuzzer/service_setsyncnotificationenabledwithoutapp_fuzzer.cpp +++ b/test/fuzztest/advancednotificationservice/servicesetsyncnotificationenabledwithoutapp_fuzzer/service_setsyncnotificationenabledwithoutapp_fuzzer.cpp @@ -23,6 +23,10 @@ namespace OHOS { namespace Notification { bool DoSomethingInterestingWithMyAPI(FuzzedDataProvider *fuzzData) { + int32_t userId = fuzzData->ConsumeIntegral(); + bool enabled = fuzzData->ConsumeBool(); + auto service = AdvancedNotificationService::GetInstance(); + service->SetSyncNotificationEnabledWithoutApp(userId, enabled); return true; } } @@ -33,6 +37,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; } diff --git a/test/fuzztest/advancednotificationservice/serviceunsubscribe_fuzzer/service_unsubscribe_fuzzer.cpp b/test/fuzztest/advancednotificationservice/serviceunsubscribe_fuzzer/service_unsubscribe_fuzzer.cpp index f9ed56c04..56eed56a6 100644 --- a/test/fuzztest/advancednotificationservice/serviceunsubscribe_fuzzer/service_unsubscribe_fuzzer.cpp +++ b/test/fuzztest/advancednotificationservice/serviceunsubscribe_fuzzer/service_unsubscribe_fuzzer.cpp @@ -18,11 +18,56 @@ #include "advanced_notification_service.h" #include "ans_permission_def.h" #include "mock_notification_request.h" +#include "mock_notification_subscribe_info.h" +#include "notification_subscriber.h" +#include "ans_subscriber_listener.h" namespace OHOS { namespace Notification { + +class TestSubscriber : public NotificationSubscriber { +public: + void OnDisconnected() override + {} + void OnDied() override + {} + void OnUpdate(const std::shared_ptr &sortingMap) override + {} + void OnDoNotDisturbDateChange(const std::shared_ptr &date) override + {} + void OnConnected() override + {} + void OnEnabledNotificationChanged(const std::shared_ptr &callbackData) override + {} + void OnCanceled(const std::shared_ptr &request, + const std::shared_ptr &sortingMap, int deleteReason) override + {} + void OnBadgeChanged(const std::shared_ptr &badgeData) override + {} + void OnBadgeEnabledChanged(const sptr &callbackData) override + {} + void OnConsumed(const std::shared_ptr &request, + const std::shared_ptr &sortingMap) override + {} + + void OnBatchCanceled(const std::vector> &requestList, + const std::shared_ptr &sortingMap, int32_t deleteReason) override + {} + + bool HasOnBatchCancelCallback() override + { + return true; + } +}; + bool DoSomethingInterestingWithMyAPI(FuzzedDataProvider *fuzzData) { + auto service = AdvancedNotificationService::GetInstance(); + std::shared_ptr subscriber = std::make_shared(); + sptr listener = new (std::nothrow) SubscriberListener(subscriber); + + sptr subscribeInfo = ObjectBuilder::Build(fuzzData); + service->Unsubscribe(listener, subscribeInfo); return true; } } @@ -33,6 +78,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; } diff --git a/test/fuzztest/advancednotificationservice/serviceupdateslots_fuzzer/service_updateslots_fuzzer.cpp b/test/fuzztest/advancednotificationservice/serviceupdateslots_fuzzer/service_updateslots_fuzzer.cpp index 098266716..7b543e9b3 100644 --- a/test/fuzztest/advancednotificationservice/serviceupdateslots_fuzzer/service_updateslots_fuzzer.cpp +++ b/test/fuzztest/advancednotificationservice/serviceupdateslots_fuzzer/service_updateslots_fuzzer.cpp @@ -19,10 +19,18 @@ #include "ans_permission_def.h" #include "mock_notification_request.h" +#include + namespace OHOS { namespace Notification { bool DoSomethingInterestingWithMyAPI(FuzzedDataProvider *fuzzData) { + auto service = AdvancedNotificationService::GetInstance(); + sptr option = ObjectBuilder::Build(fuzzData); + std::vector> slots; + sptr slot = ObjectBuilder::Build(fuzzData); + slots.emplace_back(slot); + service->UpdateSlots(option, slots); 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; } diff --git a/test/fuzztest/fuzz_common_base/mock/mock_notification_slot.h b/test/fuzztest/fuzz_common_base/mock/mock_notification_slot.h new file mode 100644 index 000000000..15861bdb7 --- /dev/null +++ b/test/fuzztest/fuzz_common_base/mock/mock_notification_slot.h @@ -0,0 +1,52 @@ +/* + * 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 MOCK_NOTIFICATION_SLOT_H +#define MOCK_NOTIFICATION_SLOT_H + +#include "mock_fuzz_object.h" +#include "notification_slot.h" +namespace OHOS { +namespace Notification { + +template <> +NotificationSlot* ObjectBuilder::Build(FuzzedDataProvider *fdp) +{ + NotificationSlot* slot = new NotificationSlot(static_cast( + fdp->ConsumeIntegralInRange(0, 5))); + slot->SetEnableLight(fdp->ConsumeBool()); + slot->SetEnableVibration(fdp->ConsumeBool()); + slot->SetDescription(fdp->ConsumeRandomLengthString(20)); + slot->SetLedLightColor(fdp->ConsumeIntegral()); + slot->SetLevel(static_cast( + dp->ConsumeIntegralInRange(0, 5))); + slot->SetSlotFlags(dp->ConsumeIntegralInRange(0, 63)); + slot->SetVisibleness(static_cast( + fdp->ConsumeIntegralInRange(0, 2))); + 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, 63)); + + ANS_LOGE("Build mock veriables"); + return slot; +} + +} // namespace Notification +} // namespace OHOS +#endif // MOCK_NOTIFICATION_SLOT_H \ No newline at end of file -- Gitee From 4a0f6a8858acce800f5219d8c4f78083b198f478 Mon Sep 17 00:00:00 2001 From: songbao1 Date: Tue, 1 Jul 2025 17:30:47 +0800 Subject: [PATCH 2/2] =?UTF-8?q?fuzz=E8=A6=86=E7=9B=96=E7=8E=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: songbao1 --- .../service_getslots_fuzzer.cpp | 2 +- .../mock/mock_notification_slot.h | 17 +++++++++++------ 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/test/fuzztest/advancednotificationservice/servicegetslots_fuzzer/service_getslots_fuzzer.cpp b/test/fuzztest/advancednotificationservice/servicegetslots_fuzzer/service_getslots_fuzzer.cpp index a96cf2452..ce37f1108 100644 --- a/test/fuzztest/advancednotificationservice/servicegetslots_fuzzer/service_getslots_fuzzer.cpp +++ b/test/fuzztest/advancednotificationservice/servicegetslots_fuzzer/service_getslots_fuzzer.cpp @@ -26,7 +26,7 @@ namespace OHOS { namespace Notification { bool DoSomethingInterestingWithMyAPI(FuzzedDataProvider *fuzzData) { - auto service = AdvancedNotificationService::GetInstance(); + auto service = AdvancedNotificationService::GetInstance(); std::vector> slots; service->GetSlots(slots); return true; 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 15861bdb7..73bde459a 100644 --- a/test/fuzztest/fuzz_common_base/mock/mock_notification_slot.h +++ b/test/fuzztest/fuzz_common_base/mock/mock_notification_slot.h @@ -21,27 +21,32 @@ namespace OHOS { 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) { NotificationSlot* slot = new NotificationSlot(static_cast( - fdp->ConsumeIntegralInRange(0, 5))); + fdp->ConsumeIntegralInRange(0, MAX_SLOT_TYPE))); slot->SetEnableLight(fdp->ConsumeBool()); slot->SetEnableVibration(fdp->ConsumeBool()); - slot->SetDescription(fdp->ConsumeRandomLengthString(20)); + slot->SetDescription(fdp->ConsumeRandomLengthString(MAX_STR_LENGTH)); slot->SetLedLightColor(fdp->ConsumeIntegral()); slot->SetLevel(static_cast( - dp->ConsumeIntegralInRange(0, 5))); - slot->SetSlotFlags(dp->ConsumeIntegralInRange(0, 63)); + dp->ConsumeIntegralInRange(0, MAX_SLOT_TYPE))); + slot->SetSlotFlags(dp->ConsumeIntegralInRange(0, MAX_FLAGS)); slot->SetVisibleness(static_cast( - fdp->ConsumeIntegralInRange(0, 2))); + fdp->ConsumeIntegralInRange(0, VISIBLENESS_STATUS))); 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, 63)); + slot->SetReminderMode(dp->ConsumeIntegralInRange(0, MAX_FLAGS)); ANS_LOGE("Build mock veriables"); return slot; -- Gitee