1d066c7e5Sopenharmony_ci/*
2d066c7e5Sopenharmony_ci * Copyright (c) 2023 Huawei Device Co., Ltd.
3d066c7e5Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License");
4d066c7e5Sopenharmony_ci * you may not use this file except in compliance with the License.
5d066c7e5Sopenharmony_ci * You may obtain a copy of the License at
6d066c7e5Sopenharmony_ci *
7d066c7e5Sopenharmony_ci *     http://www.apache.org/licenses/LICENSE-2.0
8d066c7e5Sopenharmony_ci *
9d066c7e5Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software
10d066c7e5Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS,
11d066c7e5Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12d066c7e5Sopenharmony_ci * See the License for the specific language governing permissions and
13d066c7e5Sopenharmony_ci * limitations under the License.
14d066c7e5Sopenharmony_ci */
15d066c7e5Sopenharmony_ci
16d066c7e5Sopenharmony_ci#include <cstddef>
17d066c7e5Sopenharmony_ci#include <cstdint>
18d066c7e5Sopenharmony_ci#include <string>
19d066c7e5Sopenharmony_ci
20d066c7e5Sopenharmony_ci#include "config_policy_utils.h"
21d066c7e5Sopenharmony_ci
22d066c7e5Sopenharmony_ci#define FUZZ_PROJECT_NAME "getonecfgfile_fuzzer"
23d066c7e5Sopenharmony_ci
24d066c7e5Sopenharmony_ci
25d066c7e5Sopenharmony_cinamespace OHOS {
26d066c7e5Sopenharmony_ci    bool FuzzGetOneCfgFile(const uint8_t* data, size_t size)
27d066c7e5Sopenharmony_ci    {
28d066c7e5Sopenharmony_ci        std::string userPath(reinterpret_cast<const char*>(data), size);
29d066c7e5Sopenharmony_ci        char buf[MAX_PATH_LEN] = {0};
30d066c7e5Sopenharmony_ci        char *filePath = GetOneCfgFile(userPath.c_str(), buf, MAX_PATH_LEN);
31d066c7e5Sopenharmony_ci        return filePath != nullptr;
32d066c7e5Sopenharmony_ci    }
33d066c7e5Sopenharmony_ci}
34d066c7e5Sopenharmony_ci
35d066c7e5Sopenharmony_ci// Fuzzer entry point.
36d066c7e5Sopenharmony_ciextern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
37d066c7e5Sopenharmony_ci{
38d066c7e5Sopenharmony_ci    if (data == nullptr) {
39d066c7e5Sopenharmony_ci        return 0;
40d066c7e5Sopenharmony_ci    }
41d066c7e5Sopenharmony_ci    // Run your code on data.
42d066c7e5Sopenharmony_ci    OHOS::FuzzGetOneCfgFile(data, size);
43d066c7e5Sopenharmony_ci    return 0;
44d066c7e5Sopenharmony_ci}