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 "eventreceiveproxy_fuzzer.h"
17 #include "event_receive_proxy.h"
18 #include "fuzz_common_base.h"
19 
20 namespace OHOS {
21 namespace EventFwk {
22 }  // namespace EventFwk
23 namespace {
24     constexpr size_t U32_AT_SIZE = 4;
25 }
DoSomethingInterestingWithMyAPI(FuzzData fuzzData)26 bool DoSomethingInterestingWithMyAPI(FuzzData fuzzData)
27 {
28     // make common event data
29     EventFwk::CommonEventData commonEventData;
30     bool enabled = fuzzData.GenerateRandomBool();
31     std::shared_ptr<EventFwk::EventReceiveProxy> result = std::make_shared<EventFwk::EventReceiveProxy>(nullptr);
32     if (result != nullptr) {
33         result->NotifyEvent(commonEventData, enabled, enabled);
34         return true;
35     }
36     return false;
37 }
38 }
39 
40 /* Fuzzer entry point */
LLVMFuzzerTestOneInput(const uint8_t * data,size_t size)41 extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
42 {
43     /* Run your code on data */
44     if (data == nullptr) {
45         return 0;
46     }
47 
48     if (size < OHOS::U32_AT_SIZE) {
49         return 0;
50     }
51     OHOS::FuzzData fuzzData(data, size);
52     OHOS::DoSomethingInterestingWithMyAPI(fuzzData);
53     return 0;
54 }
55