• 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 "clienttransproxyfilecommon_fuzzer.h"
17 
18 #include <cstddef>
19 #include <cstdint>
20 #include <sys/types.h>
21 #include <sys/stat.h>
22 #include <arpa/inet.h>
23 #include <fcntl.h>
24 #include <string>
25 #include "securec.h"
26 
27 #include "client_trans_proxy_file_common.h"
28 #include "fuzz_data_generator.h"
29 #include "softbus_adapter_file.h"
30 #include "softbus_adapter_mem.h"
31 #include "softbus_adapter_timer.h"
32 #include "softbus_def.h"
33 #include "softbus_error_code.h"
34 #include "softbus_type_def.h"
35 
36 namespace OHOS {
ClientTransProxyFileCommonTest(const uint8_t * data,size_t size)37 void ClientTransProxyFileCommonTest(const uint8_t* data, size_t size)
38 {
39     if ((data == nullptr) || (size < sizeof(uint64_t))) {
40         return;
41     }
42     DataGenerator::Write(data, size);
43 
44     char *filePath = nullptr;
45     char *absPath = nullptr;
46     char *destFile = nullptr;
47     uint64_t index = 0;
48     uint64_t frameNumber = 0;
49     uint32_t bufferSize = 0;
50     int32_t fileCount = 0;
51     char *path = nullptr;
52     int32_t fd = 0;
53     int32_t type = 0;
54     bool isBlock = 0;
55     GenerateUint64(index);
56     GenerateUint64(frameNumber);
57     GenerateUint32(bufferSize);
58     GenerateInt32(fileCount);
59     GenerateInt32(fd);
60     GenerateInt32(type);
61     GenerateBool(isBlock);
62 
63     IsPathValid(filePath);
64 
65     GetAndCheckRealPath(filePath, absPath);
66 
67     CheckDestFilePathValid(destFile);
68 
69     FrameIndexToType(index, frameNumber);
70 
71     BufferToFileList(nullptr, bufferSize, &fileCount);
72 
73     TransGetFileName(path);
74 
75     FileLock(fd, type, isBlock);
76 
77     FileUnLock(fd);
78     DataGenerator::Clear();
79 }
80 } // namespace OHOS
81 
82 /* Fuzzer entry point */
LLVMFuzzerTestOneInput(const uint8_t * data,size_t size)83 extern "C" int32_t LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
84 {
85     /* Run your code on data */
86     OHOS::ClientTransProxyFileCommonTest(data, size);
87     return 0;
88 }
89