From c56730908e6eac1f0f88db13d55eee68ec65cc3c Mon Sep 17 00:00:00 2001 From: liuyanzhi Date: Thu, 20 Oct 2022 19:13:47 +0800 Subject: [PATCH] fixed 44d8ca8 from https://gitee.com/liuyanzhi2020/notification_ans_standard/pulls/654 add reminder fuzz Signed-off-by: liuyanzhi Change-Id: I47f653c770dc15b472ba4dc030e01a322b8f1e1b --- test/fuzztest/BUILD.gn | 3 + test/fuzztest/notification_fuzzer/BUILD.gn | 54 ++++++++++ test/fuzztest/notification_fuzzer/corpus/init | 13 +++ .../notification_fuzzer.cpp | 70 ++++++++++++ .../notification_fuzzer/notification_fuzzer.h | 23 ++++ test/fuzztest/notification_fuzzer/project.xml | 25 +++++ test/fuzztest/readfromparcel_fuzzer/BUILD.gn | 54 ++++++++++ .../readfromparcel_fuzzer/corpus/init | 13 +++ .../readfromparcel_fuzzer/project.xml | 25 +++++ .../readfromparcel_fuzzer.cpp | 91 ++++++++++++++++ .../readfromparcel_fuzzer.h | 23 ++++ test/fuzztest/reminderrequest_fuzzer/BUILD.gn | 55 ++++++++++ .../reminderrequest_fuzzer/corpus/init | 13 +++ .../reminderrequest_fuzzer/project.xml | 25 +++++ .../reminderrequest_fuzzer.cpp | 102 ++++++++++++++++++ .../reminderrequest_fuzzer.h | 23 ++++ 16 files changed, 612 insertions(+) create mode 100644 test/fuzztest/notification_fuzzer/BUILD.gn create mode 100644 test/fuzztest/notification_fuzzer/corpus/init create mode 100644 test/fuzztest/notification_fuzzer/notification_fuzzer.cpp create mode 100644 test/fuzztest/notification_fuzzer/notification_fuzzer.h create mode 100644 test/fuzztest/notification_fuzzer/project.xml create mode 100644 test/fuzztest/readfromparcel_fuzzer/BUILD.gn create mode 100644 test/fuzztest/readfromparcel_fuzzer/corpus/init create mode 100644 test/fuzztest/readfromparcel_fuzzer/project.xml create mode 100644 test/fuzztest/readfromparcel_fuzzer/readfromparcel_fuzzer.cpp create mode 100644 test/fuzztest/readfromparcel_fuzzer/readfromparcel_fuzzer.h create mode 100644 test/fuzztest/reminderrequest_fuzzer/BUILD.gn create mode 100644 test/fuzztest/reminderrequest_fuzzer/corpus/init create mode 100644 test/fuzztest/reminderrequest_fuzzer/project.xml create mode 100644 test/fuzztest/reminderrequest_fuzzer/reminderrequest_fuzzer.cpp create mode 100644 test/fuzztest/reminderrequest_fuzzer/reminderrequest_fuzzer.h diff --git a/test/fuzztest/BUILD.gn b/test/fuzztest/BUILD.gn index 29b780aba..29af3c9bb 100644 --- a/test/fuzztest/BUILD.gn +++ b/test/fuzztest/BUILD.gn @@ -28,9 +28,12 @@ group("fuzztest") { "getnotificationslot_fuzzer:GetNotificationSlotFuzzTest", "getnotificationslotnumasbundle_fuzzer:GetNotificationSlotNumAsBundleFuzzTest", "getnotificationslotsforbundle_fuzzer:GetNotificationSlotsForBundleFuzzTest", + "notification_fuzzer:NotificationFuzzTest", "notificationrequest_fuzzer:NotificationRequestFuzzTest", "publishcontinuoustasknotification_fuzzer:PublishContinuousTaskNotificationFuzzTest", "publishnotification_fuzzer:PublishNotificationFuzzTest", + "readfromparcel_fuzzer:ReadFromParcelFuzzTest", + "reminderrequest_fuzzer:ReminderRequestFuzzTest", "removenotification_fuzzer:RemoveNotificationFuzzTest", "removenotificationsbybundle_fuzzer:RemoveNotificationsByBundleFuzzTest", "removenotificationslot_fuzzer:RemoveNotificationSlotFuzzTest", diff --git a/test/fuzztest/notification_fuzzer/BUILD.gn b/test/fuzztest/notification_fuzzer/BUILD.gn new file mode 100644 index 000000000..42f5e0125 --- /dev/null +++ b/test/fuzztest/notification_fuzzer/BUILD.gn @@ -0,0 +1,54 @@ +# 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") +module_output_path = "${component_name}/fuzztest" + +##############################fuzztest########################################## +ohos_fuzztest("NotificationFuzzTest") { + module_out_path = module_output_path + fuzz_config_file = "${component_path}/test/fuzztest/notification_fuzzer" + + include_dirs = [ "${component_path}/test/fuzztest/fuzz_common_base" ] + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + sources = [ "notification_fuzzer.cpp" ] + + deps = [ + "${component_path}/test/fuzztest/fuzz_common_base:fuzz_common_base", + "${frameworks_module_ans_path}:ans_innerkits", + ] + + external_deps = [ + "ability_base:want", + "ability_base:zuri", + "c_utils:utils", + "hiviewdfx_hilog_native:libhilog", + "multimedia_image_framework:image_native", + "relational_store:native_rdb", + ] +} + +############################################################################### +group("fuzztest") { + testonly = true + deps = [ ":NotificationFuzzTest" ] +} +############################################################################### diff --git a/test/fuzztest/notification_fuzzer/corpus/init b/test/fuzztest/notification_fuzzer/corpus/init new file mode 100644 index 000000000..1b910144f --- /dev/null +++ b/test/fuzztest/notification_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/notification_fuzzer/notification_fuzzer.cpp b/test/fuzztest/notification_fuzzer/notification_fuzzer.cpp new file mode 100644 index 000000000..44e090751 --- /dev/null +++ b/test/fuzztest/notification_fuzzer/notification_fuzzer.cpp @@ -0,0 +1,70 @@ +/* + * 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 "notification.h" +#undef private +#undef protected +#include "notification_fuzzer.h" + +namespace OHOS { + bool DoSomethingInterestingWithMyAPI(const char* data, size_t size) + { + std::string stringData(data); + sptr request = new Notification::NotificationRequest(); + if (request != nullptr) { + request->SetClassification(stringData); + } + Notification::Notification notification(stringData, request); + notification.EnableLight(); + notification.EnableSound(); + notification.EnableVibrate(); + notification.GetBundleName(); + notification.GetCreateBundle(); + notification.GetLabel(); + notification.GetLedLightColor(); + notification.GetLockscreenVisibleness(); + notification.GetGroup(); + notification.GetId(); + notification.GetKey(); + notification.GetNotificationRequest(); + notification.GetPostTime(); + notification.GetSound(); + notification.GetUid(); + notification.GetPid(); + notification.IsUnremovable(); + notification.GetVibrationStyle(); + notification.IsGroup(); + notification.IsFloatingIcon(); + notification.GetRemindType(); + notification.IsRemoveAllowed(); + Parcel parcel; + return notification.MarshallingBool(parcel); + } +} + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data */ + char *ch = ParseData(data, size); + if (ch != nullptr && size >= GetU32Size()) { + OHOS::DoSomethingInterestingWithMyAPI(ch, size); + free(ch); + ch = nullptr; + } + return 0; +} diff --git a/test/fuzztest/notification_fuzzer/notification_fuzzer.h b/test/fuzztest/notification_fuzzer/notification_fuzzer.h new file mode 100644 index 000000000..59b3a5174 --- /dev/null +++ b/test/fuzztest/notification_fuzzer/notification_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_NOTIFICATION_FUZZER_NOTIFICATION_FUZZER_H +#define TEST_FUZZTEST_NOTIFICATION_FUZZER_NOTIFICATION_FUZZER_H + +#include "fuzz_common_base.h" + +#define FUZZ_PROJECT_NAME "notification_fuzzer" + +#endif // TEST_FUZZTEST_NOTIFICATION_FUZZER_NOTIFICATION_FUZZER_H \ No newline at end of file diff --git a/test/fuzztest/notification_fuzzer/project.xml b/test/fuzztest/notification_fuzzer/project.xml new file mode 100644 index 000000000..6e8ad2cfd --- /dev/null +++ b/test/fuzztest/notification_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/test/fuzztest/readfromparcel_fuzzer/BUILD.gn b/test/fuzztest/readfromparcel_fuzzer/BUILD.gn new file mode 100644 index 000000000..e097b97e0 --- /dev/null +++ b/test/fuzztest/readfromparcel_fuzzer/BUILD.gn @@ -0,0 +1,54 @@ +# 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") +module_output_path = "${component_name}/fuzztest" + +##############################fuzztest########################################## +ohos_fuzztest("ReadFromParcelFuzzTest") { + module_out_path = module_output_path + fuzz_config_file = "${component_path}/test/fuzztest/readfromparcel_fuzzer" + + include_dirs = [ "${component_path}/test/fuzztest/fuzz_common_base" ] + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + sources = [ "readfromparcel_fuzzer.cpp" ] + + deps = [ + "${component_path}/test/fuzztest/fuzz_common_base:fuzz_common_base", + "${frameworks_module_ans_path}:ans_innerkits", + ] + + external_deps = [ + "ability_base:want", + "ability_base:zuri", + "c_utils:utils", + "hiviewdfx_hilog_native:libhilog", + "multimedia_image_framework:image_native", + "relational_store:native_rdb", + ] +} + +############################################################################### +group("fuzztest") { + testonly = true + deps = [ ":ReadFromParcelFuzzTest" ] +} +############################################################################### diff --git a/test/fuzztest/readfromparcel_fuzzer/corpus/init b/test/fuzztest/readfromparcel_fuzzer/corpus/init new file mode 100644 index 000000000..1b910144f --- /dev/null +++ b/test/fuzztest/readfromparcel_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/readfromparcel_fuzzer/project.xml b/test/fuzztest/readfromparcel_fuzzer/project.xml new file mode 100644 index 000000000..6e8ad2cfd --- /dev/null +++ b/test/fuzztest/readfromparcel_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/test/fuzztest/readfromparcel_fuzzer/readfromparcel_fuzzer.cpp b/test/fuzztest/readfromparcel_fuzzer/readfromparcel_fuzzer.cpp new file mode 100644 index 000000000..5de86ce08 --- /dev/null +++ b/test/fuzztest/readfromparcel_fuzzer/readfromparcel_fuzzer.cpp @@ -0,0 +1,91 @@ +/* + * 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 "notification.h" +#undef private +#undef protected +#include "readfromparcel_fuzzer.h" + +namespace OHOS { + namespace { + constexpr uint8_t ENABLE = 2; + constexpr uint8_t SOURCE_TYPE = 3; + constexpr uint8_t SLOT_VISIBLENESS_TYPE_NUM = 4; + constexpr uint8_t SLOT_TYPE_NUM = 5; + } + bool DoSomethingInterestingWithMyAPI(const char* data, size_t size) + { + std::string stringData(data); + sptr request = new Notification::NotificationRequest(); + if (request != nullptr) { + request->SetClassification(stringData); + } + Notification::Notification notification(request); + Parcel parcel; + notification.MarshallingString(parcel); + notification.MarshallingInt32(parcel); + notification.MarshallingInt64(parcel); + notification.MarshallingParcelable(parcel); + notification.Marshalling(parcel); + notification.ReadFromParcelBool(parcel); + notification.ReadFromParcelString(parcel); + notification.ReadFromParcelInt32(parcel); + notification.ReadFromParcelInt64(parcel); + notification.ReadFromParcelParcelable(parcel); + notification.Unmarshalling(parcel); + bool enabled = *data % ENABLE; + notification.SetEnableSound(enabled); + notification.SetEnableLight(enabled); + notification.SetEnableVibration(enabled); + int32_t color = static_cast(GetU32Data(data)); + notification.SetLedLightColor(color); + uint8_t visibleness = *data % SLOT_VISIBLENESS_TYPE_NUM; + Notification::NotificationConstant::VisiblenessType visiblenessType = + Notification::NotificationConstant::VisiblenessType(visibleness); + notification.SetLockScreenVisbleness(visiblenessType); + int64_t time = 2; + notification.SetPostTime(time); + std::vector style; + style.emplace_back(time); + notification.SetVibrationStyle(style); + int32_t remindType = static_cast(*data % SLOT_TYPE_NUM); + Notification::NotificationConstant::RemindType remind = + Notification::NotificationConstant::RemindType(remindType); + notification.SetRemindType(remind); + notification.GenerateNotificationKey(stringData, color, color, stringData, color); + notification.SetRemoveAllowed(enabled); + int32_t source = static_cast(*data % SOURCE_TYPE); + Notification::NotificationConstant::SourceType sourceType = + Notification::NotificationConstant::SourceType(source); + notification.SetSourceType(sourceType); + notification.Dump(); + return notification.ReadFromParcel(parcel); + } +} + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data */ + char *ch = ParseData(data, size); + if (ch != nullptr && size >= GetU32Size()) { + OHOS::DoSomethingInterestingWithMyAPI(ch, size); + free(ch); + ch = nullptr; + } + return 0; +} diff --git a/test/fuzztest/readfromparcel_fuzzer/readfromparcel_fuzzer.h b/test/fuzztest/readfromparcel_fuzzer/readfromparcel_fuzzer.h new file mode 100644 index 000000000..e0617c5e6 --- /dev/null +++ b/test/fuzztest/readfromparcel_fuzzer/readfromparcel_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_READFROMPARCEL_FUZZER_READFROMPARCEL_FUZZER_H +#define TEST_FUZZTEST_READFROMPARCEL_FUZZER_READFROMPARCEL_FUZZER_H + +#include "fuzz_common_base.h" + +#define FUZZ_PROJECT_NAME "readfromparcel_fuzzer" + +#endif // TEST_FUZZTEST_READFROMPARCEL_FUZZER_READFROMPARCEL_FUZZER_H \ No newline at end of file diff --git a/test/fuzztest/reminderrequest_fuzzer/BUILD.gn b/test/fuzztest/reminderrequest_fuzzer/BUILD.gn new file mode 100644 index 000000000..122306ed6 --- /dev/null +++ b/test/fuzztest/reminderrequest_fuzzer/BUILD.gn @@ -0,0 +1,55 @@ +# 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") +module_output_path = "${component_name}/fuzztest" + +##############################fuzztest########################################## +ohos_fuzztest("ReminderRequestFuzzTest") { + module_out_path = module_output_path + fuzz_config_file = "${component_path}/test/fuzztest/reminderrequest_fuzzer" + + include_dirs = [ "${component_path}/test/fuzztest/fuzz_common_base" ] + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + sources = [ "reminderrequest_fuzzer.cpp" ] + + deps = [ + "${component_path}/test/fuzztest/fuzz_common_base:fuzz_common_base", + "${core_path}:ans_core", + "${frameworks_module_ans_path}:ans_innerkits", + ] + + external_deps = [ + "ability_base:want", + "ability_base:zuri", + "c_utils:utils", + "hiviewdfx_hilog_native:libhilog", + "multimedia_image_framework:image_native", + "relational_store:native_rdb", + ] +} + +############################################################################### +group("fuzztest") { + testonly = true + deps = [ ":ReminderRequestFuzzTest" ] +} +############################################################################### diff --git a/test/fuzztest/reminderrequest_fuzzer/corpus/init b/test/fuzztest/reminderrequest_fuzzer/corpus/init new file mode 100644 index 000000000..1b910144f --- /dev/null +++ b/test/fuzztest/reminderrequest_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/reminderrequest_fuzzer/project.xml b/test/fuzztest/reminderrequest_fuzzer/project.xml new file mode 100644 index 000000000..6e8ad2cfd --- /dev/null +++ b/test/fuzztest/reminderrequest_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/test/fuzztest/reminderrequest_fuzzer/reminderrequest_fuzzer.cpp b/test/fuzztest/reminderrequest_fuzzer/reminderrequest_fuzzer.cpp new file mode 100644 index 000000000..4d6cdaea2 --- /dev/null +++ b/test/fuzztest/reminderrequest_fuzzer/reminderrequest_fuzzer.cpp @@ -0,0 +1,102 @@ +/* + * 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 "reminder_request.h" +#undef private +#undef protected +#include "reminderrequest_fuzzer.h" + +namespace OHOS { + namespace { + constexpr uint8_t ENABLE = 2; + constexpr uint8_t ACTION_BUTTON_TYPE = 3; + constexpr uint8_t COLUMN_TYPE = 2; + constexpr uint8_t SLOT_TYPE_NUM = 5; + } + bool DoSomethingInterestingWithMyAPI(const char* data, size_t size) + { + std::string stringData(data); + int32_t reminderId = static_cast(GetU32Data(data)); + Notification::ReminderRequest reminderRequest(reminderId); + reminderRequest.CanRemove(); + reminderRequest.CanShow(); + reminderRequest.Dump(); + uint8_t types = *data % ACTION_BUTTON_TYPE; + Notification::ReminderRequest::ActionButtonType type = + Notification::ReminderRequest::ActionButtonType(types); + reminderRequest.SetActionButton(stringData, type); + reminderRequest.SetContent(stringData); + reminderRequest.SetExpiredContent(stringData); + bool enabled = *data % ENABLE; + reminderRequest.SetExpired(enabled); + reminderRequest.InitReminderId(); + reminderRequest.InitUserId(reminderId); + reminderRequest.InitUid(reminderId); + reminderRequest.IsExpired(); + reminderRequest.IsShowing(); + reminderRequest.OnClose(enabled); + reminderRequest.OnDateTimeChange(); + uint64_t oriTriggerTime = 2; + uint64_t optTriggerTimes = 2; + reminderRequest.HandleSysTimeChange(oriTriggerTime, optTriggerTimes); + uint64_t oldZoneTriggerTime = 1; + uint64_t newZoneTriggerTime = 2; + uint64_t optTriggerTime = 3; + reminderRequest.HandleTimeZoneChange(oldZoneTriggerTime, newZoneTriggerTime, optTriggerTime); + reminderRequest.OnSameNotificationIdCovered(); + reminderRequest.OnShow(enabled, enabled, enabled); + reminderRequest.OnShowFail(); + reminderRequest.OnSnooze(); + reminderRequest.OnStart(); + reminderRequest.OnStop(); + reminderRequest.OnTerminate(); + reminderRequest.OnTimeZoneChange(); + std::shared_ptr resultSet = + std::make_shared(); + uint8_t column = *data % COLUMN_TYPE; + Notification::ReminderRequest::DbRecoveryType columnType = + Notification::ReminderRequest::DbRecoveryType(column); + reminderRequest.RecoverInt64FromDb(resultSet, stringData, columnType); + reminderRequest.RecoverFromDb(resultSet); + reminderRequest.RecoverActionButton(resultSet); + reminderRequest.StringSplit(stringData, stringData); + reminderRequest.RecoverWantAgent(stringData, *data); + std::shared_ptr< Notification::ReminderRequest::MaxScreenAgentInfo> maxScreenWantAgentInfo = + std::make_shared< Notification::ReminderRequest::MaxScreenAgentInfo>(); + reminderRequest.SetMaxScreenWantAgentInfo(maxScreenWantAgentInfo); + reminderRequest.SetNotificationId(reminderId); + uint8_t typed = *data % SLOT_TYPE_NUM; + Notification::NotificationConstant::SlotType slotType = + Notification::NotificationConstant::SlotType(typed); + reminderRequest.SetSlotType(slotType); + reminderRequest.SetSnoozeContent(stringData); + return reminderRequest.ShouldShowImmediately(); + } +} + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data */ + char *ch = ParseData(data, size); + if (ch != nullptr && size >= GetU32Size()) { + OHOS::DoSomethingInterestingWithMyAPI(ch, size); + free(ch); + ch = nullptr; + } + return 0; +} diff --git a/test/fuzztest/reminderrequest_fuzzer/reminderrequest_fuzzer.h b/test/fuzztest/reminderrequest_fuzzer/reminderrequest_fuzzer.h new file mode 100644 index 000000000..f6d20f9a0 --- /dev/null +++ b/test/fuzztest/reminderrequest_fuzzer/reminderrequest_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_REMINDERREQUEST_FUZZER_REMINDERREQUEST_FUZZER_H +#define TEST_FUZZTEST_REMINDERREQUEST_FUZZER_REMINDERREQUEST_FUZZER_H + +#include "fuzz_common_base.h" + +#define FUZZ_PROJECT_NAME "reminderrequest_fuzzer" + +#endif // TEST_FUZZTEST_REMINDERREQUEST_FUZZER_REMINDERREQUEST_FUZZER_H \ No newline at end of file -- Gitee