xref: /aosp_15_r20/external/stg/fuzz/btf_reader_fuzzer.cc (revision 9e3b08ae94a55201065475453d799e8b1378bea6)
1 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
2 // -*- mode: C++ -*-
3 //
4 // Copyright 2021-2022 Google LLC
5 //
6 // Licensed under the Apache License v2.0 with LLVM Exceptions (the
7 // "License"); you may not use this file except in compliance with the
8 // License.  You may obtain a copy of the License at
9 //
10 //     https://llvm.org/LICENSE.txt
11 //
12 // Unless required by applicable law or agreed to in writing, software
13 // distributed under the License is distributed on an "AS IS" BASIS,
14 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 // See the License for the specific language governing permissions and
16 // limitations under the License.
17 //
18 // Author: Matthias Maennich
19 
20 #include <cstddef>
21 #include <string_view>
22 
23 #include "btf_reader.h"
24 #include "error.h"
25 #include "graph.h"
26 
LLVMFuzzerTestOneInput(const char * data,size_t size)27 extern "C" int LLVMFuzzerTestOneInput(const char* data, size_t size) {
28   try {
29     stg::Graph graph;
30     stg::btf::ReadSection(graph, std::string_view(data, size));
31   } catch (const stg::Exception&) {
32     // Pass as this is us catching invalid BTF properly.
33   }
34   return 0;
35 }
36