From cf5c729f4e8677be4f0b8f02566d72993dc54efa Mon Sep 17 00:00:00 2001 From: liuyanzhi Date: Fri, 21 Oct 2022 20:25:14 +0800 Subject: [PATCH] fixed 11feea7 from https://gitee.com/liuyanzhi2020/notification_ans_standard/pulls/661 add fuzz test Signed-off-by: liuyanzhi Change-Id: I1e3874d8a124f0157cbe4b722adb2e1a9030ebd1 --- test/fuzztest/BUILD.gn | 2 + .../reminderrequestannex_fuzzer/BUILD.gn | 56 ++++++++++++ .../reminderrequestannex_fuzzer/corpus/init | 13 +++ .../reminderrequestannex_fuzzer/project.xml | 25 ++++++ .../reminderrequestannex_fuzzer.cpp | 86 +++++++++++++++++++ .../reminderrequestannex_fuzzer.h | 23 +++++ .../reminderrequestcontinuate_fuzzer/BUILD.gn | 56 ++++++++++++ .../corpus/init | 13 +++ .../project.xml | 25 ++++++ .../reminderrequestcontinuate_fuzzer.cpp | 45 ++++++++++ .../reminderrequestcontinuate_fuzzer.h | 23 +++++ 11 files changed, 367 insertions(+) create mode 100644 test/fuzztest/reminderrequestannex_fuzzer/BUILD.gn create mode 100644 test/fuzztest/reminderrequestannex_fuzzer/corpus/init create mode 100644 test/fuzztest/reminderrequestannex_fuzzer/project.xml create mode 100644 test/fuzztest/reminderrequestannex_fuzzer/reminderrequestannex_fuzzer.cpp create mode 100644 test/fuzztest/reminderrequestannex_fuzzer/reminderrequestannex_fuzzer.h create mode 100644 test/fuzztest/reminderrequestcontinuate_fuzzer/BUILD.gn create mode 100644 test/fuzztest/reminderrequestcontinuate_fuzzer/corpus/init create mode 100644 test/fuzztest/reminderrequestcontinuate_fuzzer/project.xml create mode 100644 test/fuzztest/reminderrequestcontinuate_fuzzer/reminderrequestcontinuate_fuzzer.cpp create mode 100644 test/fuzztest/reminderrequestcontinuate_fuzzer/reminderrequestcontinuate_fuzzer.h diff --git a/test/fuzztest/BUILD.gn b/test/fuzztest/BUILD.gn index 29af3c9bb..c6c14e7a9 100644 --- a/test/fuzztest/BUILD.gn +++ b/test/fuzztest/BUILD.gn @@ -34,6 +34,8 @@ group("fuzztest") { "publishnotification_fuzzer:PublishNotificationFuzzTest", "readfromparcel_fuzzer:ReadFromParcelFuzzTest", "reminderrequest_fuzzer:ReminderRequestFuzzTest", + "reminderrequestannex_fuzzer:ReminderRequestAnnexFuzzTest", + "reminderrequestcontinuate_fuzzer:ReminderRequestContinuateFuzzTest", "removenotification_fuzzer:RemoveNotificationFuzzTest", "removenotificationsbybundle_fuzzer:RemoveNotificationsByBundleFuzzTest", "removenotificationslot_fuzzer:RemoveNotificationSlotFuzzTest", diff --git a/test/fuzztest/reminderrequestannex_fuzzer/BUILD.gn b/test/fuzztest/reminderrequestannex_fuzzer/BUILD.gn new file mode 100644 index 000000000..1e4aae331 --- /dev/null +++ b/test/fuzztest/reminderrequestannex_fuzzer/BUILD.gn @@ -0,0 +1,56 @@ +# 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("ReminderRequestAnnexFuzzTest") { + module_out_path = module_output_path + fuzz_config_file = + "${component_path}/test/fuzztest/reminderrequestannex_fuzzer" + + include_dirs = [ "${component_path}/test/fuzztest/fuzz_common_base" ] + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + sources = [ "reminderrequestannex_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 = [ ":ReminderRequestAnnexFuzzTest" ] +} +############################################################################### diff --git a/test/fuzztest/reminderrequestannex_fuzzer/corpus/init b/test/fuzztest/reminderrequestannex_fuzzer/corpus/init new file mode 100644 index 000000000..1b910144f --- /dev/null +++ b/test/fuzztest/reminderrequestannex_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/reminderrequestannex_fuzzer/project.xml b/test/fuzztest/reminderrequestannex_fuzzer/project.xml new file mode 100644 index 000000000..6e8ad2cfd --- /dev/null +++ b/test/fuzztest/reminderrequestannex_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/test/fuzztest/reminderrequestannex_fuzzer/reminderrequestannex_fuzzer.cpp b/test/fuzztest/reminderrequestannex_fuzzer/reminderrequestannex_fuzzer.cpp new file mode 100644 index 000000000..87483032c --- /dev/null +++ b/test/fuzztest/reminderrequestannex_fuzzer/reminderrequestannex_fuzzer.cpp @@ -0,0 +1,86 @@ +/* + * 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 "reminderrequestannex_fuzzer.h" + +namespace OHOS { + bool DoSomethingInterestingWithMyAPI(const char* data, size_t size) + { + std::string stringData(data); + int32_t reminderId = static_cast(GetU32Data(data)); + Notification::ReminderRequest reminderRequest(reminderId); + reminderRequest.SetSnoozeTimes(*data); + reminderRequest.SetSnoozeTimesDynamic(*data); + uint64_t timeIntervalInSeconds = 1; + reminderRequest.SetTimeInterval(timeIntervalInSeconds); + reminderRequest.SetTitle(stringData); + reminderRequest.SetTriggerTimeInMilli(timeIntervalInSeconds); + std::shared_ptr< Notification::ReminderRequest::WantAgentInfo> wantAgentInfo = + std::make_shared< Notification::ReminderRequest::WantAgentInfo>(); + reminderRequest.SetWantAgentInfo(wantAgentInfo); + reminderRequest.ShouldShowImmediately(); + reminderRequest.GetActionButtons(); + reminderRequest.GetContent(); + reminderRequest.GetExpiredContent(); + reminderRequest.GetMaxScreenWantAgentInfo(); + reminderRequest.GetNotificationId(); + reminderRequest.GetNotificationRequest(); + reminderRequest.GetReminderId(); + reminderRequest.GetReminderTimeInMilli(); + reminderRequest.SetReminderId(reminderId); + reminderRequest.SetReminderTimeInMilli(timeIntervalInSeconds); + uint64_t ringDurationInSeconds = 0; + reminderRequest.SetRingDuration(ringDurationInSeconds); + reminderRequest.GetSlotType(); + reminderRequest.GetSnoozeContent(); + reminderRequest.GetSnoozeTimes(); + reminderRequest.GetSnoozeTimesDynamic(); + reminderRequest.GetState(); + reminderRequest.GetTimeInterval(); + reminderRequest.GetTriggerTimeInMilli(); + reminderRequest.GetUserId(); + reminderRequest.GetUid(); + reminderRequest.GetWantAgentInfo(); + reminderRequest.GetReminderType(); + reminderRequest.GetRingDuration(); + reminderRequest.UpdateNextReminder(); + reminderRequest.SetNextTriggerTime(); + Parcel parcel; + reminderRequest.Marshalling(parcel); + reminderRequest.Unmarshalling(parcel); + reminderRequest.ReadFromParcel(parcel); + reminderRequest.InitNotificationRequest(); + reminderRequest.InitServerObj(); + return reminderRequest.IsAlerting(); + } +} + +/* 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/reminderrequestannex_fuzzer/reminderrequestannex_fuzzer.h b/test/fuzztest/reminderrequestannex_fuzzer/reminderrequestannex_fuzzer.h new file mode 100644 index 000000000..8dd7714cf --- /dev/null +++ b/test/fuzztest/reminderrequestannex_fuzzer/reminderrequestannex_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_REMINDERREQUESTCONTINUATE_FUZZER_REMINDERREQUESTCONTINUATE_FUZZER_H +#define TEST_FUZZTEST_REMINDERREQUESTCONTINUATE_FUZZER_REMINDERREQUESTCONTINUATE_FUZZER_H + +#include "fuzz_common_base.h" + +#define FUZZ_PROJECT_NAME "reminderrequestcontinuate_fuzzer" + +#endif // TEST_FUZZTEST_REMINDERREQUESTCONTINUATE_FUZZER_REMINDERREQUESTCONTINUATE_FUZZER_H \ No newline at end of file diff --git a/test/fuzztest/reminderrequestcontinuate_fuzzer/BUILD.gn b/test/fuzztest/reminderrequestcontinuate_fuzzer/BUILD.gn new file mode 100644 index 000000000..434728b57 --- /dev/null +++ b/test/fuzztest/reminderrequestcontinuate_fuzzer/BUILD.gn @@ -0,0 +1,56 @@ +# 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("ReminderRequestContinuateFuzzTest") { + module_out_path = module_output_path + fuzz_config_file = + "${component_path}/test/fuzztest/reminderrequestcontinuate_fuzzer" + + include_dirs = [ "${component_path}/test/fuzztest/fuzz_common_base" ] + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + sources = [ "reminderrequestcontinuate_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 = [ ":ReminderRequestContinuateFuzzTest" ] +} +############################################################################### diff --git a/test/fuzztest/reminderrequestcontinuate_fuzzer/corpus/init b/test/fuzztest/reminderrequestcontinuate_fuzzer/corpus/init new file mode 100644 index 000000000..1b910144f --- /dev/null +++ b/test/fuzztest/reminderrequestcontinuate_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/reminderrequestcontinuate_fuzzer/project.xml b/test/fuzztest/reminderrequestcontinuate_fuzzer/project.xml new file mode 100644 index 000000000..6e8ad2cfd --- /dev/null +++ b/test/fuzztest/reminderrequestcontinuate_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/test/fuzztest/reminderrequestcontinuate_fuzzer/reminderrequestcontinuate_fuzzer.cpp b/test/fuzztest/reminderrequestcontinuate_fuzzer/reminderrequestcontinuate_fuzzer.cpp new file mode 100644 index 000000000..ef2550eac --- /dev/null +++ b/test/fuzztest/reminderrequestcontinuate_fuzzer/reminderrequestcontinuate_fuzzer.cpp @@ -0,0 +1,45 @@ +/* + * 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 "reminderrequestcontinuate_fuzzer.h" + +namespace OHOS { + bool DoSomethingInterestingWithMyAPI(const char* data, size_t size) + { + std::string stringData(data); + int32_t reminderId = static_cast(GetU32Data(data)); + Notification::ReminderRequest reminderRequest(reminderId); + reminderRequest.GetButtonInfo(); + return reminderRequest.GetUid(reminderId, stringData); + } +} + +/* 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/reminderrequestcontinuate_fuzzer/reminderrequestcontinuate_fuzzer.h b/test/fuzztest/reminderrequestcontinuate_fuzzer/reminderrequestcontinuate_fuzzer.h new file mode 100644 index 000000000..1f4efe2d8 --- /dev/null +++ b/test/fuzztest/reminderrequestcontinuate_fuzzer/reminderrequestcontinuate_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_REMINDERREQUESTANNEX_FUZZER_REMINDERREQUESTANNEX_FUZZER_H +#define TEST_FUZZTEST_REMINDERREQUESTANNEX_FUZZER_REMINDERREQUESTANNEX_FUZZER_H + +#include "fuzz_common_base.h" + +#define FUZZ_PROJECT_NAME "reminderrequestcontinuate_fuzzer" + +#endif // TEST_FUZZTEST_REMINDERREQUESTANNEX_FUZZER_REMINDERREQUESTANNEX_FUZZER_H \ No newline at end of file -- Gitee