From fbcbaa8e4364f0e6853b995d662359f15b55d76e Mon Sep 17 00:00:00 2001 From: zhangzezhong Date: Tue, 13 May 2025 21:14:52 +0800 Subject: [PATCH] ans add fuzz test Signed-off-by: zhangzezhong --- test/fuzztest/BUILD.gn | 3 + test/fuzztest/ansmanagerstub_fuzzer/BUILD.gn | 117 ++++++++++ .../ansmanagerstub_fuzzer.cpp | 216 ++++++++++++++++++ .../ansmanagerstub_fuzzer.h | 23 ++ .../ansmanagerstub_fuzzer/corpus/init | 13 ++ .../ansmanagerstub_fuzzer/project.xml | 25 ++ .../ansmanagerstubannex_fuzzer/BUILD.gn | 120 ++++++++++ .../ansmanagerstubannex_fuzzer.cpp | 104 +++++++++ .../ansmanagerstubannex_fuzzer.h | 24 ++ .../ansmanagerstubannex_fuzzer/corpus/init | 13 ++ .../ansmanagerstubannex_fuzzer/project.xml | 25 ++ .../ansmanagerstubannextwo_fuzzer/BUILD.gn | 120 ++++++++++ .../ansmanagerstubannextwo_fuzzer.cpp | 60 +++++ .../ansmanagerstubannextwo_fuzzer.h | 24 ++ .../ansmanagerstubannextwo_fuzzer/corpus/init | 13 ++ .../ansmanagerstubannextwo_fuzzer/project.xml | 25 ++ 16 files changed, 925 insertions(+) create mode 100644 test/fuzztest/ansmanagerstub_fuzzer/BUILD.gn create mode 100644 test/fuzztest/ansmanagerstub_fuzzer/ansmanagerstub_fuzzer.cpp create mode 100644 test/fuzztest/ansmanagerstub_fuzzer/ansmanagerstub_fuzzer.h create mode 100644 test/fuzztest/ansmanagerstub_fuzzer/corpus/init create mode 100644 test/fuzztest/ansmanagerstub_fuzzer/project.xml create mode 100644 test/fuzztest/ansmanagerstubannex_fuzzer/BUILD.gn create mode 100644 test/fuzztest/ansmanagerstubannex_fuzzer/ansmanagerstubannex_fuzzer.cpp create mode 100644 test/fuzztest/ansmanagerstubannex_fuzzer/ansmanagerstubannex_fuzzer.h create mode 100644 test/fuzztest/ansmanagerstubannex_fuzzer/corpus/init create mode 100644 test/fuzztest/ansmanagerstubannex_fuzzer/project.xml create mode 100644 test/fuzztest/ansmanagerstubannextwo_fuzzer/BUILD.gn create mode 100644 test/fuzztest/ansmanagerstubannextwo_fuzzer/ansmanagerstubannextwo_fuzzer.cpp create mode 100644 test/fuzztest/ansmanagerstubannextwo_fuzzer/ansmanagerstubannextwo_fuzzer.h create mode 100644 test/fuzztest/ansmanagerstubannextwo_fuzzer/corpus/init create mode 100644 test/fuzztest/ansmanagerstubannextwo_fuzzer/project.xml diff --git a/test/fuzztest/BUILD.gn b/test/fuzztest/BUILD.gn index 3ada94a98..d3443b844 100644 --- a/test/fuzztest/BUILD.gn +++ b/test/fuzztest/BUILD.gn @@ -19,6 +19,9 @@ group("fuzztest") { "addnotificationslots_fuzzer:AddNotificationSlotsFuzzTest", "addslotbytype_fuzzer:AddSlotByTypeFuzzTest", "advancednotificationservice_fuzzer:AdvancedNotificationServiceFuzzTest", + "ansmanagerstub_fuzzer:AnsManagerStubFuzzTest", + "ansmanagerstubannex_fuzzer:AnsManagerStubAnnexFuzzTest", + "ansmanagerstubannextwo_fuzzer:AnsManagerStubAnnexTwoFuzzTest", "anssubscriberproxy_fuzzer:AnsSubscriberProxyFuzzTest", "anssubscriberstub_fuzzer:AnsSubscriberStubFuzzTest", "cancelasbundle_fuzzer:CancelAsBundleFuzzTest", diff --git a/test/fuzztest/ansmanagerstub_fuzzer/BUILD.gn b/test/fuzztest/ansmanagerstub_fuzzer/BUILD.gn new file mode 100644 index 000000000..d4aade70f --- /dev/null +++ b/test/fuzztest/ansmanagerstub_fuzzer/BUILD.gn @@ -0,0 +1,117 @@ +# 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("AnsManagerStubFuzzTest") { + module_out_path = service_fuzz_test_path + fuzz_config_file = "${component_path}/test/fuzztest/ansmanagerstub_fuzzer" + include_dirs = [ + "${component_path}/test/fuzztest/fuzz_common_base", + "${services_path}/ans/include", + "${core_path}/include" + ] + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + sources = [ "ansmanagerstub_fuzzer.cpp" ] + + deps = [ + "${component_path}/test/fuzztest/fuzz_common_base:fuzz_common_base", + "${frameworks_module_ans_path}:ans_innerkits", + "${services_path}/ans:ans_service_sources", + ] + + external_deps = [ + "ability_base:want", + "ability_base:zuri", + "c_utils:utils", + "ffrt:libffrt", + "hilog:libhilog", + "kv_store:distributeddata_inner", + "image_framework:image_native", + "ipc:ipc_single", + "relational_store:native_rdb", + ] + + defines = [] + + if (is_double_framework) { + cflags += [ "-DCONFIG_DUAL_FRAMEWORK" ] + } + + if (distributed_notification_supported) { + defines += [ "DISTRIBUTED_NOTIFICATION_SUPPORTED" ] + deps += [ "${services_path}/distributed:libans_distributed" ] + include_dirs += [ "${services_path}/distributed/include" ] + } + + if (notification_smart_reminder_supported) { + defines += [ "NOTIFICATION_SMART_REMINDER_SUPPORTED" ] + } + + if (player_framework) { + external_deps += [ "player_framework:media_client" ] + defines += [ "PLAYER_FRAMEWORK_ENABLE" ] + } + + if (ans_hitrace_usage) { + external_deps += [ "hitrace:hitrace_meter" ] + defines += [ "HITRACE_METER_ENABLE" ] + } + + if (ans_config_policy_enable) { + external_deps += [ "config_policy:configpolicy_util" ] + defines += [ "CONFIG_POLICY_ENABLE" ] + } + + if (screenlock_mgr_enable) { + external_deps += [ "screenlock_mgr:screenlock_client" ] + defines += [ "SCREENLOCK_MGR_ENABLE" ] + } + + if (distributed_notification_service_feature_summary || + distributed_notification_service_feature_additional_control) { + defines += [ "ENABLE_ANS_EXT_WRAPPER" ] + } + + if (distributed_notification_service_feature_additional_control) { + defines += [ "ENABLE_ANS_ADDITIONAL_CONTROL" ] + } + + if (distributed_notification_service_feature_summary) { + defines += [ "ENABLE_ANS_AGGREGATION" ] + } + + if (telephony_cust) { + defines += [ "ENABLE_ANS_TELEPHONY_CUST_WRAPPER" ] + } + + if (distributed_notification_service_feature_disable_fa_model) { + defines += [ "ANS_DISABLE_FA_MODEL" ] + } +} + +############################################################################### +group("fuzztest") { + testonly = true + deps = [ ":AnsManagerStubFuzzTest" ] +} +############################################################################### diff --git a/test/fuzztest/ansmanagerstub_fuzzer/ansmanagerstub_fuzzer.cpp b/test/fuzztest/ansmanagerstub_fuzzer/ansmanagerstub_fuzzer.cpp new file mode 100644 index 000000000..395791700 --- /dev/null +++ b/test/fuzztest/ansmanagerstub_fuzzer/ansmanagerstub_fuzzer.cpp @@ -0,0 +1,216 @@ +/* + * Copyright (c) 2022-2023 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include + +#define private public +#define protected public +#include "advanced_notification_service.h" +#undef private +#undef protected +#include "ans_permission_def.h" +#include "ansmanagerstub_fuzzer.h" +#include "notification_record.h" +#include "notification_request.h" + +constexpr uint8_t SLOT_TYPE_NUM = 5; + +namespace OHOS { + + bool DoSomethingInterestingWithMyAPI(FuzzedDataProvider *fuzzData) + { + auto service = std::make_shared(); + service->InitPublishProcess(); + service->CreateDialogManager(); + std::string stringData = fuzzData->ConsumeRandomLengthString(); + sptr notification = new Notification::NotificationRequest(); + notification->SetOwnerUid(fuzzData->ConsumeIntegral()); + notification->SetCreatorUid(fuzzData->ConsumeIntegral()); + notification->SetSlotType(Notification::NotificationConstant::SlotType::LIVE_VIEW); + auto content = std::make_shared(); + notification->SetContent(std::make_shared(content)); + service->Publish(stringData, notification); + int notificationId = fuzzData->ConsumeIntegral(); + service->Cancel(notificationId, stringData, fuzzData->ConsumeRandomLengthString()); + service->CancelAll(fuzzData->ConsumeRandomLengthString()); + int32_t userId = fuzzData->ConsumeIntegral(); + service->CancelAsBundle(notificationId, stringData, userId); + uint8_t type = fuzzData->ConsumeIntegral() % SLOT_TYPE_NUM; + Notification::NotificationConstant::SlotType slotType = Notification::NotificationConstant::SlotType(type); + service->AddSlotByType(slotType); + std::vector> slots; + service->AddSlots(slots); + service->RemoveSlotByType(slotType); + service->RemoveAllSlots(); + sptr slot = new Notification::NotificationSlot(); + service->GetSlotByType(slotType, slot); + service->GetSlots(slots); + sptr bundleOption = new Notification::NotificationBundleOption(); + sptr buttonOption = new Notification::NotificationButtonOption(); + bundleOption->SetBundleName(fuzzData->ConsumeRandomLengthString()); + bundleOption->SetUid(fuzzData->ConsumeIntegral()); + uint64_t num = fuzzData->ConsumeIntegral(); + service->CancelAsBundle(bundleOption, fuzzData->ConsumeIntegral()); + service->CancelAsBundleWithAgent(bundleOption, fuzzData->ConsumeIntegral()); + service->GetSlotNumAsBundle(bundleOption, num); + std::vector> notifications; + service->GetActiveNotifications(notifications, fuzzData->ConsumeRandomLengthString()); + service->GetActiveNotificationNums(num); + std::vector> notificationss; + service->GetAllActiveNotifications(notificationss); + std::vector key; + service->GetSpecialActiveNotifications(key, notificationss); + bool canPublish = fuzzData->ConsumeBool(); + service->CanPublishAsBundle(stringData, canPublish); + service->PublishAsBundle(notification, stringData); + service->SetNotificationBadgeNum(num); + int importance = fuzzData->ConsumeIntegral(); + service->GetBundleImportance(importance); + bool granted = fuzzData->ConsumeBool(); + service->HasNotificationPolicyAccessPermission(granted); + int32_t removeReason = fuzzData->ConsumeIntegral(); + service->RemoveNotification(bundleOption, notificationId, stringData, removeReason); + service->RemoveAllNotifications(bundleOption); + service->Delete(stringData, removeReason); + service->DeleteByBundle(bundleOption); + service->DeleteAll(); + service->GetSlotsByBundle(bundleOption, slots); + service->UpdateSlots(bundleOption, slots); + bool enabled = fuzzData->ConsumeBool(); + service->SetNotificationsEnabledForBundle(stringData, enabled); + service->SetNotificationsEnabledForAllBundles(stringData, enabled); + service->SetNotificationsEnabledForSpecialBundle(stringData, bundleOption, enabled); + service->SetShowBadgeEnabledForBundle(bundleOption, enabled); + service->GetShowBadgeEnabledForBundle(bundleOption, enabled); + service->GetShowBadgeEnabled(enabled); + sptr info = new Notification::NotificationSubscribeInfo(); + bool allowed = fuzzData->ConsumeBool(); + service->IsAllowedNotify(allowed); + service->IsAllowedNotifySelf(bundleOption, allowed); + service->IsAllowedNotifyForBundle(bundleOption, allowed); + service->IsSpecialBundleAllowedNotify(bundleOption, allowed); + service->CancelGroup(stringData, fuzzData->ConsumeRandomLengthString()); + service->RemoveGroupByBundle(bundleOption, stringData); + sptr date = new Notification::NotificationDoNotDisturbDate(); + service->SetDoNotDisturbDate(date); + service->GetDoNotDisturbDate(date); + bool doesSupport = fuzzData->ConsumeBool(); + service->DoesSupportDoNotDisturbMode(doesSupport); + service->IsDistributedEnabled(enabled); + service->EnableDistributedByBundle(bundleOption, enabled); + service->EnableDistributedSelf(enabled); + service->EnableDistributed(enabled); + service->IsDistributedEnableByBundle(bundleOption, enabled); + int32_t remindType; + service->GetDeviceRemindType(remindType); + sptr request = new Notification::NotificationRequest(); + service->PublishContinuousTaskNotification(request); + service->CancelContinuousTaskNotification(stringData, notificationId); + bool support = fuzzData->ConsumeBool(); + service->IsSupportTemplate(stringData, support); + service->IsSpecialUserAllowedNotify(userId, allowed); + int32_t deviceIds = fuzzData->ConsumeIntegral(); + service->SetNotificationsEnabledByUser(deviceIds, enabled); + service->DeleteAllByUser(userId); + service->SetDoNotDisturbDate(date); + service->GetDoNotDisturbDate(date); + service->SetEnabledForBundleSlot(bundleOption, slotType, enabled, false); + service->GetEnabledForBundleSlot(bundleOption, slotType, enabled); + std::vector dumpInfo; + service->ShellDump(stringData, stringData, userId, userId, dumpInfo); + service->SetSyncNotificationEnabledWithoutApp(userId, enabled); + service->GetSyncNotificationEnabledWithoutApp(userId, enabled); + int32_t badgeNum = fuzzData->ConsumeIntegral(); + service->SetBadgeNumber(badgeNum, fuzzData->ConsumeRandomLengthString()); + std::shared_ptr groupInfo; + bool enable = fuzzData->ConsumeBool(); + std::string bundleName = fuzzData->ConsumeRandomLengthString(); + std::string phoneNumber = fuzzData->ConsumeRandomLengthString(); + std::string groupName = fuzzData->ConsumeRandomLengthString(); + std::string deviceType = fuzzData->ConsumeRandomLengthString(); + std::string localSwitch = fuzzData->ConsumeRandomLengthString(); + std::vector> recordList; + bool isNative = fuzzData->ConsumeBool(); + service->CanPopEnableNotificationDialog(nullptr, enable, bundleName); + std::vector keys; + std::string key1 = fuzzData->ConsumeRandomLengthString(); + keys.emplace_back(fuzzData->ConsumeRandomLengthString()); + service->RemoveNotifications(keys, fuzzData->ConsumeIntegral()); + service->SetBadgeNumberByBundle(bundleOption, fuzzData->ConsumeIntegral()); + service->SetDistributedEnabledByBundle(bundleOption, fuzzData->ConsumeRandomLengthString(), + fuzzData->ConsumeBool()); + service->IsDistributedEnableByBundle(bundleOption, enable); + service->SetDefaultNotificationEnabled(bundleOption, enabled); + service->ExcuteCancelAll(bundleOption, fuzzData->ConsumeIntegral()); + service->ExcuteDelete(stringData, fuzzData->ConsumeIntegral()); + service->HandleBadgeEnabledChanged(bundleOption, enabled); + service->RemoveSystemLiveViewNotifications(bundleName, fuzzData->ConsumeIntegral()); + service->RemoveSystemLiveViewNotificationsOfSa(fuzzData->ConsumeIntegral()); + service->TriggerLocalLiveView(bundleOption, fuzzData->ConsumeIntegral(), buttonOption); + service->RemoveNotificationBySlot(bundleOption, slot, fuzzData->ConsumeIntegral()); + service->IsNeedSilentInDoNotDisturbMode(phoneNumber, fuzzData->ConsumeIntegral()); + service->CheckNeedSilent(phoneNumber, fuzzData->ConsumeIntegral(), + fuzzData->ConsumeIntegral()); + service->ExcuteCancelGroupCancel(bundleOption, groupName, fuzzData->ConsumeIntegral()); + service->RemoveNotificationFromRecordList(recordList); + service->UpdateUnifiedGroupInfo(key1, groupInfo); + service->PublishNotificationBySa(request); + service->IsDistributedEnabledByBundle(bundleOption, deviceType, enabled); + service->DuplicateMsgControl(request); + service->DeleteDuplicateMsgs(bundleOption); + service->RemoveExpiredUniqueKey(); + service->SetSmartReminderEnabled(deviceType, enabled); + service->IsSmartReminderEnabled(deviceType, enabled); + service->SetTargetDeviceStatus(deviceType, fuzzData->ConsumeIntegral(), ""); + service->ClearAllNotificationGroupInfo(localSwitch); + + service->SetSlotFlagsAsBundle(bundleOption, fuzzData->ConsumeIntegral()); + uint32_t slotFlags; + service->GetSlotFlagsAsBundle(bundleOption, slotFlags); + service->GetActiveNotificationByFilter(bundleOption, notificationId, stringData, keys, request); + service->GetSlotByBundle(bundleOption, slotType, slot); + std::vector bundleOptions; + service->GetAllNotificationEnabledBundles(bundleOptions); + std::vector> profiles; + sptr profile = + new Notification::NotificationDoNotDisturbProfile(); + profiles.emplace_back(profile); + service->AddDoNotDisturbProfiles(profiles); + service->RemoveDoNotDisturbProfiles(profiles); + std::string value = fuzzData->ConsumeRandomLengthString(); + + sptr notificationCheckRequest = + new Notification::NotificationCheckRequest(); + service->RegisterPushCallback(nullptr, notificationCheckRequest); + service->UnregisterPushCallback(); + service->SetAdditionConfig(key1, value); + 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); + std::vector requestPermission = { + OHOS::Notification::OHOS_PERMISSION_NOTIFICATION_CONTROLLER, + OHOS::Notification::OHOS_PERMISSION_NOTIFICATION_AGENT_CONTROLLER, + OHOS::Notification::OHOS_PERMISSION_SET_UNREMOVABLE_NOTIFICATION + }; + SystemHapTokenGet(requestPermission); + OHOS::DoSomethingInterestingWithMyAPI(&fdp); + return 0; +} diff --git a/test/fuzztest/ansmanagerstub_fuzzer/ansmanagerstub_fuzzer.h b/test/fuzztest/ansmanagerstub_fuzzer/ansmanagerstub_fuzzer.h new file mode 100644 index 000000000..a6a9b4924 --- /dev/null +++ b/test/fuzztest/ansmanagerstub_fuzzer/ansmanagerstub_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_ANSMANAGERSTUB_FUZZER_ANSMANAGERSTUB_FUZZER_H +#define TEST_FUZZTEST_ANSMANAGERSTUB_FUZZER_ANSMANAGERSTUB_FUZZER_H + +#include "fuzz_common_base.h" + +#define FUZZ_PROJECT_NAME "ansmanagerstub_fuzzer" + +#endif // TEST_FUZZTEST_ANSMANAGERSTUB_FUZZER_ANSMANAGERSTUB_FUZZER_H \ No newline at end of file diff --git a/test/fuzztest/ansmanagerstub_fuzzer/corpus/init b/test/fuzztest/ansmanagerstub_fuzzer/corpus/init new file mode 100644 index 000000000..1b910144f --- /dev/null +++ b/test/fuzztest/ansmanagerstub_fuzzer/corpus/init @@ -0,0 +1,13 @@ +# 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 diff --git a/test/fuzztest/ansmanagerstub_fuzzer/project.xml b/test/fuzztest/ansmanagerstub_fuzzer/project.xml new file mode 100644 index 000000000..6e8ad2cfd --- /dev/null +++ b/test/fuzztest/ansmanagerstub_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/test/fuzztest/ansmanagerstubannex_fuzzer/BUILD.gn b/test/fuzztest/ansmanagerstubannex_fuzzer/BUILD.gn new file mode 100644 index 000000000..aaca24b7f --- /dev/null +++ b/test/fuzztest/ansmanagerstubannex_fuzzer/BUILD.gn @@ -0,0 +1,120 @@ +# 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("AnsManagerStubAnnexFuzzTest") { + module_out_path = service_fuzz_test_path + fuzz_config_file = + "${component_path}/test/fuzztest/ansmanagerstubannex_fuzzer" + + include_dirs = [ + "${component_path}/test/fuzztest/fuzz_common_base", + "${services_path}/ans/include", + "${core_path}/include" + ] + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + sources = [ "ansmanagerstubannex_fuzzer.cpp" ] + + deps = [ + "${component_path}/test/fuzztest/fuzz_common_base:fuzz_common_base", + "${frameworks_module_ans_path}:ans_innerkits", + "${services_path}/ans:ans_service_sources", + ] + + external_deps = [ + "ability_base:want", + "ability_base:zuri", + "c_utils:utils", + "ffrt:libffrt", + "hilog:libhilog", + "kv_store:distributeddata_inner", + "image_framework:image_native", + "ipc:ipc_single", + "relational_store:native_rdb", + ] + + defines = [] + + if (is_double_framework) { + cflags += [ "-DCONFIG_DUAL_FRAMEWORK" ] + } + + if (distributed_notification_supported) { + defines += [ "DISTRIBUTED_NOTIFICATION_SUPPORTED" ] + deps += [ "${services_path}/distributed:libans_distributed" ] + include_dirs += [ "${services_path}/distributed/include" ] + } + + if (notification_smart_reminder_supported) { + defines += [ "NOTIFICATION_SMART_REMINDER_SUPPORTED" ] + } + + if (player_framework) { + external_deps += [ "player_framework:media_client" ] + defines += [ "PLAYER_FRAMEWORK_ENABLE" ] + } + + if (ans_hitrace_usage) { + external_deps += [ "hitrace:hitrace_meter" ] + defines += [ "HITRACE_METER_ENABLE" ] + } + + if (ans_config_policy_enable) { + external_deps += [ "config_policy:configpolicy_util" ] + defines += [ "CONFIG_POLICY_ENABLE" ] + } + + if (screenlock_mgr_enable) { + external_deps += [ "screenlock_mgr:screenlock_client" ] + defines += [ "SCREENLOCK_MGR_ENABLE" ] + } + + if (distributed_notification_service_feature_summary || + distributed_notification_service_feature_additional_control) { + defines += [ "ENABLE_ANS_EXT_WRAPPER" ] + } + + if (distributed_notification_service_feature_additional_control) { + defines += [ "ENABLE_ANS_ADDITIONAL_CONTROL" ] + } + + if (distributed_notification_service_feature_summary) { + defines += [ "ENABLE_ANS_AGGREGATION" ] + } + + if (telephony_cust) { + defines += [ "ENABLE_ANS_TELEPHONY_CUST_WRAPPER" ] + } + + if (distributed_notification_service_feature_disable_fa_model) { + defines += [ "ANS_DISABLE_FA_MODEL" ] + } + +} + +############################################################################### +group("fuzztest") { + testonly = true + deps = [ ":AnsManagerStubAnnexFuzzTest" ] +} +############################################################################### diff --git a/test/fuzztest/ansmanagerstubannex_fuzzer/ansmanagerstubannex_fuzzer.cpp b/test/fuzztest/ansmanagerstubannex_fuzzer/ansmanagerstubannex_fuzzer.cpp new file mode 100644 index 000000000..9affb2969 --- /dev/null +++ b/test/fuzztest/ansmanagerstubannex_fuzzer/ansmanagerstubannex_fuzzer.cpp @@ -0,0 +1,104 @@ +/* + * 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. + */ + +#define private public +#define protected public +#include "advanced_notification_service.h" +#undef private +#undef protected +#include "ans_dialog_callback_proxy.h" +#include "ans_permission_def.h" +#include "ans_subscriber_proxy.h" +#include "ansmanagerstubannex_fuzzer.h" +#include "reminder_request_timer.h" + +constexpr uint8_t SLOT_TYPE_NUM = 5; + +namespace OHOS { + bool DoSomethingInterestingWithMyAPI(FuzzedDataProvider *fuzzData) + { + auto service = std::make_shared(); + service->InitPublishProcess(); + service->CreateDialogManager(); + std::string stringData = fuzzData->ConsumeRandomLengthString(); + sptr bundleOption = new Notification::NotificationBundleOption(); + bundleOption->SetBundleName(fuzzData->ConsumeRandomLengthString()); + bundleOption->SetUid(fuzzData->ConsumeIntegral()); + int32_t removeReason = fuzzData->ConsumeIntegral(); + std::vector> slots; + bool allowed = fuzzData->ConsumeBool(); + int32_t userId = fuzzData->ConsumeIntegral(); + sptr info = new Notification::NotificationSubscribeInfo(); + uint8_t type = fuzzData->ConsumeIntegral() % SLOT_TYPE_NUM; + Notification::NotificationConstant::SlotType slotType = Notification::NotificationConstant::SlotType(type); + + service->Delete(stringData, removeReason); + service->DeleteByBundle(bundleOption); + service->DeleteAll(); + service->GetSlotsByBundle(bundleOption, slots); + service->UpdateSlots(bundleOption, slots); + + bool enabled = fuzzData->ConsumeBool(); + service->SetNotificationsEnabledForBundle(stringData, enabled); + service->SetNotificationsEnabledForAllBundles(stringData, enabled); + service->SetNotificationsEnabledForSpecialBundle(stringData, bundleOption, enabled); + service->SetShowBadgeEnabledForBundle(bundleOption, enabled); + service->GetShowBadgeEnabledForBundle(bundleOption, enabled); + service->GetShowBadgeEnabled(enabled); + + service->IsAllowedNotify(allowed); + service->IsAllowedNotifySelf(bundleOption, allowed); + service->IsSpecialBundleAllowedNotify(bundleOption, allowed); + service->CancelGroup(stringData, fuzzData->ConsumeRandomLengthString()); + service->RemoveGroupByBundle(bundleOption, stringData); + service->IsDistributedEnabled(enabled); + service->EnableDistributedByBundle(bundleOption, enabled); + service->EnableDistributedSelf(enabled); + service->EnableDistributed(enabled); + service->IsDistributedEnableByBundle(bundleOption, enabled); + int32_t remindType; + service->GetDeviceRemindType(remindType); + std::vector dumpInfo; + service->ShellDump(stringData, stringData, userId, userId, dumpInfo); + + bool support = fuzzData->ConsumeBool(); + service->IsSupportTemplate(stringData, support); + service->IsSpecialUserAllowedNotify(userId, allowed); + + int32_t deviceIds = fuzzData->ConsumeIntegral(); + service->SetNotificationsEnabledByUser(deviceIds, enabled); + service->DeleteAllByUser(userId); + + sptr disturbDate = new Notification::NotificationDoNotDisturbDate(); + service->SetDoNotDisturbDate(disturbDate); + service->GetDoNotDisturbDate(disturbDate); + service->SetEnabledForBundleSlot(bundleOption, slotType, enabled, fuzzData->ConsumeBool()); + return true; + } +} + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + 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 + }; + SystemHapTokenGet(requestPermission); + OHOS::DoSomethingInterestingWithMyAPI(&fdp); + return 0; +} diff --git a/test/fuzztest/ansmanagerstubannex_fuzzer/ansmanagerstubannex_fuzzer.h b/test/fuzztest/ansmanagerstubannex_fuzzer/ansmanagerstubannex_fuzzer.h new file mode 100644 index 000000000..fb24be09b --- /dev/null +++ b/test/fuzztest/ansmanagerstubannex_fuzzer/ansmanagerstubannex_fuzzer.h @@ -0,0 +1,24 @@ +/* + * 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_ANSMANAGERSTUBANNEX_FUZZER_ANSMANAGERSTUBANNEX_FUZZER_H +#define TEST_FUZZTEST_ANSMANAGERSTUBANNEX_FUZZER_ANSMANAGERSTUBANNEX_FUZZER_H + +#include +#include "fuzz_common_base.h" + +#define FUZZ_PROJECT_NAME "ansmanagerstubannex_fuzzer" + +#endif // TEST_FUZZTEST_ANSMANAGERSTUBANNEX_FUZZER_ANSMANAGERSTUBANNEX_FUZZER_H \ No newline at end of file diff --git a/test/fuzztest/ansmanagerstubannex_fuzzer/corpus/init b/test/fuzztest/ansmanagerstubannex_fuzzer/corpus/init new file mode 100644 index 000000000..1b910144f --- /dev/null +++ b/test/fuzztest/ansmanagerstubannex_fuzzer/corpus/init @@ -0,0 +1,13 @@ +# 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 diff --git a/test/fuzztest/ansmanagerstubannex_fuzzer/project.xml b/test/fuzztest/ansmanagerstubannex_fuzzer/project.xml new file mode 100644 index 000000000..6e8ad2cfd --- /dev/null +++ b/test/fuzztest/ansmanagerstubannex_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/test/fuzztest/ansmanagerstubannextwo_fuzzer/BUILD.gn b/test/fuzztest/ansmanagerstubannextwo_fuzzer/BUILD.gn new file mode 100644 index 000000000..faebf7e18 --- /dev/null +++ b/test/fuzztest/ansmanagerstubannextwo_fuzzer/BUILD.gn @@ -0,0 +1,120 @@ +# 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("AnsManagerStubAnnexTwoFuzzTest") { + module_out_path = service_fuzz_test_path + fuzz_config_file = + "${component_path}/test/fuzztest/ansmanagerstubannextwo_fuzzer" + + include_dirs = [ + "${component_path}/test/fuzztest/fuzz_common_base", + "${services_path}/ans/include", + "${core_path}/include" + ] + + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + sources = [ "ansmanagerstubannextwo_fuzzer.cpp" ] + + deps = [ + "${component_path}/test/fuzztest/fuzz_common_base:fuzz_common_base", + "${frameworks_module_ans_path}:ans_innerkits", + "${services_path}/ans:ans_service_sources", + ] + + external_deps = [ + "ability_base:want", + "ability_base:zuri", + "c_utils:utils", + "ffrt:libffrt", + "hilog:libhilog", + "kv_store:distributeddata_inner", + "image_framework:image_native", + "ipc:ipc_single", + "relational_store:native_rdb", + ] + + defines = [] + + if (is_double_framework) { + cflags += [ "-DCONFIG_DUAL_FRAMEWORK" ] + } + + if (distributed_notification_supported) { + defines += [ "DISTRIBUTED_NOTIFICATION_SUPPORTED" ] + deps += [ "${services_path}/distributed:libans_distributed" ] + include_dirs += [ "${services_path}/distributed/include" ] + } + + if (notification_smart_reminder_supported) { + defines += [ "NOTIFICATION_SMART_REMINDER_SUPPORTED" ] + } + + if (player_framework) { + external_deps += [ "player_framework:media_client" ] + defines += [ "PLAYER_FRAMEWORK_ENABLE" ] + } + + if (ans_hitrace_usage) { + external_deps += [ "hitrace:hitrace_meter" ] + defines += [ "HITRACE_METER_ENABLE" ] + } + + if (ans_config_policy_enable) { + external_deps += [ "config_policy:configpolicy_util" ] + defines += [ "CONFIG_POLICY_ENABLE" ] + } + + if (screenlock_mgr_enable) { + external_deps += [ "screenlock_mgr:screenlock_client" ] + defines += [ "SCREENLOCK_MGR_ENABLE" ] + } + + if (distributed_notification_service_feature_summary || + distributed_notification_service_feature_additional_control) { + defines += [ "ENABLE_ANS_EXT_WRAPPER" ] + } + + if (distributed_notification_service_feature_additional_control) { + defines += [ "ENABLE_ANS_ADDITIONAL_CONTROL" ] + } + + if (distributed_notification_service_feature_summary) { + defines += [ "ENABLE_ANS_AGGREGATION" ] + } + + if (telephony_cust) { + defines += [ "ENABLE_ANS_TELEPHONY_CUST_WRAPPER" ] + } + + if (distributed_notification_service_feature_disable_fa_model) { + defines += [ "ANS_DISABLE_FA_MODEL" ] + } +} + +############################################################################### +group("fuzztest") { + testonly = true + deps = [ ":AnsManagerStubAnnexTwoFuzzTest" ] +} +############################################################################### diff --git a/test/fuzztest/ansmanagerstubannextwo_fuzzer/ansmanagerstubannextwo_fuzzer.cpp b/test/fuzztest/ansmanagerstubannextwo_fuzzer/ansmanagerstubannextwo_fuzzer.cpp new file mode 100644 index 000000000..453142a51 --- /dev/null +++ b/test/fuzztest/ansmanagerstubannextwo_fuzzer/ansmanagerstubannextwo_fuzzer.cpp @@ -0,0 +1,60 @@ +/* + * 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. + */ + +#define private public +#define protected public +#include "advanced_notification_service.h" +#undef private +#undef protected +#include "ans_permission_def.h" +#include "ansmanagerstubannextwo_fuzzer.h" + + +constexpr uint8_t SLOT_TYPE_NUM = 5; + +namespace OHOS { + bool DoSomethingInterestingWithMyAPI(FuzzedDataProvider *fuzzData) + { + auto service = std::make_shared(); + service->InitPublishProcess(); + service->CreateDialogManager(); + sptr bundleOption = new Notification::NotificationBundleOption(); + bundleOption->SetBundleName(fuzzData->ConsumeRandomLengthString()); + bundleOption->SetUid(fuzzData->ConsumeIntegral()); + uint8_t type = fuzzData->ConsumeIntegral() % SLOT_TYPE_NUM; + Notification::NotificationConstant::SlotType slotType = Notification::NotificationConstant::SlotType(type); + int32_t userId = fuzzData->ConsumeIntegral(); + bool enabled = fuzzData->ConsumeBool(); + service->GetEnabledForBundleSlot(bundleOption, slotType, enabled); + service->SetSyncNotificationEnabledWithoutApp(userId, enabled); + service->GetSyncNotificationEnabledWithoutApp(userId, enabled); + 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); + std::vector requestPermission = { + OHOS::Notification::OHOS_PERMISSION_NOTIFICATION_CONTROLLER, + OHOS::Notification::OHOS_PERMISSION_NOTIFICATION_AGENT_CONTROLLER, + OHOS::Notification::OHOS_PERMISSION_SET_UNREMOVABLE_NOTIFICATION + }; + SystemHapTokenGet(requestPermission); + OHOS::DoSomethingInterestingWithMyAPI(&fdp); + return 0; +} diff --git a/test/fuzztest/ansmanagerstubannextwo_fuzzer/ansmanagerstubannextwo_fuzzer.h b/test/fuzztest/ansmanagerstubannextwo_fuzzer/ansmanagerstubannextwo_fuzzer.h new file mode 100644 index 000000000..99d038cde --- /dev/null +++ b/test/fuzztest/ansmanagerstubannextwo_fuzzer/ansmanagerstubannextwo_fuzzer.h @@ -0,0 +1,24 @@ +/* + * 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_ANSMANAGERSTUBANNEXTWO_FUZZER_ANSMANAGERSTUBANNEXTWO_FUZZER_H +#define TEST_FUZZTEST_ANSMANAGERSTUBANNEXTWO_FUZZER_ANSMANAGERSTUBANNEXTWO_FUZZER_H + +#include +#include "fuzz_common_base.h" + +#define FUZZ_PROJECT_NAME "ansmanagerstubannextwo_fuzzer" + +#endif // TEST_FUZZTEST_ANSMANAGERSTUBANNEXTWO_FUZZER_ANSMANAGERSTUBANNEXTWO_FUZZER_H \ No newline at end of file diff --git a/test/fuzztest/ansmanagerstubannextwo_fuzzer/corpus/init b/test/fuzztest/ansmanagerstubannextwo_fuzzer/corpus/init new file mode 100644 index 000000000..1b910144f --- /dev/null +++ b/test/fuzztest/ansmanagerstubannextwo_fuzzer/corpus/init @@ -0,0 +1,13 @@ +# 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 diff --git a/test/fuzztest/ansmanagerstubannextwo_fuzzer/project.xml b/test/fuzztest/ansmanagerstubannextwo_fuzzer/project.xml new file mode 100644 index 000000000..6e8ad2cfd --- /dev/null +++ b/test/fuzztest/ansmanagerstubannextwo_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + -- Gitee