1 /*
2 * Copyright (c) 2025 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 "hitraceoption_fuzzer.h"
17
18 #include <cstddef>
19 #include <cstdint>
20 #include <string>
21 #include <iostream>
22 #include <unistd.h>
23 #include <vector>
24
25 #include "hitrace_option/hitrace_option.h"
26 #include "hitrace_fuzztest_common.h"
27
28 namespace OHOS {
29 namespace HiviewDFX {
30 namespace Hitrace {
31
FilterAppTest(const uint8_t * data,size_t size)32 void FilterAppTest(const uint8_t* data, size_t size)
33 {
34 pid_t pid = 0;
35 if (size < sizeof(pid)) {
36 return;
37 }
38 StreamToValueInfo(data, pid);
39 std::string app(reinterpret_cast<const char*>(data), size - sizeof(pid));
40 SetFilterAppName(app);
41 AddFilterPid(pid);
42 FilterAppTrace(app.c_str(), pid);
43 ClearFilterPid();
44 }
45
46 } // namespace Hitrace
47 } // namespace HiviewDFX
48 } // namespace OHOS
49
50 /* Fuzzer entry point */
LLVMFuzzerTestOneInput(const uint8_t * data,size_t size)51 extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
52 {
53 if (data == nullptr || size == 0) {
54 return 0;
55 }
56
57 /* Run your code on data */
58 OHOS::HiviewDFX::Hitrace::FilterAppTest(data, size);
59 return 0;
60 }
61