• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2021-2025 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_sink_transport_fuzzer.h"
17 
18 #include <functional>
19 #include <iostream>
20 #include <thread>
21 
22 #include <refbase.h>
23 
24 #include "constants_dinput.h"
25 #include "distributed_input_sink_transport.h"
26 
27 namespace OHOS {
28 namespace DistributedHardware {
RespPrepareRemoteInputFuzzTest(const uint8_t * data,size_t size)29 void RespPrepareRemoteInputFuzzTest(const uint8_t *data, size_t size)
30 {
31     if ((data == nullptr) || (size < sizeof(int32_t))) {
32         return;
33     }
34 
35     int32_t sessionId = *(reinterpret_cast<const int32_t*>(data));
36     nlohmann::json jsonStr;
37     jsonStr["device_id"] = "123456";
38     jsonStr["dh_id"] = "dinput_1";
39     std::string smsg = jsonStr.dump();
40 
41     DistributedInput::DistributedInputSinkTransport::GetInstance().RespPrepareRemoteInput(sessionId, smsg);
42     DistributedInput::DistributedInputSinkTransport::GetInstance().RespUnprepareRemoteInput(sessionId, smsg);
43 }
44 
RespStartRemoteInputFuzzTest(const uint8_t * data,size_t size)45 void RespStartRemoteInputFuzzTest(const uint8_t *data, size_t size)
46 {
47     if ((data == nullptr) || (size < sizeof(int32_t))) {
48         return;
49     }
50 
51     int32_t sessionId = *(reinterpret_cast<const int32_t*>(data));
52     nlohmann::json jsonStr;
53     jsonStr["device_id"] = "123456";
54     jsonStr["dh_id"] = "dinput_1";
55     std::string smsg = jsonStr.dump();
56 
57     DistributedInput::DistributedInputSinkTransport::GetInstance().RespStartRemoteInput(sessionId, smsg);
58     DistributedInput::DistributedInputSinkTransport::GetInstance().RespStopRemoteInput(sessionId, smsg);
59 }
60 } // namespace DistributedHardware
61 } // namespace OHOS
62 
63 /* Fuzzer entry point */
LLVMFuzzerTestOneInput(const uint8_t * data,size_t size)64 extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
65 {
66     /* Run your code on data */
67     OHOS::DistributedHardware::RespPrepareRemoteInputFuzzTest(data, size);
68     OHOS::DistributedHardware::RespStartRemoteInputFuzzTest(data, size);
69     return 0;
70 }