1/*
2Copyright (c) 2021 Huawei Device Co., Ltd.
3Licensed under the Apache License, Version 2.0 (the "License");
4you may not use this file except in compliance with the License.
5You may obtain a copy of the License at
6http://www.apache.org/licenses/LICENSE-2.0
7Unless required by applicable law or agreed to in writing, software
8distributed under the License is distributed on an "AS IS" BASIS,
9WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10See the License for the specific language governing permissions and
11limitations under the License.
12*/
13#include "hilogserver_fuzzer.h"
14
15#include <cstddef>
16#include <cstdint>
17#include <ctime>
18#include <sys/types.h>
19#include <unistd.h>
20#include <sys/syscall.h>
21#include "hilog/log.h"
22#include "hilog_common.h"
23#include "log_collector.h"
24
25namespace OHOS {
26    void DoSomethingInterestingWithMyAPI(const uint8_t* data, size_t size)
27    {
28        HiviewDFX::HilogBuffer hilogBuffer(true);
29        HiviewDFX::LogCollector logCollector(hilogBuffer);
30        std::vector<char> fuzzerData(reinterpret_cast<const char*>(data), reinterpret_cast<const char*>(data) + size);
31        logCollector.onDataRecv(fuzzerData, size);
32    }
33}
34
35/* Fuzzer entry point */
36extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
37{
38    if (data == nullptr || size == 0) {
39        std::cout << "invalid data" << std::endl;
40        return 0;
41    }
42    /* Run your code on data */
43    OHOS::DoSomethingInterestingWithMyAPI(data, size);
44    return 0;
45}