1 /*
2 * Copyright (c) 2023 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 <securec.h>
20 #include "softbus_utils.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_error_code.h"
31
32
33 namespace OHOS {
ClientTransChannelCallbackTest(const uint8_t * data,size_t size)34 void ClientTransChannelCallbackTest(const uint8_t* data, size_t size)
35 {
36 #define TEST_DATA_LENGTH 1024
37 if ((data == nullptr) || (size < sizeof(int32_t))) {
38 return;
39 }
40
41 char *sessionName = const_cast<char*>(reinterpret_cast<const char*>(data));
42 ChannelInfo channel = {0};
43 int32_t channelId = *(reinterpret_cast<const int32_t*>(data));
44
45 int32_t channelType = *(reinterpret_cast<const int32_t*>(data));
46
47 char *networkId = const_cast<char*>(reinterpret_cast<const char*>(data));
48 int32_t routeType = *(reinterpret_cast<const int32_t*>(data));
49 int32_t eventId = *(reinterpret_cast<const int32_t*>(data));
50 int32_t tvCount = *(reinterpret_cast<const int32_t*>(data));
51 QosTv tvList = {};
52
53 TransOnChannelOpened(sessionName, &channel);
54
55 TransOnChannelLinkDown(networkId, routeType);
56
57 TransOnChannelMsgReceived(channelId, CHANNEL_TYPE_PROXY, (void*)data, TEST_DATA_LENGTH, TRANS_SESSION_BYTES);
58
59 TransOnChannelQosEvent(channelId, channelType, eventId, tvCount, &tvList);
60 }
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::ClientTransChannelCallbackTest(data, size);
68 return 0;
69 }
70