/src/curl_fuzzer/proto_fuzzer/fuzzer_main.cc
Line | Count | Source |
1 | | /* |
2 | | * Copyright (C) Max Dymond, <cmeister2@gmail.com>, et al. |
3 | | * |
4 | | * SPDX-License-Identifier: curl |
5 | | */ |
6 | | |
7 | | /// @file |
8 | | /// @brief libFuzzer entrypoint for the libprotobuf-mutator HTTP fuzzer. |
9 | | /// Wires DEFINE_BINARY_PROTO_FUZZER to ScenarioRunner::Run. |
10 | | |
11 | | #include <curl/curl.h> |
12 | | #include <libprotobuf-mutator/src/libfuzzer/libfuzzer_macro.h> |
13 | | |
14 | | #include "curl_fuzzer.pb.h" |
15 | | #include "proto_fuzzer/scenario_runner.h" |
16 | | |
17 | | namespace { |
18 | | |
19 | | // Wire curl_global_init once so repeated fuzz iterations don't pay for it on every call. libFuzzer reuses the process; |
20 | | // static ctors run once. |
21 | | struct CurlGlobalBootstrap { |
22 | 2 | CurlGlobalBootstrap() { curl_global_init(CURL_GLOBAL_ALL); } |
23 | | }; |
24 | | const CurlGlobalBootstrap kGlobalBootstrap; |
25 | | |
26 | | } // namespace |
27 | | |
28 | | /// @brief libFuzzer entry point. libFuzzer will call this function with a valid Scenario protobuf message on each |
29 | | /// fuzzing iteration. The function is expected to run the scenario and return. Any crashes or undefined behavior during |
30 | | /// scenario execution will be reported by libFuzzer as fuzzing bugs. |
31 | | /// @param scenario The Scenario describing the curl operations to perform. |
32 | 3.30k | DEFINE_BINARY_PROTO_FUZZER(const curl::fuzzer::proto::Scenario& scenario) { |
33 | 3.30k | proto_fuzzer::ScenarioRunner().Run(scenario); |
34 | 3.30k | } |