1 /*
2 * Copyright (c) 2021-2024 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 "distributed_input_source_transport_fuzzer.h"
17
18 #include <cstddef>
19 #include <cstdint>
20 #include <functional>
21 #include <iostream>
22 #include <thread>
23 #include <unistd.h>
24
25 #include <refbase.h>
26
27 #include "constants_dinput.h"
28 #include "distributed_input_inject.h"
29 #include "distributed_input_source_transport.h"
30
31 namespace OHOS {
32 namespace DistributedHardware {
OpenInputSoftbusFuzzTest(const uint8_t * data,size_t size)33 void OpenInputSoftbusFuzzTest(const uint8_t *data, size_t size)
34 {
35 if ((data == nullptr) || (size == 0)) {
36 return;
37 }
38
39 std::string remoteDevId(reinterpret_cast<const char*>(data), size);
40
41 const uint32_t sleepTimeUs = 100 * 1000;
42 usleep(sleepTimeUs);
43 DistributedInput::DistributedInputSourceTransport::GetInstance().OpenInputSoftbus(remoteDevId, true);
44 DistributedInput::DistributedInputSourceTransport::GetInstance().CloseInputSoftbus(remoteDevId, true);
45 }
46 } // namespace DistributedHardware
47 } // namespace OHOS
48
49 /* Fuzzer entry point */
LLVMFuzzerTestOneInput(const uint8_t * data,size_t size)50 extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
51 {
52 OHOS::DistributedHardware::DistributedInput::DistributedInputInject::GetInstance();
53 /* Run your code on data */
54 OHOS::DistributedHardware::OpenInputSoftbusFuzzTest(data, size);
55 return 0;
56 }