diff --git a/test/fuzztest/BUILD.gn b/test/fuzztest/BUILD.gn index 0c561b3eed55dd8c4235416a69838656481b4951..dc1e3f310be68af8ecfdb2e2765490d3bb6a90d4 100644 --- a/test/fuzztest/BUILD.gn +++ b/test/fuzztest/BUILD.gn @@ -21,11 +21,13 @@ group("fuzztest") { "cancelasbundle_fuzzer:CancelAsBundleFuzzTest", "cancelgroup_fuzzer:CancelGroupFuzzTest", "cancelnotification_fuzzer:CancelNotificationFuzzTest", + "enabledistributed_fuzzer:EnableDistributedFuzzTest", "getallactivenotifications_fuzzer:GetAllActiveNotificationsFuzzTest", "getbundleimportance_fuzzer:GetBundleImportanceFuzzTest", "getnotificationslot_fuzzer:GetNotificationSlotFuzzTest", "getnotificationslotnumasbundle_fuzzer:GetNotificationSlotNumAsBundleFuzzTest", "getnotificationslotsforbundle_fuzzer:GetNotificationSlotsForBundleFuzzTest", + "publishcontinuoustasknotification_fuzzer:PublishContinuousTaskNotificationFuzzTest", "publishnotification_fuzzer:PublishNotificationFuzzTest", "removenotification_fuzzer:RemoveNotificationFuzzTest", "removenotificationsbybundle_fuzzer:RemoveNotificationsByBundleFuzzTest", diff --git a/test/fuzztest/enabledistributed_fuzzer/BUILD.gn b/test/fuzztest/enabledistributed_fuzzer/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..9afbaac41b86449d4209c3c1522bce8141bcac18 --- /dev/null +++ b/test/fuzztest/enabledistributed_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("EnableDistributedFuzzTest") { + module_out_path = module_output_path + fuzz_config_file = "${component_path}/test/fuzztest/enabledistributed_fuzzer" + + include_dirs = [ "${component_path}/test/fuzztest/fuzz_common_base" ] + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + sources = [ "enabledistributed_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 = [] + deps += [ ":EnableDistributedFuzzTest" ] +} +############################################################################### diff --git a/test/fuzztest/enabledistributed_fuzzer/corpus/init b/test/fuzztest/enabledistributed_fuzzer/corpus/init new file mode 100644 index 0000000000000000000000000000000000000000..1b910144fb1ff33a40a44b1d2a491b1ab05b598b --- /dev/null +++ b/test/fuzztest/enabledistributed_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/enabledistributed_fuzzer/enabledistributed_fuzzer.cpp b/test/fuzztest/enabledistributed_fuzzer/enabledistributed_fuzzer.cpp new file mode 100644 index 0000000000000000000000000000000000000000..84386e3ba9e54639735bc5b3d7102f7a32534ac9 --- /dev/null +++ b/test/fuzztest/enabledistributed_fuzzer/enabledistributed_fuzzer.cpp @@ -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. + */ + +#include "enabledistributed_fuzzer.h" + +#include "notification_helper.h" + +namespace OHOS { + namespace { + constexpr uint8_t ENABLE = 2; + } + bool DoSomethingInterestingWithMyAPI(const char* data, size_t size) + { + // test EnableDistributed function + bool enabled = *data % ENABLE; + Notification::NotificationHelper::EnableDistributed(enabled); + // test EnableDistributedByBundle function + std::string stringData(data); + int32_t usingData = static_cast(GetU32Data(data)); + Notification::NotificationBundleOption bundleOption; + bundleOption.SetBundleName(stringData); + bundleOption.SetUid(usingData); + Notification::NotificationHelper::EnableDistributedByBundle(bundleOption, enabled); + // test EnableDistributedSelf function + Notification::NotificationHelper::EnableDistributedSelf(enabled); + // test IsDistributedEnableByBundle function + return Notification::NotificationHelper::IsDistributedEnableByBundle(bundleOption, enabled); + } +} + +/* 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) { + OHOS::DoSomethingInterestingWithMyAPI(ch, size); + free(ch); + ch = nullptr; + } + return 0; +} diff --git a/test/fuzztest/enabledistributed_fuzzer/enabledistributed_fuzzer.h b/test/fuzztest/enabledistributed_fuzzer/enabledistributed_fuzzer.h new file mode 100644 index 0000000000000000000000000000000000000000..3ea830821f2a6511ce5070a97777681fb7dec12c --- /dev/null +++ b/test/fuzztest/enabledistributed_fuzzer/enabledistributed_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_ENABLEDISTRIBUTED_FUZZER_ENABLEDISTRIBUTED_FUZZER_H +#define TEST_FUZZTEST_ENABLEDISTRIBUTED_FUZZER_ENABLEDISTRIBUTED_FUZZER_H + +#include "fuzz_common_base.h" + +#define FUZZ_PROJECT_NAME "enabledistributed_fuzzer" + +#endif // TEST_FUZZTEST_ENABLEDISTRIBUTED_FUZZER_ENABLEDISTRIBUTED_FUZZER_H diff --git a/test/fuzztest/enabledistributed_fuzzer/project.xml b/test/fuzztest/enabledistributed_fuzzer/project.xml new file mode 100644 index 0000000000000000000000000000000000000000..6e8ad2cfde8f8bda4beb6cabbe7efd8bc3c54eec --- /dev/null +++ b/test/fuzztest/enabledistributed_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/test/fuzztest/publishcontinuoustasknotification_fuzzer/BUILD.gn b/test/fuzztest/publishcontinuoustasknotification_fuzzer/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..94edcf0638f988d0ec72ef89a20c7b255c3ffdc6 --- /dev/null +++ b/test/fuzztest/publishcontinuoustasknotification_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("PublishContinuousTaskNotificationFuzzTest") { + module_out_path = module_output_path + fuzz_config_file = + "${component_path}/test/fuzztest/publishcontinuoustasknotification_fuzzer" + + include_dirs = [ "${component_path}/test/fuzztest/fuzz_common_base" ] + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + sources = [ "publishcontinuoustasknotification_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 = [] + deps += [ ":PublishContinuousTaskNotificationFuzzTest" ] +} +############################################################################### diff --git a/test/fuzztest/publishcontinuoustasknotification_fuzzer/corpus/init b/test/fuzztest/publishcontinuoustasknotification_fuzzer/corpus/init new file mode 100644 index 0000000000000000000000000000000000000000..1b910144fb1ff33a40a44b1d2a491b1ab05b598b --- /dev/null +++ b/test/fuzztest/publishcontinuoustasknotification_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/publishcontinuoustasknotification_fuzzer/project.xml b/test/fuzztest/publishcontinuoustasknotification_fuzzer/project.xml new file mode 100644 index 0000000000000000000000000000000000000000..6e8ad2cfde8f8bda4beb6cabbe7efd8bc3c54eec --- /dev/null +++ b/test/fuzztest/publishcontinuoustasknotification_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/test/fuzztest/publishcontinuoustasknotification_fuzzer/publishcontinuoustasknotification_fuzzer.cpp b/test/fuzztest/publishcontinuoustasknotification_fuzzer/publishcontinuoustasknotification_fuzzer.cpp new file mode 100644 index 0000000000000000000000000000000000000000..5feb39f0d7d5bfd82af7eddaa4e85bcc43c65ec7 --- /dev/null +++ b/test/fuzztest/publishcontinuoustasknotification_fuzzer/publishcontinuoustasknotification_fuzzer.cpp @@ -0,0 +1,105 @@ +/* + * 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. + */ + +#include "publishcontinuoustasknotification_fuzzer.h" + +#include "notification_helper.h" + +namespace OHOS { + namespace { + constexpr uint8_t ENABLE = 2; + constexpr uint8_t SLOT_TYPE_NUM = 5; + constexpr uint8_t FLAG_STATUS = 3; + } + bool DoSomethingInterestingWithMyAPI(const char* data, size_t size) + { + std::string stringData(data); + Notification::NotificationRequest request; + request.SetAlertOneTime(*data % ENABLE); + + int32_t style = static_cast(GetU32Data(data)); + Notification::NotificationRequest::BadgeStyle badgeStyle = + Notification::NotificationRequest::BadgeStyle(style); + request.SetBadgeIconStyle(badgeStyle); + request.SetBadgeNumber(style); + request.SetClassification(stringData); + + uint32_t color = GetU32Data(data); + request.SetColor(color); + request.SetColorEnabled(*data % ENABLE); + + std::shared_ptr contentType = + std::make_shared(); + contentType->SetText(stringData); + contentType->SetTitle(stringData); + contentType->SetAdditionalText(stringData); + std::shared_ptr content = + std::make_shared(contentType); + request.SetContent(content); + request.SetCountdownTimer(*data % ENABLE); + request.SetCreatorBundleName(stringData); + request.SetDeliveryTime(style); + + std::shared_ptr notificationFlages = + std::make_shared(); + int32_t soundEnabled = static_cast(*data % FLAG_STATUS); + Notification::NotificationConstant::FlagStatus sound = + Notification::NotificationConstant::FlagStatus(soundEnabled); + notificationFlages->SetSoundEnabled(sound); + notificationFlages->SetVibrationEnabled(sound); + request.SetFlags(notificationFlages); + + Notification::NotificationRequest::GroupAlertType groupAlertType = + Notification::NotificationRequest::GroupAlertType(color); + request.SetGroupAlertType(groupAlertType); + + request.SetGroupName(stringData); + request.SetGroupOverview(*data % ENABLE); + request.SetLabel(stringData); + request.SetNotificationId(style); + request.SetOwnerBundleName(stringData); + + uint8_t types = *data % SLOT_TYPE_NUM; + Notification::NotificationConstant::SlotType slotType = Notification::NotificationConstant::SlotType(types); + request.SetSlotType(slotType); + // test PublishContinuousTaskNotification function + Notification::NotificationHelper::PublishContinuousTaskNotification(request); + // test GetDeviceRemindType function + int32_t remindType = static_cast(*data % SLOT_TYPE_NUM); + Notification::NotificationConstant::RemindType remind = + Notification::NotificationConstant::RemindType(remindType); + Notification::NotificationHelper::GetDeviceRemindType(remind); + // test CancelContinuousTaskNotification function + Notification::NotificationHelper::CancelContinuousTaskNotification(stringData, style); + // test IsSupportTemplate function + bool support = *data % ENABLE; + Notification::NotificationHelper::IsSupportTemplate(stringData, support); + // test IsAllowedNotify function + return Notification::NotificationHelper::IsAllowedNotify(style, support); + } +} + +/* 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/publishcontinuoustasknotification_fuzzer/publishcontinuoustasknotification_fuzzer.h b/test/fuzztest/publishcontinuoustasknotification_fuzzer/publishcontinuoustasknotification_fuzzer.h new file mode 100644 index 0000000000000000000000000000000000000000..a88146c289cbff76419f20c4e2e92ef468c6d3a8 --- /dev/null +++ b/test/fuzztest/publishcontinuoustasknotification_fuzzer/publishcontinuoustasknotification_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_PUBLISHCONTINUOUSTASKNOTIFICATION_FUZZER_PUBLISHCONTINUOUSTASKNOTIFICATION_FUZZER_H +#define TEST_FUZZTEST_PUBLISHCONTINUOUSTASKNOTIFICATION_FUZZER_PUBLISHCONTINUOUSTASKNOTIFICATION_FUZZER_H + +#include "fuzz_common_base.h" + +#define FUZZ_PROJECT_NAME "publishcontinuoustasknotification_fuzzer" + +#endif // TEST_FUZZTEST_PUBLISHCONTINUOUSTASKNOTIFICATION_FUZZER_PUBLISHCONTINUOUSTASKNOTIFICATION_FUZZER_H