• 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 
26 #include "client_trans_proxy_file_common.h"
27 #include "securec.h"
28 #include "softbus_adapter_file.h"
29 #include "softbus_adapter_mem.h"
30 #include "softbus_adapter_timer.h"
31 #include "softbus_def.h"
32 #include "softbus_errcode.h"
33 #include "softbus_log.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 
43     char *filePath = nullptr;
44     char *absPath = nullptr;
45     char *destFile = nullptr;
46     uint64_t index = *(reinterpret_cast<const uint64_t*>(data));
47     uint64_t frameNumber = *(reinterpret_cast<const uint64_t*>(data));
48     uint32_t bufferSize = *(reinterpret_cast<const uint32_t*>(data));
49     int32_t fileCount = *(reinterpret_cast<const int32_t*>(data));
50     char *path = nullptr;
51     int32_t fd = *(reinterpret_cast<const int32_t*>(data));
52     int32_t type = *(reinterpret_cast<const int32_t*>(data));
53     bool isBlock = *(reinterpret_cast<const bool*>(data));
54 
55     IsPathValid(filePath);
56 
57     GetAndCheckRealPath(filePath, absPath);
58 
59     CheckDestFilePathValid(destFile);
60 
61     FrameIndexToType(index, frameNumber);
62 
63     BufferToFileList(nullptr, bufferSize, &fileCount);
64 
65     TransGetFileName(path);
66 
67     FileLock(fd, type, isBlock);
68 
69     FileUnLock(fd);
70 }
71 } // namespace OHOS
72 
73 /* Fuzzer entry point */
LLVMFuzzerTestOneInput(const uint8_t * data,size_t size)74 extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
75 {
76     /* Run your code on data */
77     OHOS::ClientTransProxyFileCommonTest(data, size);
78     return 0;
79 }
80 
81