• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
24 namespace OHOS {
25     namespace {
26         constexpr uint8_t ENABLE = 2;
27         constexpr uint8_t FLAG_STATUS = 11;
28     }
DoSomethingInterestingWithMyAPI(const char * data,size_t size)29     bool DoSomethingInterestingWithMyAPI(const char* data, size_t size)
30     {
31         std::string stringData(data);
32         int32_t notificationId = static_cast<int32_t>(GetU32Data(data));
33         Notification::NotificationRequest request(notificationId);
34         request.IsInProgress();
35         bool enabled = *data % ENABLE;
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.SetMaxScreenWantAgent(wantAgent);
47         request.GetMaxScreenWantAgent();
48         std::shared_ptr<AAFwk::WantParams> extras = nullptr;
49         request.SetAdditionalData(extras);
50         request.GetAdditionalData();
51         request.GetDeliveryTime();
52         request.IsShowDeliveryTime();
53         request.SetShowDeliveryTime(enabled);
54         // make NotificationActionButton paramter
55         std::shared_ptr<Notification::NotificationActionButton> actionButton =
56             std::make_shared<Notification::NotificationActionButton>();
57         // make semanticActionButton paramter
58         int32_t semanticAction = static_cast<int32_t>(*data % FLAG_STATUS);
59         Notification::NotificationConstant::SemanticActionButton semanticActionButton =
60             Notification::NotificationConstant::SemanticActionButton(semanticAction);
61         actionButton->SetSemanticActionButton(semanticActionButton);
62         actionButton->SetAutoCreatedReplies(enabled);
63         actionButton->SetContextDependent(enabled);
64         request.AddActionButton(actionButton);
65         request.ClearActionButtons();
66         request.IsPermitSystemGeneratedContextualActionButtons();
67         request.SetPermitSystemGeneratedContextualActionButtons(enabled);
68         return request.IsAgentNotification();
69     }
70 }
71 
72 /* Fuzzer entry point */
LLVMFuzzerTestOneInput(const uint8_t * data,size_t size)73 extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
74 {
75     /* Run your code on data */
76     char *ch = ParseData(data, size);
77     if (ch != nullptr && size >= GetU32Size()) {
78         OHOS::DoSomethingInterestingWithMyAPI(ch, size);
79         free(ch);
80         ch = nullptr;
81     }
82     return 0;
83 }
84