• 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_user_input.h"
19 #undef private
20 #undef protected
21 #include "notificationuserinputannex_fuzzer.h"
22 #include <fuzzer/FuzzedDataProvider.h>
23 
24 namespace OHOS {
25     namespace {
26         constexpr uint8_t INPUT_EDIT_TYPE = 3;
27     }
DoSomethingInterestingWithMyAPI(FuzzedDataProvider * fdp)28     bool DoSomethingInterestingWithMyAPI(FuzzedDataProvider* fdp)
29     {
30         std::string stringData = fdp->ConsumeRandomLengthString();
31         Notification::NotificationUserInput notificationUserInput(stringData);
32         AAFwk::Want want;
33         Notification::NotificationUserInput userInput(stringData);
34         std::map<std::string, std::shared_ptr<Uri>> results;
35         notificationUserInput.AddMimeInputToWant(userInput, want, results);
36         nlohmann::json jsonObj;
37         notificationUserInput.ToJson(jsonObj);
38         notificationUserInput.FromJson(jsonObj);
39         std::string inputKey = fdp->ConsumeRandomLengthString();
40         std::string tag = fdp->ConsumeRandomLengthString();
41         std::vector<std::string> options;
42         options.emplace_back(stringData);
43         bool permitFreeFormInput = fdp->ConsumeBool();
44         std::set<std::string> permitMimeTypes;
45         std::shared_ptr<AAFwk::WantParams> additional;
46         uint8_t inputEditTypes = fdp->ConsumeIntegral<uint8_t>() % INPUT_EDIT_TYPE;
47         Notification::NotificationConstant::InputEditType inputEditType =
48             Notification::NotificationConstant::InputEditType(inputEditTypes);
49         Notification::NotificationUserInput::Create(inputKey, tag, options, permitFreeFormInput,
50                 permitMimeTypes, additional, inputEditType);
51         return true;
52     }
53 }
54 
55 /* Fuzzer entry point */
LLVMFuzzerTestOneInput(const uint8_t * data,size_t size)56 extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
57 {
58     /* Run your code on data */
59     FuzzedDataProvider fdp(data, size);
60     OHOS::DoSomethingInterestingWithMyAPI(&fdp);
61     return 0;
62 }
63