12498b56bSopenharmony_ci/*
22498b56bSopenharmony_ciCopyright (c) 2021 Huawei Device Co., Ltd.
32498b56bSopenharmony_ciLicensed under the Apache License, Version 2.0 (the "License");
42498b56bSopenharmony_ciyou may not use this file except in compliance with the License.
52498b56bSopenharmony_ciYou may obtain a copy of the License at
62498b56bSopenharmony_cihttp://www.apache.org/licenses/LICENSE-2.0
72498b56bSopenharmony_ciUnless required by applicable law or agreed to in writing, software
82498b56bSopenharmony_cidistributed under the License is distributed on an "AS IS" BASIS,
92498b56bSopenharmony_ciWITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
102498b56bSopenharmony_ciSee the License for the specific language governing permissions and
112498b56bSopenharmony_cilimitations under the License.
122498b56bSopenharmony_ci*/
132498b56bSopenharmony_ci#include "hilogserver_fuzzer.h"
142498b56bSopenharmony_ci
152498b56bSopenharmony_ci#include <cstddef>
162498b56bSopenharmony_ci#include <cstdint>
172498b56bSopenharmony_ci#include <ctime>
182498b56bSopenharmony_ci#include <sys/types.h>
192498b56bSopenharmony_ci#include <unistd.h>
202498b56bSopenharmony_ci#include <sys/syscall.h>
212498b56bSopenharmony_ci#include "hilog/log.h"
222498b56bSopenharmony_ci#include "hilog_common.h"
232498b56bSopenharmony_ci#include "log_collector.h"
242498b56bSopenharmony_ci
252498b56bSopenharmony_cinamespace OHOS {
262498b56bSopenharmony_ci    void DoSomethingInterestingWithMyAPI(const uint8_t* data, size_t size)
272498b56bSopenharmony_ci    {
282498b56bSopenharmony_ci        HiviewDFX::HilogBuffer hilogBuffer(true);
292498b56bSopenharmony_ci        HiviewDFX::LogCollector logCollector(hilogBuffer);
302498b56bSopenharmony_ci        std::vector<char> fuzzerData(reinterpret_cast<const char*>(data), reinterpret_cast<const char*>(data) + size);
312498b56bSopenharmony_ci        logCollector.onDataRecv(fuzzerData, size);
322498b56bSopenharmony_ci    }
332498b56bSopenharmony_ci}
342498b56bSopenharmony_ci
352498b56bSopenharmony_ci/* Fuzzer entry point */
362498b56bSopenharmony_ciextern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
372498b56bSopenharmony_ci{
382498b56bSopenharmony_ci    if (data == nullptr || size == 0) {
392498b56bSopenharmony_ci        std::cout << "invalid data" << std::endl;
402498b56bSopenharmony_ci        return 0;
412498b56bSopenharmony_ci    }
422498b56bSopenharmony_ci    /* Run your code on data */
432498b56bSopenharmony_ci    OHOS::DoSomethingInterestingWithMyAPI(data, size);
442498b56bSopenharmony_ci    return 0;
452498b56bSopenharmony_ci}