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