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 "clienttranschannelcallback_fuzzer.h"
17 #include <cstddef>
18 #include <cstdint>
19 #include "session.h"
20 #include "softbus_def.h"
21 #include "client_trans_channel_callback.h"
22 #include "client_trans_auth_manager.h"
23 #include "client_trans_proxy_manager.h"
24 #include "client_trans_session_callback.h"
25 #include "client_trans_session_manager.h"
26 #include "client_trans_tcp_direct_manager.h"
27 #include "client_trans_udp_manager.h"
28 #include "softbus_errcode.h"
29 #include "softbus_log.h"
30
31 namespace OHOS {
ClientTransChannelCallbackTest(const uint8_t * data,size_t size)32 void ClientTransChannelCallbackTest(const uint8_t* data, size_t size)
33 {
34 if ((data == nullptr) || (size < sizeof(int32_t))) {
35 return;
36 }
37
38 char *sessionName = nullptr;
39 ChannelInfo channel = {0};
40 int32_t channelId = *(reinterpret_cast<const int32_t*>(data));
41 int32_t channelType = *(reinterpret_cast<const int32_t*>(data));
42 char *networkId = nullptr;
43 int32_t routeType = *(reinterpret_cast<const int32_t*>(data));
44 const void *clientData = nullptr;
45 uint32_t len = *(reinterpret_cast<const uint32_t*>(data));
46 int32_t pktType = *(reinterpret_cast<const int32_t*>(data));
47 int32_t eventId = *(reinterpret_cast<const int32_t*>(data));
48 int32_t tvCount = *(reinterpret_cast<const int32_t*>(data));
49 QosTv tvList = {};
50
51 TransOnChannelOpened(sessionName, &channel);
52
53 TransOnChannelLinkDown(networkId, routeType);
54
55 TransOnChannelMsgReceived(channelId, channelType, clientData, len, (SessionPktType)pktType);
56
57 TransOnChannelQosEvent(channelId, channelType, eventId, tvCount, &tvList);
58 }
59 } // namespace OHOS
60
61 /* Fuzzer entry point */
LLVMFuzzerTestOneInput(const uint8_t * data,size_t size)62 extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
63 {
64 /* Run your code on data */
65 OHOS::ClientTransChannelCallbackTest(data, size);
66 return 0;
67 }
68