1 /*
2 Copyright (c) 2021 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 http://www.apache.org/licenses/LICENSE-2.0
7 Unless required by applicable law or agreed to in writing, software
8 distributed under the License is distributed on an "AS IS" BASIS,
9 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10 See the License for the specific language governing permissions and
11 limitations 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 
25 namespace OHOS {
DoSomethingInterestingWithMyAPI(const uint8_t * data,size_t size)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 */
LLVMFuzzerTestOneInput(const uint8_t * data,size_t size)36 extern "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 }