/src/curl_fuzzer/proto_fuzzer/option_apply.h
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 Translates Scenario SetOption messages into curl_easy_setopt calls, |
9 | | /// plus the fixed baseline setopts the harness always applies. |
10 | | |
11 | | #ifndef PROTO_FUZZER_OPTION_APPLY_H_ |
12 | | #define PROTO_FUZZER_OPTION_APPLY_H_ |
13 | | |
14 | | #include <curl/curl.h> |
15 | | |
16 | | #include <cstddef> |
17 | | #include <cstdint> |
18 | | #include <string> |
19 | | |
20 | | #include "curl_fuzzer.pb.h" |
21 | | #include "proto_fuzzer/option_model.h" |
22 | | |
23 | | namespace proto_fuzzer { |
24 | | |
25 | | /// Reset curl's global trace configuration to a known off baseline for the |
26 | | /// lifetime of one input. |
27 | | /// |
28 | | /// curl_global_trace() only mutates the components it names and exposes no |
29 | | /// read-back, so a true save/restore is not possible through the public API. |
30 | | /// Instead the guard resets "-all" on both entry and exit: the input's trace |
31 | | /// selection is contained to the guard's scope, and a previous input's "all" |
32 | | /// (or any subset it left enabled) cannot leak into the next input. This makes |
33 | | /// coverage and any trace-dependent failure independent of corpus order. |
34 | | class ScopedTraceReset final { |
35 | | public: |
36 | 240k | ScopedTraceReset() { (void)curl_global_trace("-all"); } |
37 | 240k | ~ScopedTraceReset() { (void)curl_global_trace("-all"); } |
38 | | |
39 | | ScopedTraceReset(const ScopedTraceReset&) = delete; |
40 | | ScopedTraceReset& operator=(const ScopedTraceReset&) = delete; |
41 | | ScopedTraceReset(ScopedTraceReset&&) = delete; |
42 | | ScopedTraceReset& operator=(ScopedTraceReset&&) = delete; |
43 | | }; |
44 | | |
45 | | struct curl_slist* ApplyBaselineOptions(CURL* easy, curl::fuzzer::proto::Scheme scheme, bool trace_ids = false, |
46 | | const std::string& trace_config = {}); |
47 | | |
48 | | CURLcode ApplySetOption(CURL* easy, const curl::fuzzer::proto::SetOption& option); |
49 | | |
50 | | CURLcode ApplyTlsClientCredentialProfile(CURL* easy, curl::fuzzer::proto::TlsClientCredentialProfile profile); |
51 | | |
52 | | std::size_t RuntimeOptionCount(const curl::fuzzer::proto::Scenario& scenario); |
53 | | |
54 | | std::size_t ApplyScenarioOptions(CURL* easy, const curl::fuzzer::proto::Scenario& scenario); |
55 | | |
56 | | } // namespace proto_fuzzer |
57 | | |
58 | | #endif // PROTO_FUZZER_OPTION_APPLY_H_ |