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 #include "fileutils_fuzzer.h"
16 #include "utils/file_utils.h"
17 #include <cstddef>
18 #include <cstdint>
19
20 namespace OHOS {
FileUtilFuzzTest(const uint8_t * data,size_t size)21 bool FileUtilFuzzTest(const uint8_t *data, size_t size)
22 {
23 if ((data == nullptr) || (size < sizeof(uint32_t))) {
24 return false;
25 }
26 unsigned int ustate = *(reinterpret_cast<const unsigned int *>(data));
27 uint32_t state32 = *(reinterpret_cast<const uint32_t *>(data));
28 std::string metaData(reinterpret_cast<const char *>(data), size);
29 struct StorageDaemon::FileList list = {ustate, metaData};
30 std::vector<std::string> metaData2;
31 metaData2.push_back(metaData);
32 std::vector<StorageDaemon::FileList> metaData4;
33 metaData4.push_back(list);
34 std::string metaData5;
35 StorageDaemon::IsDir(metaData);
36 StorageDaemon::StringToUint32(metaData, state32);
37 StorageDaemon::GetSubDirs(metaData, metaData2);
38 StorageDaemon::ReadDigitDir(metaData, metaData4);
39 StorageDaemon::ReadFile(metaData, &metaData5);
40 return true;
41 }
42 } // namespace OHOS
43
44 /* Fuzzer entry point */
LLVMFuzzerTestOneInput(const uint8_t * data,size_t size)45 extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
46 {
47 /* Run your code on data */
48 OHOS::FileUtilFuzzTest(data, size);
49 return 0;
50 }
51