getcontrolfile_fuzzer.cpp 1.2 KB
Newer Older
X
xionglei6 已提交
1
/*
C
chengjinsong2 已提交
2
 * Copyright (c) 2022 Huawei Device Co., Ltd.
X
xionglei6 已提交
3 4 5 6
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
C
chengjinsong2 已提交
7
 * http://www.apache.org/licenses/LICENSE-2.0
X
xionglei6 已提交
8 9 10 11 12 13 14 15
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

X
xionglei6 已提交
16
#include "getcontrolfile_fuzzer.h"
C
cheng_jinsong 已提交
17 18
#include <string>
#include <climits>
X
xionglei6 已提交
19 20 21 22 23 24
#include "init_file.h"

namespace OHOS {
    bool FuzzGetControlFile(const uint8_t* data, size_t size)
    {
        bool result = false;
C
cheng_jinsong 已提交
25 26 27 28 29
        if (size > PATH_MAX) {
            return true;
        }
        std::string str(reinterpret_cast<const char*>(data), size);
        if (!GetControlFile(str.c_str())) {
X
xionglei6 已提交
30 31 32 33 34 35 36 37 38 39 40 41
            result = true;
        }
        return result;
    }
}

/* Fuzzer entry point */
extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
{
    /* Run your code on data */
    OHOS::FuzzGetControlFile(data, size);
    return 0;
C
chengjinsong2 已提交
42
}