From 753284563022adcac3359d41ea67a9cbec736322 Mon Sep 17 00:00:00 2001 From: liuyanzhi Date: Tue, 11 Jul 2023 02:44:43 +0000 Subject: [PATCH] fix fuzz Signed-off-by: liuyanzhi Change-Id: I59256c4cfa4a5fef5f93dde86432bffa6880072c --- .../advancednotificationservice_fuzzer.cpp | 76 +++++++++---------- 1 file changed, 34 insertions(+), 42 deletions(-) diff --git a/test/fuzztest/advancednotificationservice_fuzzer/advancednotificationservice_fuzzer.cpp b/test/fuzztest/advancednotificationservice_fuzzer/advancednotificationservice_fuzzer.cpp index 90c5726f3..ad39f6eb5 100644 --- a/test/fuzztest/advancednotificationservice_fuzzer/advancednotificationservice_fuzzer.cpp +++ b/test/fuzztest/advancednotificationservice_fuzzer/advancednotificationservice_fuzzer.cpp @@ -23,6 +23,7 @@ #include "notification_request.h" constexpr uint8_t SLOT_TYPE_NUM = 5; +constexpr uint8_t ENABLE = 2; namespace OHOS { @@ -30,17 +31,14 @@ namespace OHOS { bool DoSomethingInterestingWithMyAPI(const char* data, size_t size) { - std::string stringData(data); + std::string stringData(data, size); sptr notification = new Notification::NotificationRequest(); - const std::string label = "this is a notification label"; - const std::string deviceId = "this is a notification deviceId"; - advancedNotificationService.Publish(label, notification); - int notificationId = 1; - advancedNotificationService.Cancel(notificationId, label); + advancedNotificationService.Publish(stringData, notification); + int notificationId = static_cast(GetU32Data(data)); + advancedNotificationService.Cancel(notificationId, stringData); advancedNotificationService.CancelAll(); - const std::string representativeBundle = "this is a notification representativeBundle"; - int32_t userId = 1; - advancedNotificationService.CancelAsBundle(notificationId, representativeBundle, userId); + int32_t userId = static_cast(GetU32Data(data)); + advancedNotificationService.CancelAsBundle(notificationId, stringData, userId); uint8_t type = *data % SLOT_TYPE_NUM; Notification::NotificationConstant::SlotType slotType = Notification::NotificationConstant::SlotType(type); advancedNotificationService.AddSlotByType(slotType); @@ -52,7 +50,7 @@ namespace OHOS { advancedNotificationService.GetSlotByType(slotType, slot); advancedNotificationService.GetSlots(slots); sptr bundleOption = new Notification::NotificationBundleOption(); - uint64_t num = 1; + uint64_t num = static_cast(GetU32Data(data)); advancedNotificationService.GetSlotNumAsBundle(bundleOption, num); std::vector> notifications; advancedNotificationService.GetActiveNotifications(notifications); @@ -61,32 +59,29 @@ namespace OHOS { advancedNotificationService.GetAllActiveNotifications(notificationss); std::vector key; advancedNotificationService.GetSpecialActiveNotifications(key, notificationss); - std::string agent = "this is a notification agent"; - advancedNotificationService.SetNotificationAgent(agent); - advancedNotificationService.GetNotificationAgent(agent); - bool canPublish = true; - advancedNotificationService.CanPublishAsBundle(representativeBundle, canPublish); - advancedNotificationService.PublishAsBundle(notification, representativeBundle); + advancedNotificationService.SetNotificationAgent(stringData); + advancedNotificationService.GetNotificationAgent(stringData); + bool canPublish = *data % ENABLE; + advancedNotificationService.CanPublishAsBundle(stringData, canPublish); + advancedNotificationService.PublishAsBundle(notification, stringData); advancedNotificationService.SetNotificationBadgeNum(num); - int importance = 1; + int importance = static_cast(GetU32Data(data)); advancedNotificationService.GetBundleImportance(importance); - bool granted = true; + bool granted = *data % ENABLE; advancedNotificationService.HasNotificationPolicyAccessPermission(granted); - int32_t removeReason = 1; - advancedNotificationService.RemoveNotification(bundleOption, notificationId, label, removeReason); + int32_t removeReason = static_cast(GetU32Data(data)); + advancedNotificationService.RemoveNotification(bundleOption, notificationId, stringData, removeReason); advancedNotificationService.RemoveAllNotifications(bundleOption); - const std::string keys = "this is a notification keys"; - advancedNotificationService.Delete(keys, removeReason); + advancedNotificationService.Delete(stringData, removeReason); advancedNotificationService.DeleteByBundle(bundleOption); advancedNotificationService.DeleteAll(); advancedNotificationService.GetSlotsByBundle(bundleOption, slots); advancedNotificationService.UpdateSlots(bundleOption, slots); - advancedNotificationService.RequestEnableNotification(deviceId); - const std::string bundle = "this is a notification bundle"; - bool enabled = true; - advancedNotificationService.SetNotificationsEnabledForBundle(bundle, enabled); - advancedNotificationService.SetNotificationsEnabledForAllBundles(deviceId, enabled); - advancedNotificationService.SetNotificationsEnabledForSpecialBundle(deviceId, bundleOption, enabled); + advancedNotificationService.RequestEnableNotification(stringData); + bool enabled = *data % ENABLE; + advancedNotificationService.SetNotificationsEnabledForBundle(stringData, enabled); + advancedNotificationService.SetNotificationsEnabledForAllBundles(stringData, enabled); + advancedNotificationService.SetNotificationsEnabledForSpecialBundle(stringData, bundleOption, enabled); advancedNotificationService.SetShowBadgeEnabledForBundle(bundleOption, enabled); advancedNotificationService.GetShowBadgeEnabledForBundle(bundleOption, enabled); advancedNotificationService.GetShowBadgeEnabled(enabled); @@ -94,17 +89,16 @@ namespace OHOS { sptr info = new Notification::NotificationSubscribeInfo(); advancedNotificationService.Subscribe(subscriber, info); advancedNotificationService.Unsubscribe(subscriber, info); - bool allowed = true; + bool allowed = *data % ENABLE; advancedNotificationService.IsAllowedNotify(allowed); advancedNotificationService.IsAllowedNotifySelf(allowed); advancedNotificationService.IsSpecialBundleAllowedNotify(bundleOption, allowed); - const std::string groupName = "this is a notification groupName"; - advancedNotificationService.CancelGroup(groupName); - advancedNotificationService.RemoveGroupByBundle(bundleOption, groupName); + advancedNotificationService.CancelGroup(stringData); + advancedNotificationService.RemoveGroupByBundle(bundleOption, stringData); sptr date = new Notification::NotificationDoNotDisturbDate(); advancedNotificationService.SetDoNotDisturbDate(date); advancedNotificationService.GetDoNotDisturbDate(date); - bool doesSupport = true; + bool doesSupport = *data % ENABLE; advancedNotificationService.DoesSupportDoNotDisturbMode(doesSupport); advancedNotificationService.IsDistributedEnabled(enabled); advancedNotificationService.EnableDistributedByBundle(bundleOption, enabled); @@ -115,31 +109,29 @@ namespace OHOS { advancedNotificationService.GetDeviceRemindType(remindType); sptr request = new Notification::NotificationRequest(); advancedNotificationService.PublishContinuousTaskNotification(request); - advancedNotificationService.CancelContinuousTaskNotification(label, notificationId); + advancedNotificationService.CancelContinuousTaskNotification(stringData, notificationId); sptr reminder = new Notification::ReminderRequest(); advancedNotificationService.PublishReminder(reminder); - const int32_t reminderId = 1; + int32_t reminderId = static_cast(GetU32Data(data)); advancedNotificationService.CancelReminder(reminderId); std::vector> reminders; advancedNotificationService.GetValidReminders(reminders); advancedNotificationService.CancelAllReminders(); - const std::string templateName = "this is a notification templateName"; - bool support = true; - advancedNotificationService.IsSupportTemplate(templateName, support); + bool support = *data % ENABLE; + advancedNotificationService.IsSupportTemplate(stringData, support); advancedNotificationService.IsSpecialUserAllowedNotify(userId, allowed); - const int32_t deviceIds = 1; + int32_t deviceIds = static_cast(GetU32Data(data)); advancedNotificationService.SetNotificationsEnabledByUser(deviceIds, enabled); advancedNotificationService.DeleteAllByUser(userId); advancedNotificationService.SetDoNotDisturbDate(date); advancedNotificationService.GetDoNotDisturbDate(date); advancedNotificationService.SetEnabledForBundleSlot(bundleOption, slotType, enabled); advancedNotificationService.GetEnabledForBundleSlot(bundleOption, slotType, enabled); - const std::string cmd = "this is a notification cmd"; std::vector dumpInfo; - advancedNotificationService.ShellDump(cmd, bundle, userId, dumpInfo); + advancedNotificationService.ShellDump(stringData, stringData, userId, dumpInfo); advancedNotificationService.SetSyncNotificationEnabledWithoutApp(userId, enabled); advancedNotificationService.GetSyncNotificationEnabledWithoutApp(userId, enabled); - int32_t badgeNum = 1; + int32_t badgeNum = static_cast(GetU32Data(data)); advancedNotificationService.SetBadgeNumber(badgeNum); return true; -- Gitee