• 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 "clienttransproxyfilemanager_fuzzer.h"
17 
18 #include <cstddef>
19 #include <cstdint>
20 #include <cinttypes>
21 #include <limits>
22 #include <string>
23 #include <unistd.h>
24 
25 #include "client_trans_proxy_file_manager.h"
26 #include "client_trans_pending.h"
27 #include "client_trans_proxy_file_common.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 "securec.h"
33 #include "softbus_adapter_errcode.h"
34 #include "softbus_adapter_file.h"
35 #include "softbus_adapter_mem.h"
36 #include "softbus_adapter_timer.h"
37 #include "softbus_app_info.h"
38 #include "softbus_conn_interface.h"
39 #include "softbus_def.h"
40 #include "softbus_error_code.h"
41 #include "softbus_type_def.h"
42 #include "softbus_utils.h"
43 #include "trans_server_proxy.h"
44 
45 namespace OHOS {
ClientTransProxyFileManagerTest(const uint8_t * data,size_t size)46 void ClientTransProxyFileManagerTest(const uint8_t* data, size_t size)
47 {
48     if ((data == nullptr) || (size < sizeof(int32_t))) {
49         return;
50     }
51 
52     DataGenerator::Write(data, size);
53     int32_t channelId = 0;
54     const char **sFileList = nullptr;
55     const char **dFileList = nullptr;
56     uint32_t fileCnt = 0;
57     int32_t sessionId = 0;
58     GenerateInt32(channelId);
59     GenerateInt32(sessionId);
60     GenerateUint32(fileCnt);
61     const FileFrame oneFrame = {0};
62 
63     ProxyChannelSendFile(channelId, sFileList, dFileList, fileCnt);
64 
65     ProcessRecvFileFrameData(sessionId, channelId, &oneFrame);
66     DataGenerator::Clear();
67 }
68 } // namespace OHOS
69 
70 /* Fuzzer entry point */
LLVMFuzzerTestOneInput(const uint8_t * data,size_t size)71 extern "C" int32_t LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
72 {
73     /* Run your code on data */
74     OHOS::ClientTransProxyFileManagerTest(data, size);
75     return 0;
76 }
77