1 /* 2 * Copyright (c) 2022 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16 #define private public 17 #define protected public 18 #include "notification_action_button.h" 19 #undef private 20 #undef protected 21 #include "notificationrequest_fuzzer.h" 22 #include "notification_request.h" 23 #include <fuzzer/FuzzedDataProvider.h> 24 25 namespace OHOS { 26 namespace { 27 constexpr uint8_t FLAG_STATUS = 11; 28 } DoSomethingInterestingWithMyAPI(FuzzedDataProvider * fdp)29 bool DoSomethingInterestingWithMyAPI(FuzzedDataProvider *fdp) 30 { 31 std::string stringData = fdp->ConsumeRandomLengthString(); 32 int32_t notificationId = fdp->ConsumeIntegral<int32_t>(); 33 Notification::NotificationRequest request(notificationId); 34 request.IsInProgress(); 35 bool enabled = fdp->ConsumeBool(); 36 request.SetInProgress(enabled); 37 request.IsUnremovable(); 38 request.SetUnremovable(enabled); 39 request.GetBadgeNumber(); 40 request.GetNotificationId(); 41 std::shared_ptr<AbilityRuntime::WantAgent::WantAgent> wantAgent = nullptr; 42 request.SetWantAgent(wantAgent); 43 request.GetWantAgent(); 44 request.SetRemovalWantAgent(wantAgent); 45 request.GetRemovalWantAgent(); 46 request.GetMaxScreenWantAgent(); 47 std::shared_ptr<AAFwk::WantParams> extras = nullptr; 48 request.SetAdditionalData(extras); 49 request.GetAdditionalData(); 50 request.GetDeliveryTime(); 51 request.IsShowDeliveryTime(); 52 request.SetShowDeliveryTime(enabled); 53 // make NotificationActionButton paramter 54 std::shared_ptr<Notification::NotificationActionButton> actionButton = 55 std::make_shared<Notification::NotificationActionButton>(); 56 // make semanticActionButton paramter 57 int32_t semanticAction = fdp->ConsumeIntegral<int32_t>() % FLAG_STATUS; 58 Notification::NotificationConstant::SemanticActionButton semanticActionButton = 59 Notification::NotificationConstant::SemanticActionButton(semanticAction); 60 actionButton->SetSemanticActionButton(semanticActionButton); 61 actionButton->SetAutoCreatedReplies(enabled); 62 actionButton->SetContextDependent(enabled); 63 request.AddActionButton(actionButton); 64 request.ClearActionButtons(); 65 request.IsPermitSystemGeneratedContextualActionButtons(); 66 request.SetPermitSystemGeneratedContextualActionButtons(enabled); 67 return request.IsAgentNotification(); 68 } 69 } 70 71 /* Fuzzer entry point */ LLVMFuzzerTestOneInput(const uint8_t * data,size_t size)72extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) 73 { 74 /* Run your code on data */ 75 FuzzedDataProvider fdp(data, size); 76 OHOS::DoSomethingInterestingWithMyAPI(&fdp); 77 return 0; 78 } 79