1 /*
2 * Copyright (c) 2024 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 "faultloggerdclient_fuzzer.h"
17
18 #include <cstddef>
19 #include <iostream>
20 #include "faultloggerd_client.h"
21 #include "fault_logger_daemon.h"
22 #include "faultloggerd_fuzzertest_common.h"
23
24 namespace OHOS {
25 namespace HiviewDFX {
26
FaultloggerdClientTest(const uint8_t * data,size_t size)27 void FaultloggerdClientTest(const uint8_t* data, size_t size)
28 {
29 int32_t type;
30 int32_t pid;
31 int32_t tid;
32
33 int offsetTotalLength = sizeof(type) + sizeof(pid) + sizeof(tid);
34 if (offsetTotalLength > size) {
35 return;
36 }
37
38 STREAM_TO_VALUEINFO(data, type);
39 STREAM_TO_VALUEINFO(data, pid);
40 STREAM_TO_VALUEINFO(data, tid);
41
42 RequestFileDescriptor(type);
43 RequestPipeFd(pid, type);
44 RequestDelPipeFd(pid);
45 RequestCheckPermission(pid);
46 RequestSdkDump(pid, tid);
47 }
48 } // namespace HiviewDFX
49 } // namespace OHOS
50
51 /* Fuzzer entry point */
LLVMFuzzerTestOneInput(const uint8_t * data,size_t size)52 extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
53 {
54 if (data == nullptr || size == 0) {
55 return 0;
56 }
57
58 /* Run your code on data */
59 OHOS::HiviewDFX::FaultloggerdClientTest(data, size);
60 return 0;
61 }
62