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 "clienttransproxymanager_fuzzer.h"
17 
18 #include <cstddef>
19 #include <cstdint>
20 #include <limits>
21 #include <securec.h>
22 #include <unistd.h>
23 
24 #include "client_trans_proxy_manager.h"
25 #include "client_trans_pending.h"
26 #include "client_trans_proxy_file_common.h"
27 #include "client_trans_proxy_file_manager.h"
28 #include "client_trans_session_manager.h"
29 #include "client_trans_socket_manager.h"
30 #include "client_trans_tcp_direct_message.h"
31 #include "softbus_adapter_errcode.h"
32 #include "softbus_adapter_file.h"
33 #include "softbus_adapter_mem.h"
34 #include "softbus_adapter_timer.h"
35 #include "softbus_app_info.h"
36 #include "softbus_conn_interface.h"
37 #include "softbus_errcode.h"
38 #include "softbus_feature_config.h"
39 #include "softbus_utils.h"
40 #include "trans_server_proxy.h"
41 
42 namespace OHOS {
ClientTransProxyManagerTest(const uint8_t * data,size_t size)43 void ClientTransProxyManagerTest(const uint8_t* data, size_t size)
44 {
45     if ((data == nullptr) || (size < sizeof(int32_t))) {
46         return;
47     }
48 
49     char *sessionName = nullptr;
50     ChannelInfo channel = {0};
51     int32_t channelId = *(reinterpret_cast<const int32_t*>(data));
52     const void *clientData = nullptr;
53     uint32_t len = *(reinterpret_cast<const uint32_t*>(data));
54     int32_t pktType = *(reinterpret_cast<const int32_t*>(data));
55     int32_t type = *(reinterpret_cast<const int32_t*>(data));
56     const char **sFileList = nullptr;
57     const char **dFileList = nullptr;
58     uint32_t fileCnt = *(reinterpret_cast<const uint32_t*>(data));
59     int32_t sessionId = *(reinterpret_cast<const int32_t*>(data));
60     const char *charData = nullptr;
61 
62     ClientTransProxyOnChannelOpened(sessionName, &channel);
63 
64     ClientTransProxyOnDataReceived(channelId, clientData, len, (SessionPktType)pktType);
65 
66     ClientTransProxyCloseChannel(channelId);
67 
68     TransProxyChannelSendBytes(channelId, clientData, len);
69 
70     TransProxyChannelSendMessage(channelId, clientData, len);
71 
72     TransProxyChannelSendFile(channelId, sFileList, dFileList, fileCnt);
73 
74     ProcessFileFrameData(sessionId, channelId, charData, len, type);
75 }
76 } // namespace OHOS
77 
78 /* Fuzzer entry point */
LLVMFuzzerTestOneInput(const uint8_t * data,size_t size)79 extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
80 {
81     /* Run your code on data */
82     OHOS::ClientTransProxyManagerTest(data, size);
83     return 0;
84 }
85