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 "transserverproxyextern_fuzzer.h"
17 #include <cstddef>
18 #include <cstdint>
19
20 #include "trans_server_proxy.h"
21 #include "session.h"
22 #include "softbus_def.h"
23 #include "client_trans_channel_callback.h"
24 #include "client_trans_auth_manager.h"
25 #include "client_trans_proxy_manager.h"
26 #include "client_trans_session_callback.h"
27 #include "client_trans_session_manager.h"
28 #include "client_trans_tcp_direct_manager.h"
29 #include "client_trans_udp_manager.h"
30 #include "softbus_errcode.h"
31 #include "softbus_log.h"
32
33 namespace OHOS {
TransServerProxyDeInitTest(const uint8_t * data,size_t size)34 void TransServerProxyDeInitTest(const uint8_t* data, size_t size)
35 {
36 if ((data == nullptr) || (size == 0)) {
37 return;
38 }
39
40 TransServerProxyDeInit();
41 }
42
ServerIpcOpenAuthSessionTest(const uint8_t * data,size_t size)43 void ServerIpcOpenAuthSessionTest(const uint8_t* data, size_t size)
44 {
45 if ((data == nullptr) || (size == 0)) {
46 return;
47 }
48
49 ServerIpcOpenAuthSession(nullptr, nullptr);
50 }
51
ServerIpcNotifyAuthSuccessTest(const uint8_t * data,size_t size)52 void ServerIpcNotifyAuthSuccessTest(const uint8_t* data, size_t size)
53 {
54 if ((data == nullptr) || (size < sizeof(int32_t))) {
55 return;
56 }
57
58 int32_t channelId = *(reinterpret_cast<const int32_t*>(data));
59 int32_t channelType = *(reinterpret_cast<const int32_t*>(data));
60
61 ServerIpcNotifyAuthSuccess(channelId, channelType);
62 }
63
ServerIpcCloseChannelTest(const uint8_t * data,size_t size)64 void ServerIpcCloseChannelTest(const uint8_t* data, size_t size)
65 {
66 if ((data == nullptr) || (size < sizeof(int32_t))) {
67 return;
68 }
69 int32_t channelId = *(reinterpret_cast<const int32_t*>(data));
70 int32_t channelType = *(reinterpret_cast<const int32_t*>(data));
71
72 ServerIpcCloseChannel(channelId, channelType);
73 }
74
ServerIpcSendMessageTest(const uint8_t * data,size_t size)75 void ServerIpcSendMessageTest(const uint8_t* data, size_t size)
76 {
77 if ((data == nullptr) || (size < sizeof(int32_t))) {
78 return;
79 }
80
81 const void *clientData = nullptr;
82
83 uint32_t len = *(reinterpret_cast<const uint32_t*>(data));
84
85 int32_t channelId = *(reinterpret_cast<const int32_t*>(data));
86 int32_t channelType = *(reinterpret_cast<const int32_t*>(data));
87 int32_t msgType = *(reinterpret_cast<const int32_t*>(data));
88
89 ServerIpcSendMessage(channelId, channelType, clientData, len, msgType);
90 }
91
ServerIpcQosReportTest(const uint8_t * data,size_t size)92 void ServerIpcQosReportTest(const uint8_t* data, size_t size)
93 {
94 if ((data == nullptr) || (size < sizeof(int32_t))) {
95 return;
96 }
97
98 int32_t channelId = *(reinterpret_cast<const int32_t*>(data));
99 int32_t channelType = *(reinterpret_cast<const int32_t*>(data));
100 int32_t appType = *(reinterpret_cast<const int32_t*>(data));
101 int32_t quality = *(reinterpret_cast<const int32_t*>(data));
102
103 ServerIpcQosReport(channelId, channelType, appType, quality);
104 }
105
ServerIpcStreamStatsTest(const uint8_t * data,size_t size)106 void ServerIpcStreamStatsTest(const uint8_t* data, size_t size)
107 {
108 if ((data == nullptr) || (size < sizeof(int32_t))) {
109 return;
110 }
111
112 int32_t channelId = *(reinterpret_cast<const int32_t*>(data));
113 int32_t channelType = *(reinterpret_cast<const int32_t*>(data));
114
115 ServerIpcStreamStats(channelId, channelType, nullptr);
116 }
117
ServerIpcRippleStatsTest(const uint8_t * data,size_t size)118 void ServerIpcRippleStatsTest(const uint8_t* data, size_t size)
119 {
120 if ((data == nullptr) || (size < sizeof(int32_t))) {
121 return;
122 }
123
124 int32_t channelId = *(reinterpret_cast<const int32_t*>(data));
125 int32_t channelType = *(reinterpret_cast<const int32_t*>(data));
126
127 ServerIpcRippleStats(channelId, channelType, nullptr);
128 }
129
ServerIpcRemovePermissionTest(const uint8_t * data,size_t size)130 void ServerIpcRemovePermissionTest(const uint8_t* data, size_t size)
131 {
132 if ((data == nullptr) || (size == 0)) {
133 return;
134 }
135
136 const char *tmpSessionName = "com.plrdtest.dsoftbus";
137
138 ServerIpcRemovePermission(tmpSessionName);
139 }
140 } // namespace OHOS
141
142 /* Fuzzer entry point */
LLVMFuzzerTestOneInput(const uint8_t * data,size_t size)143 extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
144 {
145 /* Run your code on data */
146 OHOS::TransServerProxyDeInitTest(data, size);
147 OHOS::ServerIpcOpenAuthSessionTest(data, size);
148 OHOS::ServerIpcCloseChannelTest(data, size);
149 OHOS::ServerIpcSendMessageTest(data, size);
150 OHOS::ServerIpcQosReportTest(data, size);
151 OHOS::ServerIpcStreamStatsTest(data, size);
152 OHOS::ServerIpcRippleStatsTest(data, size);
153 OHOS::ServerIpcRemovePermissionTest(data, size);
154 return 0;
155 }
156