1 /*
2  * Copyright (c) 2023-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 "device_manager_service_listener.h"
17 #include "dm_auth_manager.h"
18 #include "dm_device_info.h"
19 #include "dm_publish_info.h"
20 #include "dm_subscribe_info.h"
21 #include "hichain_connector.h"
22 #include "softbus_bus_center.h"
23 #include "softbus_connector.h"
24 #include "softbus_session.h"
25 #include "on_session_opened_fuzzer.h"
26 
27 namespace OHOS {
28 namespace DistributedHardware {
29 
30 class SoftbusSessionCallbackTest : public ISoftbusSessionCallback {
31 public:
SoftbusSessionCallbackTest()32     SoftbusSessionCallbackTest() {}
~SoftbusSessionCallbackTest()33     virtual ~SoftbusSessionCallbackTest() {}
34     void OnSessionOpened(int32_t sessionId, int32_t sessionSide, int32_t result) override
35     {
36         (void)sessionId;
37         (void)sessionSide;
38         (void)result;
39     }
40     void OnSessionClosed(int32_t sessionId) override
41     {
42         (void)sessionId;
43     }
44     void OnDataReceived(int32_t sessionId, std::string message) override
45     {
46         (void)sessionId;
47         (void)message;
48     }
49     bool GetIsCryptoSupport() override
50     {
51         return true;
52     }
53     void OnAuthDeviceDataReceived(int32_t sessionId, std::string message) override
54     {
55         (void)sessionId;
56         (void)message;
57     }
58 };
59 
OnSessionOpenedFuzzTest(const uint8_t* data, size_t size)60 void OnSessionOpenedFuzzTest(const uint8_t* data, size_t size)
61 {
62     if ((data == nullptr) || (size < sizeof(int))) {
63         return;
64     }
65 
66     int sessionId = *(reinterpret_cast<const int*>(data));
67     int result = *(reinterpret_cast<const int*>(data));
68 
69     std::shared_ptr<SoftbusSession> softbusSession = std::make_shared<SoftbusSession>();
70     softbusSession->RegisterSessionCallback(std::make_shared<SoftbusSessionCallbackTest>());
71     softbusSession->OnSessionOpened(sessionId, result);
72     softbusSession->OnSessionClosed(sessionId);
73 }
74 }
75 }
76 
77 /* Fuzzer entry point */
LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)78 extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
79 {
80     /* Run your code on data */
81     OHOS::DistributedHardware::OnSessionOpenedFuzzTest(data, size);
82 
83     return 0;
84 }
85