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() {}
OnSessionOpened(int32_t sessionId,int32_t sessionSide,int32_t result)34 void OnSessionOpened(int32_t sessionId, int32_t sessionSide, int32_t result) override
35 {
36 (void)sessionId;
37 (void)sessionSide;
38 (void)result;
39 }
OnSessionClosed(int32_t sessionId)40 void OnSessionClosed(int32_t sessionId) override
41 {
42 (void)sessionId;
43 }
OnDataReceived(int32_t sessionId,std::string message)44 void OnDataReceived(int32_t sessionId, std::string message) override
45 {
46 (void)sessionId;
47 (void)message;
48 }
GetIsCryptoSupport()49 bool GetIsCryptoSupport() override
50 {
51 return true;
52 }
OnUnbindSessionOpened(int32_t socket,PeerSocketInfo info)53 void OnUnbindSessionOpened(int32_t socket, PeerSocketInfo info) override
54 {
55 (void)socket;
56 (void)info;
57 }
OnAuthDeviceDataReceived(int32_t sessionId,std::string message)58 void OnAuthDeviceDataReceived(int32_t sessionId, std::string message) override
59 {
60 (void)sessionId;
61 (void)message;
62 }
BindSocketSuccess(int32_t socket)63 void BindSocketSuccess(int32_t socket) override
64 {
65 (void)socket;
66 }
BindSocketFail()67 void BindSocketFail() override {}
68 };
69
OnSessionOpenedFuzzTest(const uint8_t * data,size_t size)70 void OnSessionOpenedFuzzTest(const uint8_t* data, size_t size)
71 {
72 if ((data == nullptr) || (size < sizeof(int))) {
73 return;
74 }
75
76 int sessionId = *(reinterpret_cast<const int*>(data));
77 int result = *(reinterpret_cast<const int*>(data));
78
79 std::shared_ptr<SoftbusSession> softbusSession = std::make_shared<SoftbusSession>();
80 softbusSession->RegisterSessionCallback(std::make_shared<SoftbusSessionCallbackTest>());
81 softbusSession->OnSessionOpened(sessionId, result);
82 softbusSession->OnSessionClosed(sessionId);
83 }
84 }
85 }
86
87 /* Fuzzer entry point */
LLVMFuzzerTestOneInput(const uint8_t * data,size_t size)88 extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
89 {
90 /* Run your code on data */
91 OHOS::DistributedHardware::OnSessionOpenedFuzzTest(data, size);
92
93 return 0;
94 }
95