• 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 #include <cstdint>
17 #define private public
18 #define protected public
19 #include "notification.h"
20 #undef private
21 #undef protected
22 #include "readfromparcel_fuzzer.h"
23 #include <fuzzer/FuzzedDataProvider.h>
24 
25 namespace OHOS {
26     namespace {
27         constexpr uint8_t SOURCE_TYPE = 3;
28         constexpr uint8_t SLOT_VISIBLENESS_TYPE_NUM = 4;
29         constexpr uint8_t SLOT_TYPE_NUM = 5;
30     }
DoSomethingInterestingWithMyAPI(FuzzedDataProvider * fdp)31     bool DoSomethingInterestingWithMyAPI(FuzzedDataProvider* fdp)
32     {
33         std::string stringData = fdp->ConsumeRandomLengthString();
34         sptr<Notification::NotificationRequest> request = new Notification::NotificationRequest();
35         if (request != nullptr) {
36             request->SetClassification(stringData);
37         }
38         Notification::Notification notification(request);
39         Parcel parcel;
40         notification.MarshallingString(parcel);
41         notification.MarshallingInt32(parcel);
42         notification.MarshallingInt64(parcel);
43         notification.MarshallingParcelable(parcel);
44         notification.Marshalling(parcel);
45         notification.ReadFromParcelBool(parcel);
46         notification.ReadFromParcelString(parcel);
47         notification.ReadFromParcelInt32(parcel);
48         notification.ReadFromParcelInt64(parcel);
49         notification.ReadFromParcelParcelable(parcel);
50         notification.Unmarshalling(parcel);
51         bool enabled = fdp->ConsumeBool();
52         notification.SetEnableSound(enabled);
53         notification.SetEnableLight(enabled);
54         notification.SetEnableVibration(enabled);
55         int32_t color = fdp->ConsumeIntegral<int32_t>();
56         notification.SetLedLightColor(color);
57         uint8_t visibleness = fdp->ConsumeIntegral<uint8_t>() % SLOT_VISIBLENESS_TYPE_NUM;
58         Notification::NotificationConstant::VisiblenessType visiblenessType =
59             Notification::NotificationConstant::VisiblenessType(visibleness);
60         notification.SetLockScreenVisbleness(visiblenessType);
61         int64_t time = 2;
62         notification.SetPostTime(time);
63         std::vector<int64_t> style;
64         style.emplace_back(time);
65         notification.SetVibrationStyle(style);
66         int32_t remindType = static_cast<int32_t>(fdp->ConsumeIntegral<uint8_t>() % SLOT_TYPE_NUM);
67         Notification::NotificationConstant::RemindType remind =
68             Notification::NotificationConstant::RemindType(remindType);
69         notification.SetRemindType(remind);
70         notification.SetRemoveAllowed(enabled);
71         int32_t source = static_cast<int32_t>(fdp->ConsumeIntegral<uint8_t>() % SOURCE_TYPE);
72         Notification::NotificationConstant::SourceType sourceType =
73             Notification::NotificationConstant::SourceType(source);
74         notification.SetSourceType(sourceType);
75         notification.Dump();
76         return notification.ReadFromParcel(parcel);
77     }
78 }
79 
80 /* Fuzzer entry point */
LLVMFuzzerTestOneInput(const uint8_t * data,size_t size)81 extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
82 {
83     /* Run your code on data */
84     FuzzedDataProvider fdp(data, size);
85     OHOS::DoSomethingInterestingWithMyAPI(&fdp);
86     return 0;
87 }
88