• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 #include "softbus_log.h"
32 
33 
34 namespace OHOS {
ClientTransChannelCallbackTest(const uint8_t * data,size_t size)35 void ClientTransChannelCallbackTest(const uint8_t* data, size_t size)
36 {
37     #define TEST_DATA_LENGTH 1024
38     if ((data == nullptr) || (size < sizeof(int32_t))) {
39         return;
40     }
41 
42     char *sessionName = const_cast<char*>(reinterpret_cast<const char*>(data));
43     ChannelInfo channel = {0};
44     int32_t channelId = *(reinterpret_cast<const int32_t*>(data));
45 
46     int32_t channelType = *(reinterpret_cast<const int32_t*>(data));
47 
48     char *networkId = const_cast<char*>(reinterpret_cast<const char*>(data));
49     int32_t routeType = *(reinterpret_cast<const int32_t*>(data));
50     int32_t eventId = *(reinterpret_cast<const int32_t*>(data));
51     int32_t tvCount = *(reinterpret_cast<const int32_t*>(data));
52     QosTv tvList = {};
53 
54     TransOnChannelOpened(sessionName, &channel);
55 
56     TransOnChannelLinkDown(networkId, routeType);
57 
58     TransOnChannelMsgReceived(channelId, CHANNEL_TYPE_PROXY, (void*)data, TEST_DATA_LENGTH, TRANS_SESSION_BYTES);
59 
60     TransOnChannelQosEvent(channelId, channelType, eventId, tvCount, &tvList);
61 }
62 } // namespace OHOS
63 
64 /* Fuzzer entry point */
LLVMFuzzerTestOneInput(const uint8_t * data,size_t size)65 extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
66 {
67     /* Run your code on data */
68     OHOS::ClientTransChannelCallbackTest(data, size);
69     return 0;
70 }
71