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_user_input.h"
19 #undef private
20 #undef protected
21 #include "notificationuserinput_fuzzer.h"
22
23 namespace OHOS {
24 namespace {
25 constexpr uint8_t ENABLE = 2;
26 constexpr uint8_t INPUT_EDIT_TYPE = 3;
27 }
DoSomethingInterestingWithMyAPI(const char * data,size_t size)28 bool DoSomethingInterestingWithMyAPI(const char* data, size_t size)
29 {
30 std::string stringData(data);
31 Notification::NotificationUserInput notificationUserInput(stringData);
32 AAFwk::Want want;
33 uint8_t sources = *data % ENABLE;
34 Notification::NotificationConstant::InputsSource source =
35 Notification::NotificationConstant::InputsSource(sources);
36 notificationUserInput.SetInputsSource(want, source);
37 notificationUserInput.GetInputsSource(want);
38 std::shared_ptr<Notification::NotificationUserInput> input =
39 std::make_shared<Notification::NotificationUserInput>();
40 std::vector<std::shared_ptr<Notification::NotificationUserInput>> userInputs;
41 userInputs.emplace_back(input);
42 AAFwk::WantParams additional;
43 notificationUserInput.AddInputsToWant(userInputs, want, additional);
44 notificationUserInput.GetInputsFromWant(want);
45 notificationUserInput.Create(stringData);
46 notificationUserInput.GetInputKey();
47 notificationUserInput.AddAdditionalData(additional);
48 notificationUserInput.GetAdditionalData();
49 uint8_t inputEditTypes = *data % INPUT_EDIT_TYPE;
50 Notification::NotificationConstant::InputEditType inputEditType =
51 Notification::NotificationConstant::InputEditType(inputEditTypes);
52 notificationUserInput.SetEditType(inputEditType);
53 notificationUserInput.GetEditType();
54 std::vector<std::string> options;
55 options.emplace_back(stringData);
56 notificationUserInput.SetOptions(options);
57 notificationUserInput.GetOptions();
58 bool doPermit = *data % ENABLE;
59 notificationUserInput.SetPermitMimeTypes(stringData, doPermit);
60 notificationUserInput.GetPermitMimeTypes();
61 notificationUserInput.IsMimeTypeOnly();
62 notificationUserInput.SetTag(stringData);
63 notificationUserInput.GetTag();
64 notificationUserInput.SetPermitFreeFormInput(doPermit);
65 notificationUserInput.IsPermitFreeFormInput();
66 notificationUserInput.Dump();
67 Parcel parcel;
68 notificationUserInput.ReadFromParcel(parcel);
69 return notificationUserInput.Marshalling(parcel);
70 }
71 }
72
73 /* Fuzzer entry point */
LLVMFuzzerTestOneInput(const uint8_t * data,size_t size)74 extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
75 {
76 /* Run your code on data */
77 char *ch = ParseData(data, size);
78 if (ch != nullptr && size >= GetU32Size()) {
79 OHOS::DoSomethingInterestingWithMyAPI(ch, size);
80 free(ch);
81 ch = nullptr;
82 }
83 return 0;
84 }
85