• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022 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  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #include <cstddef>
17 #include <cstdint>
18 #include <string>
19 
20 #include "faultlogger_client.h"
21 #include "hiviewdfx_faultlogger_fuzzer.h"
22 
23 namespace OHOS {
FuzzInterfaceAddFaultLog(const uint8_t * data,size_t size)24 void FuzzInterfaceAddFaultLog(const uint8_t* data, size_t size)
25 {
26     FaultLogInfoInner inner;
27     inner.time = static_cast<int64_t>(*data);
28     inner.id = static_cast<int32_t>(*data);
29     inner.pid = static_cast<int32_t>(*data);
30     inner.faultLogType = static_cast<HiviewDFX::FaultLogType>(*data);
31     inner.module = std::string(reinterpret_cast<const char*>(data), size);
32     inner.summary = std::string(reinterpret_cast<const char*>(data), size);
33     inner.module = std::string(reinterpret_cast<const char*>(data), size);
34     inner.logPath = std::string(reinterpret_cast<const char*>(data), size);
35     HiviewDFX::AddFaultLog(inner);
36     HiviewDFX::AddFaultLog(inner.time, inner.faultLogType, inner.module, inner.summary);
37 }
38 
FuzzInterfaceQuerySelfFaultLog(const uint8_t * data,size_t size)39 void FuzzInterfaceQuerySelfFaultLog(const uint8_t* data, size_t size)
40 {
41     auto type = static_cast<HiviewDFX::FaultLogType>(*data);
42     auto count = static_cast<int32_t>(*data);
43     auto result = HiviewDFX::QuerySelfFaultLog(type, count);
44     if (result != nullptr) {
45         while (result->HasNext()) {
46             result->Next();
47         }
48     }
49 }
50 
FuzzFaultloggerClientInterface(const uint8_t * data,size_t size)51 void FuzzFaultloggerClientInterface(const uint8_t* data, size_t size)
52 {
53     FuzzInterfaceAddFaultLog(data, size);
54     FuzzInterfaceQuerySelfFaultLog(data, size);
55 }
56 }
57 
58 // Fuzzer entry point.
LLVMFuzzerTestOneInput(const uint8_t * data,size_t size)59 extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
60 {
61     OHOS::FuzzFaultloggerClientInterface(data, size);
62     return 0;
63 }
64