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