/src/curl_fuzzer/proto_fuzzer/target_policy.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 Implementation of the per-binary proto mutation policies. |
9 | | |
10 | | #include "proto_fuzzer/target_policy.h" |
11 | | |
12 | | #include <curl/curl.h> |
13 | | |
14 | | #include <algorithm> |
15 | | #include <array> |
16 | | #include <cstddef> |
17 | | #include <cstdint> |
18 | | #include <limits> |
19 | | #include <string> |
20 | | |
21 | | #include "proto_fuzzer/option_model.h" |
22 | | #include "proto_fuzzer/scenario_limits.h" |
23 | | #include "proto_fuzzer/telnet_scenario.h" |
24 | | |
25 | | namespace proto_fuzzer { |
26 | | |
27 | | namespace { |
28 | | |
29 | | // Linux raises smaller socket-buffer requests to an implementation minimum, |
30 | | // so 2048 is both cheap and reliably small enough to exercise short writes. |
31 | | constexpr std::uint32_t kDefaultBackpressureBufferBytes = 2048; |
32 | | |
33 | | // Values outside these ranges do not create useful new socket behavior for |
34 | | // the harness's bounded 4-16 KiB writes. Keeping them small also prevents a |
35 | | // mutated uint32 recv size from overflowing the int accepted by setsockopt. |
36 | | constexpr std::uint32_t kMinBackpressureBufferBytes = 2048; |
37 | | constexpr std::uint32_t kMaxBackpressureBufferBytes = 4096; |
38 | | constexpr std::uint32_t kMaxDrainBytesPerIteration = 1024; |
39 | | constexpr std::uint32_t kHaproxyConnectBufferBytes = 2048; |
40 | | constexpr std::uint32_t kHaproxyConnectDrainBytes = 48; |
41 | | constexpr std::uint32_t kMqttProbeBufferBytes = 2048; |
42 | | constexpr std::uint32_t kMqttProbeDrainBytes = 1024; |
43 | | constexpr std::uint32_t kSmtpProbeBufferBytes = 2048; |
44 | | constexpr std::uint32_t kSmtpProbeDrainBytes = 1024; |
45 | | |
46 | | // CURLOPT_LOCALPORTRANGE performs one synchronous bind attempt per selected |
47 | | // port. Retain a useful retry window without letting one mutation request tens |
48 | | // of thousands of syscalls from a single transfer. |
49 | | constexpr std::uint64_t kMaxLocalPortRange = 16; |
50 | | constexpr std::size_t kGopherTlsPeerKeyHostBytes = 10163; |
51 | | |
52 | | // A default, bounded identifier keeps newly generated inputs on the gateway's |
53 | | // /ipfs/ or /ipns/ namespace. The path, query, and fragment after it stay |
54 | | // mutation-controlled. |
55 | | constexpr char kDefaultIpfsCid[] = "bafybeigdyrzt5sfp7udm7hu76uh7y26nf3efuylqabf3oclgtqy55fbzdi"; |
56 | | constexpr char kDefaultIpnsName[] = "k51qzi5uqu5dlvj2baxnqndepeb86cbk3ng7n3i46uzyxzyqj2xjonzllnv0v8"; |
57 | | |
58 | | /// Remove a repeated-field suffix that the runtime would ignore. Doing this |
59 | | /// in LPM's postprocessor matters for speed as well as memory: otherwise later |
60 | | /// mutations keep rediscovering and editing objects that cannot reach curl. |
61 | | template <typename RepeatedField> |
62 | 5.64M | void TrimRepeated(RepeatedField* field, std::size_t limit) { |
63 | 5.64M | const std::size_t size = static_cast<std::size_t>(field->size()); |
64 | 5.64M | if (size > limit) { |
65 | 5.96k | field->DeleteSubrange(static_cast<int>(limit), static_cast<int>(size - limit)); |
66 | 5.96k | } |
67 | 5.64M | } target_policy.cc:void proto_fuzzer::(anonymous namespace)::TrimRepeated<google::protobuf::RepeatedPtrField<curl::fuzzer::proto::SetOption> >(google::protobuf::RepeatedPtrField<curl::fuzzer::proto::SetOption>*, unsigned long) Line | Count | Source | 62 | 623k | void TrimRepeated(RepeatedField* field, std::size_t limit) { | 63 | 623k | const std::size_t size = static_cast<std::size_t>(field->size()); | 64 | 623k | if (size > limit) { | 65 | 2.29k | field->DeleteSubrange(static_cast<int>(limit), static_cast<int>(size - limit)); | 66 | 2.29k | } | 67 | 623k | } |
target_policy.cc:void proto_fuzzer::(anonymous namespace)::TrimRepeated<google::protobuf::RepeatedPtrField<curl::fuzzer::proto::MimePart> >(google::protobuf::RepeatedPtrField<curl::fuzzer::proto::MimePart>*, unsigned long) Line | Count | Source | 62 | 213k | void TrimRepeated(RepeatedField* field, std::size_t limit) { | 63 | 213k | const std::size_t size = static_cast<std::size_t>(field->size()); | 64 | 213k | if (size > limit) { | 65 | 642 | field->DeleteSubrange(static_cast<int>(limit), static_cast<int>(size - limit)); | 66 | 642 | } | 67 | 213k | } |
target_policy.cc:void proto_fuzzer::(anonymous namespace)::TrimRepeated<google::protobuf::RepeatedPtrField<curl::fuzzer::proto::MimeDataPart> >(google::protobuf::RepeatedPtrField<curl::fuzzer::proto::MimeDataPart>*, unsigned long) Line | Count | Source | 62 | 66.9k | void TrimRepeated(RepeatedField* field, std::size_t limit) { | 63 | 66.9k | const std::size_t size = static_cast<std::size_t>(field->size()); | 64 | 66.9k | if (size > limit) { | 65 | 301 | field->DeleteSubrange(static_cast<int>(limit), static_cast<int>(size - limit)); | 66 | 301 | } | 67 | 66.9k | } |
target_policy.cc:void proto_fuzzer::(anonymous namespace)::TrimRepeated<google::protobuf::RepeatedPtrField<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > > >(google::protobuf::RepeatedPtrField<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > >*, unsigned long) Line | Count | Source | 62 | 2.98M | void TrimRepeated(RepeatedField* field, std::size_t limit) { | 63 | 2.98M | const std::size_t size = static_cast<std::size_t>(field->size()); | 64 | 2.98M | if (size > limit) { | 65 | 1.51k | field->DeleteSubrange(static_cast<int>(limit), static_cast<int>(size - limit)); | 66 | 1.51k | } | 67 | 2.98M | } |
target_policy.cc:void proto_fuzzer::(anonymous namespace)::TrimRepeated<google::protobuf::RepeatedPtrField<curl::fuzzer::proto::WebSocketFrame> >(google::protobuf::RepeatedPtrField<curl::fuzzer::proto::WebSocketFrame>*, unsigned long) Line | Count | Source | 62 | 750k | void TrimRepeated(RepeatedField* field, std::size_t limit) { | 63 | 750k | const std::size_t size = static_cast<std::size_t>(field->size()); | 64 | 750k | if (size > limit) { | 65 | 235 | field->DeleteSubrange(static_cast<int>(limit), static_cast<int>(size - limit)); | 66 | 235 | } | 67 | 750k | } |
target_policy.cc:void proto_fuzzer::(anonymous namespace)::TrimRepeated<google::protobuf::RepeatedPtrField<curl::fuzzer::proto::Http3Action> >(google::protobuf::RepeatedPtrField<curl::fuzzer::proto::Http3Action>*, unsigned long) Line | Count | Source | 62 | 11.7k | void TrimRepeated(RepeatedField* field, std::size_t limit) { | 63 | 11.7k | const std::size_t size = static_cast<std::size_t>(field->size()); | 64 | 11.7k | if (size > limit) { | 65 | 81 | field->DeleteSubrange(static_cast<int>(limit), static_cast<int>(size - limit)); | 66 | 81 | } | 67 | 11.7k | } |
target_policy.cc:void proto_fuzzer::(anonymous namespace)::TrimRepeated<google::protobuf::RepeatedPtrField<curl::fuzzer::proto::Http3Header> >(google::protobuf::RepeatedPtrField<curl::fuzzer::proto::Http3Header>*, unsigned long) Line | Count | Source | 62 | 13.2k | void TrimRepeated(RepeatedField* field, std::size_t limit) { | 63 | 13.2k | const std::size_t size = static_cast<std::size_t>(field->size()); | 64 | 13.2k | if (size > limit) { | 65 | 45 | field->DeleteSubrange(static_cast<int>(limit), static_cast<int>(size - limit)); | 66 | 45 | } | 67 | 13.2k | } |
target_policy.cc:void proto_fuzzer::(anonymous namespace)::TrimRepeated<google::protobuf::RepeatedPtrField<curl::fuzzer::proto::Http2Action> >(google::protobuf::RepeatedPtrField<curl::fuzzer::proto::Http2Action>*, unsigned long) Line | Count | Source | 62 | 36.1k | void TrimRepeated(RepeatedField* field, std::size_t limit) { | 63 | 36.1k | const std::size_t size = static_cast<std::size_t>(field->size()); | 64 | 36.1k | if (size > limit) { | 65 | 159 | field->DeleteSubrange(static_cast<int>(limit), static_cast<int>(size - limit)); | 66 | 159 | } | 67 | 36.1k | } |
target_policy.cc:void proto_fuzzer::(anonymous namespace)::TrimRepeated<google::protobuf::RepeatedPtrField<curl::fuzzer::proto::Http2Setting> >(google::protobuf::RepeatedPtrField<curl::fuzzer::proto::Http2Setting>*, unsigned long) Line | Count | Source | 62 | 53.5k | void TrimRepeated(RepeatedField* field, std::size_t limit) { | 63 | 53.5k | const std::size_t size = static_cast<std::size_t>(field->size()); | 64 | 53.5k | if (size > limit) { | 65 | 43 | field->DeleteSubrange(static_cast<int>(limit), static_cast<int>(size - limit)); | 66 | 43 | } | 67 | 53.5k | } |
target_policy.cc:void proto_fuzzer::(anonymous namespace)::TrimRepeated<google::protobuf::RepeatedPtrField<curl::fuzzer::proto::Http2Header> >(google::protobuf::RepeatedPtrField<curl::fuzzer::proto::Http2Header>*, unsigned long) Line | Count | Source | 62 | 182k | void TrimRepeated(RepeatedField* field, std::size_t limit) { | 63 | 182k | const std::size_t size = static_cast<std::size_t>(field->size()); | 64 | 182k | if (size > limit) { | 65 | 19 | field->DeleteSubrange(static_cast<int>(limit), static_cast<int>(size - limit)); | 66 | 19 | } | 67 | 182k | } |
target_policy.cc:void proto_fuzzer::(anonymous namespace)::TrimRepeated<google::protobuf::RepeatedPtrField<curl::fuzzer::proto::MultiAction> >(google::protobuf::RepeatedPtrField<curl::fuzzer::proto::MultiAction>*, unsigned long) Line | Count | Source | 62 | 36.4k | void TrimRepeated(RepeatedField* field, std::size_t limit) { | 63 | 36.4k | const std::size_t size = static_cast<std::size_t>(field->size()); | 64 | 36.4k | if (size > limit) { | 65 | 16 | field->DeleteSubrange(static_cast<int>(limit), static_cast<int>(size - limit)); | 66 | 16 | } | 67 | 36.4k | } |
target_policy.cc:void proto_fuzzer::(anonymous namespace)::TrimRepeated<google::protobuf::RepeatedPtrField<curl::fuzzer::proto::Connection> >(google::protobuf::RepeatedPtrField<curl::fuzzer::proto::Connection>*, unsigned long) Line | Count | Source | 62 | 675k | void TrimRepeated(RepeatedField* field, std::size_t limit) { | 63 | 675k | const std::size_t size = static_cast<std::size_t>(field->size()); | 64 | 675k | if (size > limit) { | 65 | 622 | field->DeleteSubrange(static_cast<int>(limit), static_cast<int>(size - limit)); | 66 | 622 | } | 67 | 675k | } |
|
68 | | |
69 | | /// Bound fixed-target metadata. Compatibility inputs preserve their original |
70 | | /// option strings; consumers of bounded request metadata cap their own views. |
71 | 1.77M | void TrimMetadata(std::string* value) { |
72 | 1.77M | if (value->size() > scenario_limits::kMaxMetadataBytes) { |
73 | 121 | value->resize(scenario_limits::kMaxMetadataBytes); |
74 | 121 | } |
75 | 1.77M | } |
76 | | |
77 | | /// Give the successful-TLS lane a hostname its fixed certificate can verify |
78 | | /// while retaining the fuzz-controlled path, query, and fragment. Arbitrary |
79 | | /// authorities remain covered by the compatibility lane; |
80 | | /// spending this lane's mutations on URL failures would keep curl's peer-cert |
81 | | /// and encrypted application-data paths dark. |
82 | 197k | void CanonicalizeTlsAuthority(curl::fuzzer::proto::Scenario* scenario) { |
83 | 197k | const std::string& host_path = scenario->host_path(); |
84 | 197k | const std::size_t suffix_start = host_path.find_first_of("/?#"); |
85 | 197k | if (suffix_start == std::string::npos) { |
86 | 4.85k | scenario->set_host_path("tls.test/"); |
87 | 4.85k | return; |
88 | 4.85k | } |
89 | 193k | scenario->set_host_path("tls.test" + host_path.substr(suffix_start)); |
90 | 193k | } |
91 | | |
92 | | /// Give CONNECT-UDP one fixed IPv6 destination when the input selects a |
93 | | /// bracketed authority. The proxy transport remains the owned loopback peer; |
94 | | /// only curl's MASQUE URI encoder consumes this destination literal. |
95 | 15.3k | void CanonicalizeHttp3Authority(curl::fuzzer::proto::Scenario* scenario) { |
96 | 15.3k | const std::string& host_path = scenario->host_path(); |
97 | 15.3k | if (!scenario->http3_plan().use_h1_connect_udp_proxy() || host_path.empty() || host_path.front() != '[') { |
98 | 15.3k | CanonicalizeTlsAuthority(scenario); |
99 | 15.3k | return; |
100 | 15.3k | } |
101 | 4 | const std::size_t suffix_start = host_path.find_first_of("/?#"); |
102 | 4 | scenario->set_host_path(std::string("[::1]") + |
103 | 4 | (suffix_start == std::string::npos ? "/" : host_path.substr(suffix_start))); |
104 | 4 | } |
105 | | |
106 | | /// Alt-Svc lookup cannot run while the harness's wildcard CONNECT_TO route is |
107 | | /// active. Give file-backed Alt-Svc inputs one fixed origin whose port can be |
108 | | /// populated in curl's DNS cache before that override is safely detached, |
109 | | /// while preserving all mutation-controlled path, query, and fragment bytes. |
110 | 1.85k | void CanonicalizeAltSvcAuthority(curl::fuzzer::proto::Scenario* scenario) { |
111 | 1.85k | const std::string& host_path = scenario->host_path(); |
112 | 1.85k | const std::size_t suffix_start = host_path.find_first_of("/?#"); |
113 | 1.85k | if (suffix_start == std::string::npos) { |
114 | 5 | scenario->set_host_path("altsvc-origin.test/"); |
115 | 5 | return; |
116 | 5 | } |
117 | 1.85k | scenario->set_host_path("altsvc-origin.test" + host_path.substr(suffix_start)); |
118 | 1.85k | } |
119 | | |
120 | | /// Both fixed TLS peers support the same closed set of checked-in certificate |
121 | | /// bundles. Unknown proto3 enum values fall back to the historical EC chain. |
122 | 146k | void CanonicalizeTlsCertificateChain(curl::fuzzer::proto::Scenario* scenario) { |
123 | 146k | switch (scenario->tls_certificate_chain()) { |
124 | 133k | case curl::fuzzer::proto::TLS_CERTIFICATE_CHAIN_DEFAULT_EC: |
125 | 145k | case curl::fuzzer::proto::TLS_CERTIFICATE_CHAIN_ALL_KEY_TYPES: |
126 | 145k | return; |
127 | 114 | default: |
128 | 114 | scenario->clear_tls_certificate_chain(); |
129 | 114 | return; |
130 | 146k | } |
131 | 146k | } |
132 | | |
133 | | /// Keep the HTTPS/HTTP2 group selector inside its closed, useful set. Unknown |
134 | | /// proto3 enum values take the inexpensive historical-input path. |
135 | 29.5k | void CanonicalizeTlsGroupProfile(curl::fuzzer::proto::Scenario* scenario) { |
136 | 29.5k | switch (scenario->tls_group_profile()) { |
137 | 27.0k | case curl::fuzzer::proto::TLS_GROUP_X25519: |
138 | 29.5k | case curl::fuzzer::proto::TLS_GROUP_PROVIDER_DEFAULT: |
139 | 29.5k | return; |
140 | 1 | default: |
141 | 1 | scenario->clear_tls_group_profile(); |
142 | 1 | return; |
143 | 29.5k | } |
144 | 29.5k | } |
145 | | |
146 | | /// Keep the client-side TLS probe inside the closed set whose backing bytes, |
147 | | /// paths, and provider names are owned by the harness. |
148 | 81.3k | void CanonicalizeTlsClientCredentialProfile(curl::fuzzer::proto::Scenario* scenario) { |
149 | 81.3k | switch (scenario->tls_client_credential_profile()) { |
150 | 76.9k | case curl::fuzzer::proto::TLS_CLIENT_CREDENTIAL_NONE: |
151 | 78.6k | case curl::fuzzer::proto::TLS_CLIENT_CREDENTIAL_MALFORMED_PKCS12: |
152 | 79.1k | case curl::fuzzer::proto::TLS_CLIENT_CREDENTIAL_ENGINE_DEV_NULL: |
153 | 80.8k | case curl::fuzzer::proto::TLS_CLIENT_CREDENTIAL_DEFAULT_PROVIDER_DEV_NULL: |
154 | 81.3k | case curl::fuzzer::proto::TLS_CLIENT_CREDENTIAL_UNLOADED_PROVIDER_DEV_NULL: |
155 | 81.3k | return; |
156 | 7 | default: |
157 | 7 | scenario->clear_tls_client_credential_profile(); |
158 | 7 | return; |
159 | 81.3k | } |
160 | 81.3k | } |
161 | | |
162 | | /// Keep the OpenSSL handshake terminal inside its closed, harness-owned set. |
163 | 81.3k | void CanonicalizeTlsHandshakeProfile(curl::fuzzer::proto::Scenario* scenario) { |
164 | 81.3k | switch (scenario->tls_handshake_profile()) { |
165 | 77.4k | case curl::fuzzer::proto::TLS_HANDSHAKE_DEFAULT: |
166 | 81.0k | case curl::fuzzer::proto::TLS_HANDSHAKE_OPENSSL_CLOSE_NOTIFY: |
167 | 81.3k | case curl::fuzzer::proto::TLS_HANDSHAKE_OPENSSL_HELLO_REQUEST: |
168 | 81.3k | return; |
169 | 9 | default: |
170 | 9 | scenario->clear_tls_handshake_profile(); |
171 | 9 | return; |
172 | 81.3k | } |
173 | 81.3k | } |
174 | | |
175 | | /// Keep Gopher's harness-owned transport probe inside its closed enum. The |
176 | | /// fixed TLS hostname is long enough to reach the session-key size limit but |
177 | | /// remains below the structured target's 32 KiB input cap. |
178 | 17.9k | void CanonicalizeGopherProbeMode(curl::fuzzer::proto::Scenario* scenario) { |
179 | 17.9k | switch (scenario->gopher_probe_mode()) { |
180 | 17.6k | case curl::fuzzer::proto::GOPHER_PROBE_DEFAULT: |
181 | 17.7k | case curl::fuzzer::proto::GOPHER_PROBE_PARTIAL_WRITE_NO_TIMEOUT: |
182 | 17.8k | case curl::fuzzer::proto::GOPHER_PROBE_SEND_TIMEOUT: |
183 | 17.9k | case curl::fuzzer::proto::GOPHER_PROBE_TLS_SESSION_KEY_LIMIT: |
184 | 17.9k | return; |
185 | 1 | default: |
186 | 1 | scenario->clear_gopher_probe_mode(); |
187 | 1 | return; |
188 | 17.9k | } |
189 | 17.9k | } |
190 | | |
191 | | /// Keep RTSP's harness-owned lifecycle and client-write probes inside their |
192 | | /// closed enum. Unknown values preserve the ordinary single-transfer path. |
193 | 15.7k | void CanonicalizeRtspProbeMode(curl::fuzzer::proto::Scenario* scenario) { |
194 | 15.7k | switch (scenario->rtsp_probe_mode()) { |
195 | 15.7k | case curl::fuzzer::proto::RTSP_PROBE_DEFAULT: |
196 | 15.7k | case curl::fuzzer::proto::RTSP_PROBE_CROSS_ORIGIN_REUSE: |
197 | 15.7k | case curl::fuzzer::proto::RTSP_PROBE_SPLIT_INVALID_RTP_WRITE_FAILURE: |
198 | 15.7k | return; |
199 | 0 | default: |
200 | 0 | scenario->clear_rtsp_probe_mode(); |
201 | 0 | return; |
202 | 15.7k | } |
203 | 15.7k | } |
204 | | |
205 | | /// Keep MQTT's harness-owned send and credential probes inside their closed |
206 | | /// enum. The compatibility target preserves this append-only field without |
207 | | /// reaching this postprocessor. |
208 | 8.42k | void CanonicalizeMqttProbeMode(curl::fuzzer::proto::Scenario* scenario) { |
209 | 8.42k | switch (scenario->mqtt_probe_mode()) { |
210 | 8.41k | case curl::fuzzer::proto::MQTT_PROBE_DEFAULT: |
211 | 8.42k | case curl::fuzzer::proto::MQTT_PROBE_SEND_BACKPRESSURE: |
212 | 8.42k | case curl::fuzzer::proto::MQTT_PROBE_OVERSIZED_USERNAME: |
213 | 8.42k | case curl::fuzzer::proto::MQTT_PROBE_OVERSIZED_PASSWORD: |
214 | 8.42k | return; |
215 | 0 | default: |
216 | 0 | scenario->clear_mqtt_probe_mode(); |
217 | 0 | return; |
218 | 8.42k | } |
219 | 8.42k | } |
220 | | |
221 | | /// Keep SMTP's harness-owned TLS and send probes inside their closed enum. |
222 | | /// Compatibility does not run this postprocessor and preserves appended data. |
223 | 12.0k | void CanonicalizeSmtpProbeMode(curl::fuzzer::proto::Scenario* scenario) { |
224 | 12.0k | switch (scenario->smtp_probe_mode()) { |
225 | 12.0k | case curl::fuzzer::proto::SMTP_PROBE_DEFAULT: |
226 | 12.0k | case curl::fuzzer::proto::SMTP_PROBE_STARTTLS_TRY: |
227 | 12.0k | case curl::fuzzer::proto::SMTP_PROBE_STARTTLS_REQUIRE: |
228 | 12.0k | case curl::fuzzer::proto::SMTP_PROBE_STARTTLS_FILTER_ALLOCATION_FAILURE: |
229 | 12.0k | case curl::fuzzer::proto::SMTP_PROBE_SEND_BACKPRESSURE: |
230 | 12.0k | return; |
231 | 0 | default: |
232 | 0 | scenario->clear_smtp_probe_mode(); |
233 | 0 | return; |
234 | 12.0k | } |
235 | 12.0k | } |
236 | | |
237 | | /// Keep the proxied origin parseable while retaining every path, query, and |
238 | | /// fragment byte. The fixed numeric proxy endpoint handles routing separately; |
239 | | /// mutating the origin authority would therefore buy only early URL failures, |
240 | | /// not additional HTTP/2 proxy behavior. |
241 | 27.0k | void CanonicalizeH2ProxyOriginAuthority(curl::fuzzer::proto::Scenario* scenario) { |
242 | 27.0k | const std::string& host_path = scenario->host_path(); |
243 | 27.0k | const std::size_t suffix_start = host_path.find_first_of("/?#"); |
244 | 27.0k | if (suffix_start == std::string::npos) { |
245 | 494 | scenario->set_host_path("origin.test/"); |
246 | 494 | return; |
247 | 494 | } |
248 | 26.5k | scenario->set_host_path("origin.test" + host_path.substr(suffix_start)); |
249 | 26.5k | } |
250 | | |
251 | | /// Local-resolution SOCKS modes use libc/curl's deterministic localhost path, |
252 | | /// while SOCKS4A and SOCKS5-hostname deliberately carry a fixed hostname to |
253 | | /// the proxy. The path/query/fragment stays mutation-controlled. |
254 | 28.3k | void CanonicalizeSocksAuthority(curl::fuzzer::proto::Scenario* scenario) { |
255 | 28.3k | const std::string& host_path = scenario->host_path(); |
256 | 28.3k | const std::size_t suffix_start = host_path.find_first_of("/?#"); |
257 | 28.3k | const auto mode = scenario->socks_proxy_mode(); |
258 | 28.3k | const bool resolve_at_proxy = |
259 | 28.3k | mode == curl::fuzzer::proto::SOCKS_PROXY_SOCKS4A || mode == curl::fuzzer::proto::SOCKS_PROXY_SOCKS5_HOSTNAME; |
260 | 28.3k | const char* host = resolve_at_proxy ? "socks.test" : "localhost"; |
261 | 28.3k | if (suffix_start == std::string::npos) { |
262 | 364 | scenario->set_host_path(std::string(host) + "/"); |
263 | 364 | return; |
264 | 364 | } |
265 | 27.9k | scenario->set_host_path(std::string(host) + host_path.substr(suffix_start)); |
266 | 27.9k | } |
267 | | |
268 | | /// Keep proxy and Unix-domain HTTP transfers on one parseable origin while |
269 | | /// preserving the mutation-controlled path, query, and fragment. Routing is |
270 | | /// selected independently by a fixed numeric proxy or abstract socket name, |
271 | | /// so authority mutation would add early URL failures without new transport |
272 | | /// behavior. |
273 | 4.56k | void CanonicalizeHttpTransportAuthority(curl::fuzzer::proto::Scenario* scenario) { |
274 | 4.56k | const std::string& host_path = scenario->host_path(); |
275 | 4.56k | const std::size_t suffix_start = host_path.find_first_of("/?#"); |
276 | 4.56k | if (suffix_start == std::string::npos) { |
277 | 9 | scenario->set_host_path("transport.test/"); |
278 | 9 | return; |
279 | 9 | } |
280 | 4.55k | scenario->set_host_path("transport.test" + host_path.substr(suffix_start)); |
281 | 4.55k | } |
282 | | |
283 | | /// Select a fixed origin that drives the chosen no-proxy parser or owned TCP |
284 | | /// listener while retaining the mutation-controlled path, query, and fragment. |
285 | 11.7k | void CanonicalizeProxySocketOptionAuthority(curl::fuzzer::proto::Scenario* scenario) { |
286 | 11.7k | const char* host; |
287 | 11.7k | switch (scenario->proxy_socket_option_mode()) { |
288 | 830 | case curl::fuzzer::proto::PROXY_SOCKET_OPTION_NOPROXY_HOSTNAME: |
289 | 830 | host = "service.proxy.test"; |
290 | 830 | break; |
291 | 3.50k | case curl::fuzzer::proto::PROXY_SOCKET_OPTION_NOPROXY_IPV4_CIDR: |
292 | 3.50k | host = "127.0.0.2"; |
293 | 3.50k | break; |
294 | 5.86k | case curl::fuzzer::proto::PROXY_SOCKET_OPTION_NOPROXY_IPV6_CIDR: |
295 | 5.86k | host = "[::1]"; |
296 | 5.86k | break; |
297 | 1.20k | case curl::fuzzer::proto::PROXY_SOCKET_OPTION_ENV_HTTP_PROXY: |
298 | 1.20k | host = "proxy-origin.test"; |
299 | 1.20k | break; |
300 | 318 | case curl::fuzzer::proto::PROXY_SOCKET_OPTION_LOOPBACK_INTERFACE_KEEPALIVE: |
301 | 318 | host = "resolve.test"; |
302 | 318 | break; |
303 | 0 | case curl::fuzzer::proto::PROXY_SOCKET_OPTION_DEFAULT: |
304 | 0 | default: |
305 | 0 | return; |
306 | 11.7k | } |
307 | | |
308 | 11.7k | const std::string& host_path = scenario->host_path(); |
309 | 11.7k | const std::size_t suffix_start = host_path.find_first_of("/?#"); |
310 | 11.7k | scenario->set_host_path(std::string(host) + |
311 | 11.7k | (suffix_start == std::string::npos ? "/" : host_path.substr(suffix_start))); |
312 | 11.7k | } |
313 | | |
314 | | /// Use libc/curl's localhost path when there are no structured entries, and a |
315 | | /// fixed cache-backed name when entries are present. The DoH lane uses the |
316 | | /// certificate's tls.test authority because its outer transfer completes a |
317 | | /// verified TLS/ALPN h2 handshake. In every case the path, query, and fragment |
318 | | /// remain mutation-controlled. |
319 | 20.9k | void CanonicalizeResolverAuthority(curl::fuzzer::proto::Scenario* scenario) { |
320 | 20.9k | const std::string& host_path = scenario->host_path(); |
321 | 20.9k | const std::size_t suffix_start = host_path.find_first_of("/?#"); |
322 | 20.9k | const char* host = "localhost"; |
323 | 20.9k | switch (scenario->resolver_mode()) { |
324 | 676 | case curl::fuzzer::proto::RESOLVER_MODE_THREADED_POSITIVE: |
325 | 676 | host = "resolver-positive.test"; |
326 | 676 | break; |
327 | 46 | case curl::fuzzer::proto::RESOLVER_MODE_THREADED_NEGATIVE: |
328 | 46 | host = "resolver-negative.test"; |
329 | 46 | break; |
330 | 416 | case curl::fuzzer::proto::RESOLVER_MODE_THREADED_LINK_LOCAL: |
331 | 416 | host = "resolver-link-local.test"; |
332 | 416 | break; |
333 | 946 | case curl::fuzzer::proto::RESOLVER_MODE_THREADED_PARTIAL: |
334 | 946 | host = "resolver-partial.test"; |
335 | 946 | break; |
336 | 522 | case curl::fuzzer::proto::RESOLVER_MODE_THREADED_QUEUED_CANCEL: |
337 | 522 | host = "resolver-queued-cancel.test"; |
338 | 522 | break; |
339 | 636 | case curl::fuzzer::proto::RESOLVER_MODE_UNIX_SOCKET: |
340 | 636 | host = "resolver-unix.test"; |
341 | 636 | break; |
342 | 1.52k | case curl::fuzzer::proto::RESOLVER_MODE_GLOBAL_LIFECYCLE: |
343 | 1.52k | host = "localhost"; |
344 | 1.52k | break; |
345 | 16.2k | case curl::fuzzer::proto::RESOLVER_MODE_DEFAULT: |
346 | 16.2k | default: |
347 | 16.2k | host = |
348 | 16.2k | scenario->has_doh() |
349 | 16.2k | ? "tls.test" |
350 | 16.2k | : ((scenario->happy_eyeballs() || !scenario->resolve_entries().empty()) ? "resolve.test" : "localhost"); |
351 | 16.2k | break; |
352 | 20.9k | } |
353 | 20.9k | if (suffix_start == std::string::npos) { |
354 | 514 | scenario->set_host_path(std::string(host) + "/"); |
355 | 514 | return; |
356 | 514 | } |
357 | 20.4k | scenario->set_host_path(std::string(host) + host_path.substr(suffix_start)); |
358 | 20.4k | } |
359 | | |
360 | 20.9k | bool IsThreadedResolverMode(curl::fuzzer::proto::ResolverMode mode) { |
361 | 20.9k | return mode == curl::fuzzer::proto::RESOLVER_MODE_THREADED_POSITIVE || |
362 | 20.3k | mode == curl::fuzzer::proto::RESOLVER_MODE_THREADED_NEGATIVE || |
363 | 20.2k | mode == curl::fuzzer::proto::RESOLVER_MODE_THREADED_LINK_LOCAL || |
364 | 19.8k | mode == curl::fuzzer::proto::RESOLVER_MODE_THREADED_PARTIAL || |
365 | 18.9k | mode == curl::fuzzer::proto::RESOLVER_MODE_THREADED_QUEUED_CANCEL; |
366 | 20.9k | } |
367 | | |
368 | | /// Give the TFTP lane a parseable filename-bearing URL while retaining the |
369 | | /// fuzz-controlled path, query, and fragment. The UDP peer rewrites curl's |
370 | | /// destination after URL parsing, so authority mutations cannot reach another |
371 | | /// host; canonicalizing them here avoids spending most iterations on failures |
372 | | /// before curl constructs a TFTP request. An explicit slash is preserved so |
373 | | /// the missing-filename error remains reachable. |
374 | 4.77k | void CanonicalizeTftpAuthority(curl::fuzzer::proto::Scenario* scenario) { |
375 | 4.77k | const std::string& host_path = scenario->host_path(); |
376 | 4.77k | const std::size_t suffix_start = host_path.find_first_of("/?#"); |
377 | 4.77k | if (suffix_start == std::string::npos) { |
378 | 392 | scenario->set_host_path("tftp.test/file"); |
379 | 392 | return; |
380 | 392 | } |
381 | 4.38k | scenario->set_host_path("tftp.test" + host_path.substr(suffix_start)); |
382 | 4.38k | } |
383 | | |
384 | | /// Keep the FTP lane inside the same parseable authority while leaving every |
385 | | /// path segment and wildcard under mutation control. CONNECT_TO already |
386 | | /// confines networking, but rejecting malformed authorities before USER/PWD |
387 | | /// would waste the control/data peer this target uniquely provides. |
388 | | /// Implicit-TLS inputs use the checked-in certificate's tls.test name so every |
389 | | /// control and data handshake can be verified before the same exchange runs. |
390 | 14.9k | void CanonicalizeFtpAuthority(curl::fuzzer::proto::Scenario* scenario) { |
391 | 14.9k | const std::string& host_path = scenario->host_path(); |
392 | 14.9k | const std::size_t suffix_start = host_path.find_first_of("/?#"); |
393 | 14.9k | const char* host = scenario->scheme() == curl::fuzzer::proto::SCHEME_FTPS ? "tls.test" : "ftp.test"; |
394 | 14.9k | if (suffix_start == std::string::npos) { |
395 | 409 | scenario->set_host_path(std::string(host) + "/file"); |
396 | 409 | return; |
397 | 409 | } |
398 | 14.5k | scenario->set_host_path(std::string(host) + host_path.substr(suffix_start)); |
399 | 14.5k | } |
400 | | |
401 | | /// Keep the SMTP lane inside a parseable authority while leaving the URL path |
402 | | /// mutation-controlled. In this curl revision the path is the EHLO argument |
403 | | /// (the client's announced domain), not the envelope recipient; recipients |
404 | | /// arrive through Scenario.mail_rcpt. Preserving the suffix still exercises |
405 | | /// EHLO parsing, while a fixed host avoids spending iterations on URL failures |
406 | | /// before curl sends its first command. Implicit-TLS inputs use the checked-in |
407 | | /// certificate's tls.test name so the verified handshake can complete before |
408 | | /// the same command exchange runs. |
409 | 12.0k | void CanonicalizeSmtpAuthority(curl::fuzzer::proto::Scenario* scenario) { |
410 | 12.0k | const std::string& host_path = scenario->host_path(); |
411 | 12.0k | const std::size_t suffix_start = host_path.find_first_of("/?#"); |
412 | 12.0k | const char* host = scenario->scheme() == curl::fuzzer::proto::SCHEME_SMTPS ? "tls.test" : "smtp.test"; |
413 | 12.0k | if (suffix_start == std::string::npos) { |
414 | 400 | scenario->set_host_path(std::string(host) + "/client.test"); |
415 | 400 | return; |
416 | 400 | } |
417 | 11.6k | scenario->set_host_path(std::string(host) + host_path.substr(suffix_start)); |
418 | 11.6k | } |
419 | | |
420 | | /// Keep the IMAP lane inside a parseable authority while retaining every URL |
421 | | /// path parameter, query, and fragment byte. The path carries the mailbox and |
422 | | /// the `;UID=`, `;MAILINDEX=`, `;SECTION=`, and `;PARTIAL=` selectors that |
423 | | /// choose FETCH, SEARCH, and LIST states; canonicalizing only the host avoids |
424 | | /// spending iterations on failures before curl sends its first command. |
425 | | /// Plaintext IMAP retains only an explicit port 80: OAuthBearer omits that |
426 | | /// default port from its generated message, covering a distinct stable branch |
427 | | /// without reopening arbitrary mutation-controlled ports. |
428 | | /// Implicit-TLS inputs use the checked-in certificate's tls.test name so the |
429 | | /// verified handshake can complete before the same tagged exchange runs. |
430 | 12.9k | void CanonicalizeImapAuthority(curl::fuzzer::proto::Scenario* scenario) { |
431 | 12.9k | const std::string& host_path = scenario->host_path(); |
432 | 12.9k | const std::size_t suffix_start = host_path.find_first_of("/?#"); |
433 | 12.9k | const char* host = scenario->scheme() == curl::fuzzer::proto::SCHEME_IMAPS ? "tls.test" : "imap.test"; |
434 | 12.9k | const std::size_t authority_end = suffix_start == std::string::npos ? host_path.size() : suffix_start; |
435 | 12.9k | const bool retain_default_port = scenario->scheme() == curl::fuzzer::proto::SCHEME_IMAP && authority_end >= 3 && |
436 | 3.94k | host_path.compare(authority_end - 3, 3, ":80") == 0; |
437 | 12.9k | const std::string authority = std::string(host) + (retain_default_port ? ":80" : ""); |
438 | 12.9k | if (suffix_start == std::string::npos) { |
439 | 366 | scenario->set_host_path(authority + "/INBOX"); |
440 | 366 | return; |
441 | 366 | } |
442 | 12.5k | scenario->set_host_path(authority + host_path.substr(suffix_start)); |
443 | 12.5k | } |
444 | | |
445 | | /// Give POP3 a mailbox with a message id by default so the lane reaches RETR |
446 | | /// rather than only LIST. The id remains mutation-controlled, and an explicit |
447 | | /// trailing slash or query continues to select the listing and error states. |
448 | | /// Implicit-TLS inputs use the checked-in certificate's tls.test name so the |
449 | | /// verified handshake can complete before the same status-line exchange runs. |
450 | 8.29k | void CanonicalizePop3Authority(curl::fuzzer::proto::Scenario* scenario) { |
451 | 8.29k | const std::string& host_path = scenario->host_path(); |
452 | 8.29k | const std::size_t suffix_start = host_path.find_first_of("/?#"); |
453 | 8.29k | const char* host = scenario->scheme() == curl::fuzzer::proto::SCHEME_POP3S ? "tls.test" : "pop3.test"; |
454 | 8.29k | if (suffix_start == std::string::npos) { |
455 | 358 | scenario->set_host_path(std::string(host) + "/1"); |
456 | 358 | return; |
457 | 358 | } |
458 | 7.93k | scenario->set_host_path(std::string(host) + host_path.substr(suffix_start)); |
459 | 7.93k | } |
460 | | |
461 | | /// Pin the MQTT broker authority while leaving the URL path mutation- |
462 | | /// controlled: curl percent-decodes that path into the PUBLISH/SUBSCRIBE topic. |
463 | | /// A missing path is a legitimate "No MQTT topic found" error, but a default |
464 | | /// topic makes most newly generated inputs reach the packet peer instead of |
465 | | /// stopping at URL validation. Implicit-TLS inputs use the checked-in |
466 | | /// certificate's tls.test name so the verified handshake can complete before |
467 | | /// the same packet exchange runs. |
468 | 8.42k | void CanonicalizeMqttAuthority(curl::fuzzer::proto::Scenario* scenario) { |
469 | 8.42k | const std::string& host_path = scenario->host_path(); |
470 | 8.42k | const std::size_t suffix_start = host_path.find_first_of("/?#"); |
471 | 8.42k | const char* host = scenario->scheme() == curl::fuzzer::proto::SCHEME_MQTTS ? "tls.test" : "mqtt.test"; |
472 | 8.42k | if (suffix_start == std::string::npos) { |
473 | 469 | scenario->set_host_path(std::string(host) + "/topic"); |
474 | 469 | return; |
475 | 469 | } |
476 | 7.95k | scenario->set_host_path(std::string(host) + host_path.substr(suffix_start)); |
477 | 7.95k | } |
478 | | |
479 | | /// Pin the DICT server authority while retaining every lookup selector in the |
480 | | /// URL path. In curl's DICT handler the path after the leading slash is the |
481 | | /// complete command: `/d:word`, `/match:word:db`, `/show:db`, or a raw command |
482 | | /// with colons becoming spaces. A default DEFINE keeps newly generated inputs |
483 | | /// reaching the command peer instead of stopping at URL validation, while an |
484 | | /// explicit path (including a bare `/`) continues to select the other states. |
485 | 6.07k | void CanonicalizeDictAuthority(curl::fuzzer::proto::Scenario* scenario) { |
486 | 6.07k | const std::string& host_path = scenario->host_path(); |
487 | 6.07k | const std::size_t suffix_start = host_path.find_first_of("/?#"); |
488 | 6.07k | if (suffix_start == std::string::npos) { |
489 | 272 | scenario->set_host_path("dict.test/d:word"); |
490 | 272 | return; |
491 | 272 | } |
492 | 5.80k | std::string canonical = "dict.test" + host_path.substr(suffix_start); |
493 | 5.80k | if (canonical.size() > scenario_limits::kMaxDictHostPathBytes) { |
494 | 32 | canonical.resize(scenario_limits::kMaxDictHostPathBytes); |
495 | 32 | } |
496 | 5.80k | scenario->set_host_path(canonical); |
497 | 5.80k | } |
498 | | |
499 | | /// Pin the LDAP directory authority while retaining the complete URL suffix. |
500 | | /// In this curl revision OpenLDAP parses the base DN, attributes, scope, and |
501 | | /// filter from the URL path (`/dn?attrs?scope?filter`); CURLOPT_CUSTOMREQUEST |
502 | | /// is not consulted. A default base DN makes newly generated inputs reach the |
503 | | /// bind/search peer, and dropping any userinfo component keeps OpenLDAP's |
504 | | /// strict URL parser from rejecting credentials it only accepts separately. |
505 | | /// Implicit-TLS inputs use the checked-in certificate's tls.test name so the |
506 | | /// verified handshake can complete before the same BER exchange runs. |
507 | 13.3k | void CanonicalizeLdapAuthority(curl::fuzzer::proto::Scenario* scenario) { |
508 | 13.3k | const std::string& host_path = scenario->host_path(); |
509 | 13.3k | const std::size_t suffix_start = host_path.find_first_of("/?#"); |
510 | 13.3k | const char* host = scenario->scheme() == curl::fuzzer::proto::SCHEME_LDAPS ? "tls.test" : "ldap.test"; |
511 | 13.3k | if (suffix_start == std::string::npos) { |
512 | 254 | scenario->set_host_path(std::string(host) + "/dc=example,dc=com"); |
513 | 254 | return; |
514 | 254 | } |
515 | 13.1k | scenario->set_host_path(std::string(host) + host_path.substr(suffix_start)); |
516 | 13.1k | } |
517 | | |
518 | | /// Pin the RTSP peer's authority while preserving the path, query, and |
519 | | /// fragment. curl builds its request stream URI from CURLOPT_RTSP_STREAM_URI |
520 | | /// (defaulting to "*"), but the URL still has to parse before the dedicated |
521 | | /// request/response peer can be reached. A default stream path keeps newly |
522 | | /// generated scenarios representative rather than spending them on URL errors. |
523 | 15.7k | void CanonicalizeRtspAuthority(curl::fuzzer::proto::Scenario* scenario) { |
524 | 15.7k | const std::string& host_path = scenario->host_path(); |
525 | 15.7k | const std::size_t suffix_start = host_path.find_first_of("/?#"); |
526 | 15.7k | if (suffix_start == std::string::npos) { |
527 | 256 | scenario->set_host_path("rtsp.test/stream"); |
528 | 256 | return; |
529 | 256 | } |
530 | 15.4k | scenario->set_host_path("rtsp.test" + host_path.substr(suffix_start)); |
531 | 15.4k | } |
532 | | |
533 | | /// Pin the IPFS/IPNS identifier while preserving the gateway path, query, and |
534 | | /// fragment. curl's command-line tool rewrites these schemes to an HTTP |
535 | | /// gateway request; the structured lane performs that same rewrite inside the |
536 | | /// runner, so the identifier has no local meaning beyond selecting the |
537 | | /// /ipfs/<cid> or /ipns/<name> namespace. A default identifier makes newly |
538 | | /// generated inputs reach the HTTP peer, while the bounded suffix retains the |
539 | | /// fuzz-controlled request target. |
540 | 24.2k | void CanonicalizeIpfsAuthority(curl::fuzzer::proto::Scenario* scenario) { |
541 | 24.2k | const std::string& host_path = scenario->host_path(); |
542 | 24.2k | const std::size_t suffix_start = host_path.find_first_of("/?#"); |
543 | 24.2k | std::string canonical = scenario->scheme() == curl::fuzzer::proto::SCHEME_IPNS ? kDefaultIpnsName : kDefaultIpfsCid; |
544 | 24.2k | if (suffix_start != std::string::npos) { |
545 | 2.00k | canonical += host_path.substr(suffix_start); |
546 | 2.00k | } |
547 | 24.2k | if (canonical.size() > scenario_limits::kMaxIpfsHostPathBytes) { |
548 | 1 | canonical.resize(scenario_limits::kMaxIpfsHostPathBytes); |
549 | 1 | } |
550 | 24.2k | scenario->set_host_path(canonical); |
551 | 24.2k | } |
552 | | |
553 | | /// Put every handle in the multi lane on one origin so connection limits, |
554 | | /// queueing, and reuse affect real transfers instead of independent hosts. |
555 | | /// Path/query/fragment bytes remain mutation-controlled. |
556 | 36.4k | void CanonicalizeMultiAuthority(curl::fuzzer::proto::Scenario* scenario) { |
557 | 36.4k | const std::string& host_path = scenario->host_path(); |
558 | 36.4k | const std::size_t suffix_start = host_path.find_first_of("/?#"); |
559 | 36.4k | if (suffix_start == std::string::npos) { |
560 | 768 | scenario->set_host_path("multi.test/"); |
561 | 768 | return; |
562 | 768 | } |
563 | 35.6k | scenario->set_host_path("multi.test" + host_path.substr(suffix_start)); |
564 | 35.6k | } |
565 | | |
566 | | template <typename RepeatedBytes> |
567 | 2.22M | void BoundStringValues(RepeatedBytes* values, std::size_t count_limit, std::size_t value_limit) { |
568 | 2.22M | TrimRepeated(values, count_limit); |
569 | 2.22M | for (std::string& value : *values) { |
570 | 571k | if (value.size() > value_limit) { |
571 | 129 | value.resize(value_limit); |
572 | 129 | } |
573 | 571k | } |
574 | 2.22M | } |
575 | | |
576 | | template <typename RepeatedBytes> |
577 | 955k | void BoundHeaderValues(RepeatedBytes* headers, std::size_t limit) { |
578 | 955k | BoundStringValues(headers, limit, scenario_limits::kMaxMetadataBytes); |
579 | 955k | } |
580 | | |
581 | | /// Keep one response script identical to the prefix MockServer and |
582 | | /// WebSocketMockServer can deliver. Raw chunks take precedence over structured |
583 | | /// frames, matching both runtime serializers. |
584 | 750k | void BoundConnectionShape(curl::fuzzer::proto::Connection* connection) { |
585 | 750k | TrimRepeated(connection->mutable_on_readable(), scenario_limits::kMaxResponseChunks); |
586 | 750k | const std::size_t raw_count = static_cast<std::size_t>(connection->on_readable_size()); |
587 | 750k | TrimRepeated(connection->mutable_server_frames(), scenario_limits::kMaxResponseChunks - raw_count); |
588 | 750k | } |
589 | | |
590 | | /// Retain the observable prefix of one filename-backed parser input while |
591 | | /// debiting the shared per-scenario file-byte budget. |
592 | 3.11M | void BoundFileInput(std::string* input, std::size_t* remaining_bytes) { |
593 | 3.11M | const std::size_t limit = std::min(scenario_limits::kMaxFileInputBytes, *remaining_bytes); |
594 | 3.11M | if (input->size() > limit) { |
595 | 0 | input->resize(limit); |
596 | 0 | } |
597 | 3.11M | *remaining_bytes -= input->size(); |
598 | 3.11M | } |
599 | | |
600 | 623k | void BoundFileInputs(curl::fuzzer::proto::Scenario* scenario) { |
601 | 623k | std::size_t remaining_bytes = scenario_limits::kMaxFileInputTotalBytes; |
602 | 623k | BoundFileInput(scenario->mutable_cookie_file(), &remaining_bytes); |
603 | 623k | BoundFileInput(scenario->mutable_altsvc_file(), &remaining_bytes); |
604 | 623k | BoundFileInput(scenario->mutable_hsts_file(), &remaining_bytes); |
605 | 623k | BoundFileInput(scenario->mutable_netrc_file(), &remaining_bytes); |
606 | 623k | BoundFileInput(scenario->mutable_crl_file(), &remaining_bytes); |
607 | 623k | } |
608 | | |
609 | | /// Apply the metadata/header limits shared by both MIME part message types. |
610 | | template <typename Part> |
611 | 332k | void BoundMimePartMetadata(Part* part) { |
612 | 332k | TrimMetadata(part->mutable_name()); |
613 | 332k | TrimMetadata(part->mutable_filename()); |
614 | 332k | TrimMetadata(part->mutable_content_type()); |
615 | 332k | BoundHeaderValues(part->mutable_headers(), scenario_limits::kMaxMimeHeadersPerPart); |
616 | 332k | } target_policy.cc:void proto_fuzzer::(anonymous namespace)::BoundMimePartMetadata<curl::fuzzer::proto::MimePart>(curl::fuzzer::proto::MimePart*) Line | Count | Source | 611 | 197k | void BoundMimePartMetadata(Part* part) { | 612 | 197k | TrimMetadata(part->mutable_name()); | 613 | 197k | TrimMetadata(part->mutable_filename()); | 614 | 197k | TrimMetadata(part->mutable_content_type()); | 615 | 197k | BoundHeaderValues(part->mutable_headers(), scenario_limits::kMaxMimeHeadersPerPart); | 616 | 197k | } |
target_policy.cc:void proto_fuzzer::(anonymous namespace)::BoundMimePartMetadata<curl::fuzzer::proto::MimeDataPart>(curl::fuzzer::proto::MimeDataPart*) Line | Count | Source | 611 | 134k | void BoundMimePartMetadata(Part* part) { | 612 | 134k | TrimMetadata(part->mutable_name()); | 613 | 134k | TrimMetadata(part->mutable_filename()); | 614 | 134k | TrimMetadata(part->mutable_content_type()); | 615 | 134k | BoundHeaderValues(part->mutable_headers(), scenario_limits::kMaxMimeHeadersPerPart); | 616 | 134k | } |
|
617 | | |
618 | 49.6k | void BoundGeneratedMimeData(curl::fuzzer::proto::GeneratedBytes* generated, std::size_t* remaining_bytes) { |
619 | 49.6k | if (generated->pattern().size() > scenario_limits::kMaxGeneratedMimePatternBytes) { |
620 | 44 | generated->mutable_pattern()->resize(scenario_limits::kMaxGeneratedMimePatternBytes); |
621 | 44 | } |
622 | | |
623 | 49.6k | const std::size_t pattern_size = generated->pattern().size(); |
624 | 49.6k | if (pattern_size == 0 || *remaining_bytes == 0) { |
625 | 18.4k | generated->clear_repeat_count(); |
626 | 18.4k | return; |
627 | 18.4k | } |
628 | | |
629 | | // Keep every exact in-range size, including 16/32/64 KiB and their +/-1 |
630 | | // neighborhoods. Counts beyond the shared budget all have identical runtime |
631 | | // behavior, so fold them onto the largest observable repetition count. |
632 | 31.1k | const std::size_t max_repeat_count = *remaining_bytes / pattern_size; |
633 | 31.1k | const std::size_t repeat_count = |
634 | 31.1k | std::min<std::size_t>(static_cast<std::size_t>(generated->repeat_count()), max_repeat_count); |
635 | 31.1k | generated->set_repeat_count(static_cast<std::uint32_t>(repeat_count)); |
636 | 31.1k | *remaining_bytes -= repeat_count * pattern_size; |
637 | 31.1k | } |
638 | | |
639 | 134k | void BoundMimeLeaf(curl::fuzzer::proto::MimeDataPart* part, std::size_t* remaining_generated_bytes) { |
640 | 134k | BoundMimePartMetadata(part); |
641 | 134k | if (part->content_case() == curl::fuzzer::proto::MimeDataPart::kGeneratedData) { |
642 | 23.9k | BoundGeneratedMimeData(part->mutable_generated_data(), remaining_generated_bytes); |
643 | 111k | } else if (part->data().size() > scenario_limits::kMaxMimeDataBytes) { |
644 | 2 | part->mutable_data()->resize(scenario_limits::kMaxMimeDataBytes); |
645 | 2 | } |
646 | 134k | } |
647 | | |
648 | | /// Mirror the runtime's shared top-level/nested part budget in the protobuf |
649 | | /// itself. A simple per-list cap is insufficient because many bounded child |
650 | | /// lists could still leave most of the message semantically dead. |
651 | 106k | void BoundMimeShape(curl::fuzzer::proto::MimePost* post) { |
652 | 106k | TrimRepeated(post->mutable_parts(), scenario_limits::kMaxTopLevelMimeParts); |
653 | 106k | std::size_t remaining = scenario_limits::kMaxTotalMimeParts; |
654 | 106k | std::size_t remaining_generated_bytes = scenario_limits::kMaxGeneratedMimeDataBytes; |
655 | 106k | std::size_t retained_top_parts = 0; |
656 | | |
657 | 303k | while (retained_top_parts < static_cast<std::size_t>(post->parts_size()) && remaining != 0) { |
658 | 197k | auto* part = post->mutable_parts(static_cast<int>(retained_top_parts)); |
659 | 197k | ++retained_top_parts; |
660 | 197k | --remaining; |
661 | 197k | BoundMimePartMetadata(part); |
662 | | |
663 | 197k | if (part->content_case() == curl::fuzzer::proto::MimePart::kData) { |
664 | 12.4k | if (part->data().size() > scenario_limits::kMaxMimeDataBytes) { |
665 | 3 | part->mutable_data()->resize(scenario_limits::kMaxMimeDataBytes); |
666 | 3 | } |
667 | 12.4k | continue; |
668 | 12.4k | } |
669 | 184k | if (part->content_case() == curl::fuzzer::proto::MimePart::kGeneratedData) { |
670 | 25.7k | BoundGeneratedMimeData(part->mutable_generated_data(), &remaining_generated_bytes); |
671 | 25.7k | continue; |
672 | 25.7k | } |
673 | 158k | if (part->content_case() != curl::fuzzer::proto::MimePart::kSubparts) { |
674 | 91.9k | continue; |
675 | 91.9k | } |
676 | | |
677 | 66.9k | auto* children = part->mutable_subparts()->mutable_parts(); |
678 | 66.9k | TrimRepeated(children, std::min(scenario_limits::kMaxNestedMimeParts, remaining)); |
679 | 134k | for (auto& child : *children) { |
680 | 134k | BoundMimeLeaf(&child, &remaining_generated_bytes); |
681 | 134k | --remaining; |
682 | 134k | } |
683 | 66.9k | } |
684 | | |
685 | 106k | TrimRepeated(post->mutable_parts(), retained_top_parts); |
686 | 106k | } |
687 | | |
688 | | /// Remove upload bytes and read steps the callback cannot observe. Clamping |
689 | | /// individual limits also keeps mutations concentrated on short reads instead |
690 | | /// of many distinct uint32 values that all collapse to the same 16 KiB cap. |
691 | | void BoundUploadShape(curl::fuzzer::proto::UploadScript* upload, std::size_t data_limit, std::size_t read_step_limit, |
692 | 66.3k | std::size_t read_size_limit) { |
693 | 66.3k | if (upload->data().size() > data_limit) { |
694 | 11 | upload->mutable_data()->resize(data_limit); |
695 | 11 | } |
696 | | // RepeatedField<uint32_t> lacks RepeatedPtrField's DeleteSubrange helper; |
697 | | // removing the ignored suffix from the end is constant-time per element and |
698 | | // preserves the mutation-significant prefix exactly. |
699 | 159k | while (static_cast<std::size_t>(upload->read_sizes_size()) > read_step_limit) { |
700 | 92.6k | upload->mutable_read_sizes()->RemoveLast(); |
701 | 92.6k | } |
702 | 181k | for (int i = 0; i < upload->read_sizes_size(); ++i) { |
703 | 115k | if (upload->read_sizes(i) > read_size_limit) { |
704 | 1.27k | upload->set_read_sizes(i, static_cast<std::uint32_t>(read_size_limit)); |
705 | 1.27k | } |
706 | 115k | } |
707 | 66.3k | } |
708 | | |
709 | | /// Trim a protobuf repeated scalar without depending on the container's |
710 | | /// pointer-field-only DeleteSubrange API. Keeping the mutation-significant |
711 | | /// prefix matches every runtime selector loop. |
712 | | template <typename RepeatedScalar> |
713 | 47.8k | void TrimRepeatedScalar(RepeatedScalar* values, std::size_t limit) { |
714 | 51.6k | while (static_cast<std::size_t>(values->size()) > limit) { |
715 | 3.86k | values->RemoveLast(); |
716 | 3.86k | } |
717 | 47.8k | } |
718 | | |
719 | | /// Canonicalize the allocation failure plan to the same fixed-size sequence |
720 | | /// consumed by the runtime controller. Sorting lets its hot callback compare |
721 | | /// only the next ordinal, while retaining the lowest distinct values keeps |
722 | | /// an oversized mutation focused on reachable work. |
723 | 956k | void CanonicalizeAllocationFailures(curl::fuzzer::proto::Scenario* scenario) { |
724 | 956k | std::array<std::uint32_t, scenario_limits::kMaxAllocationFailures> retained{}; |
725 | 956k | std::size_t retained_count = 0; |
726 | 956k | const std::uint32_t maximum = static_cast<std::uint32_t>(scenario_limits::kMaxAllocationOrdinal); |
727 | | |
728 | 1.16M | for (const std::uint32_t raw : scenario->fail_allocations()) { |
729 | 1.16M | if (raw == 0) { |
730 | 110k | continue; |
731 | 110k | } |
732 | 1.05M | const std::uint32_t ordinal = 1U + ((raw - 1U) % maximum); |
733 | 1.05M | const auto begin = retained.begin(); |
734 | 1.05M | const auto end = begin + static_cast<std::ptrdiff_t>(retained_count); |
735 | 1.05M | const auto position = std::lower_bound(begin, end, ordinal); |
736 | 1.05M | if (position != end && *position == ordinal) { |
737 | 297k | continue; |
738 | 297k | } |
739 | 756k | const std::size_t index = static_cast<std::size_t>(position - begin); |
740 | 756k | if (index >= retained.size()) { |
741 | 489k | continue; |
742 | 489k | } |
743 | 266k | if (retained_count < retained.size()) { |
744 | 260k | ++retained_count; |
745 | 260k | } |
746 | 284k | for (std::size_t destination = retained_count - 1; destination > index; --destination) { |
747 | 17.4k | retained[destination] = retained[destination - 1]; |
748 | 17.4k | } |
749 | 266k | retained[index] = ordinal; |
750 | 266k | } |
751 | | |
752 | 956k | auto* values = scenario->mutable_fail_allocations(); |
753 | 956k | values->Clear(); |
754 | 1.21M | for (std::size_t index = 0; index < retained_count; ++index) { |
755 | 260k | values->Add(retained[index]); |
756 | 260k | } |
757 | 956k | } |
758 | | |
759 | | /// Keep injected failures out of curl's debug event adapter. Its socket |
760 | | /// monitor is heap-backed, and rejecting the allocation that records a newly |
761 | | /// announced socket leaves a later CURL_POLL_REMOVE with no matching entry. |
762 | | /// Ordinary inputs still cover curl_easy_perform_ev; allocation plans use the |
763 | | /// equivalent blocking easy entrypoint and retain a stable allocation trace. |
764 | 956k | void CanonicalizeAllocationFailureDrive(curl::fuzzer::proto::Scenario* scenario) { |
765 | 956k | if (!scenario->fail_allocations().empty() && scenario->has_api_plan() && |
766 | 6.63k | scenario->api_plan().drive_mode() == curl::fuzzer::proto::API_DRIVE_EASY_EVENTS) { |
767 | 30 | scenario->mutable_api_plan()->set_drive_mode(curl::fuzzer::proto::API_DRIVE_EASY_PERFORM); |
768 | 30 | } |
769 | 956k | } |
770 | | |
771 | | /// Fold an unknown API drive selector to the ordinary multi-perform path |
772 | | /// before generated guards decide whether multi-only fields are eligible. |
773 | 31.8k | void CanonicalizeApiDriveMode(curl::fuzzer::proto::ApiPlan* plan) { |
774 | 31.8k | switch (plan->drive_mode()) { |
775 | 21.2k | case curl::fuzzer::proto::API_DRIVE_MULTI_PERFORM: |
776 | 24.1k | case curl::fuzzer::proto::API_DRIVE_MULTI_SOCKET: |
777 | 29.5k | case curl::fuzzer::proto::API_DRIVE_EASY_PERFORM: |
778 | 30.7k | case curl::fuzzer::proto::API_DRIVE_EASY_EVENTS: |
779 | 31.8k | case curl::fuzzer::proto::API_DRIVE_CONNECT_ONLY: |
780 | 31.8k | return; |
781 | 3 | default: |
782 | 3 | plan->set_drive_mode(curl::fuzzer::proto::API_DRIVE_MULTI_PERFORM); |
783 | 3 | return; |
784 | 31.8k | } |
785 | 31.8k | } |
786 | | |
787 | | /// Keep API work proportional to the fixed descriptor tables used by the |
788 | | /// runtime. Selector magnitudes stay mutation-controlled because the runtime |
789 | | /// folds them into the relevant typed table; only suffixes it cannot execute |
790 | | /// are dead and therefore removed here. |
791 | 15.9k | void BoundApiPlanShape(curl::fuzzer::proto::ApiPlan* plan) { |
792 | 15.9k | TrimRepeatedScalar(plan->mutable_share_data_selectors(), scenario_limits::kMaxApiShareDataSelectors); |
793 | 15.9k | TrimRepeatedScalar(plan->mutable_easy_info_selectors(), scenario_limits::kMaxApiInfoSelectors); |
794 | 15.9k | TrimRepeatedScalar(plan->mutable_reentrant_probe_selectors(), scenario_limits::kMaxApiReentrantSelectors); |
795 | | |
796 | 15.9k | CanonicalizeApiDriveMode(plan); |
797 | 15.9k | switch (plan->drive_mode()) { |
798 | 10.6k | case curl::fuzzer::proto::API_DRIVE_MULTI_PERFORM: |
799 | 12.0k | case curl::fuzzer::proto::API_DRIVE_MULTI_SOCKET: |
800 | 12.0k | break; |
801 | 2.70k | case curl::fuzzer::proto::API_DRIVE_EASY_PERFORM: |
802 | 3.27k | case curl::fuzzer::proto::API_DRIVE_EASY_EVENTS: |
803 | 3.85k | case curl::fuzzer::proto::API_DRIVE_CONNECT_ONLY: |
804 | | // Wakeup is a multi-handle API and has no live object in easy mode. |
805 | | // Likewise, a body callback cannot be resumed while one of these |
806 | | // blocking entrypoints owns the thread. Clearing both mutations keeps |
807 | | // every retained API-plan value observable and bounded. |
808 | 3.85k | plan->set_wake_multi(false); |
809 | 3.85k | plan->set_pause_response_once(false); |
810 | 3.85k | break; |
811 | 0 | default: |
812 | 0 | break; |
813 | 15.9k | } |
814 | 15.9k | } |
815 | | |
816 | | /// Retain the same-easy MIME repeat only when its callback cursor and MIME |
817 | | /// consumer both exist. Pinning this closed probe to the ordinary multi loop |
818 | | /// avoids combining a second perform with connect-only or paused-response |
819 | | /// lifecycles whose state cannot be meaningfully reused. |
820 | 15.9k | void CanonicalizeApiMimeRepeat(curl::fuzzer::proto::Scenario* scenario) { |
821 | 15.9k | if (!scenario->has_api_plan() || !scenario->api_plan().repeat_mime_post()) { |
822 | 13.8k | return; |
823 | 13.8k | } |
824 | | |
825 | 2.06k | bool has_callback_part = false; |
826 | 2.06k | if (scenario->has_mime_post()) { |
827 | 2.98k | for (const auto& part : scenario->mime_post().parts()) { |
828 | 2.98k | if (part.content_case() == curl::fuzzer::proto::MimePart::kUploadCallback) { |
829 | 2.06k | has_callback_part = true; |
830 | 2.06k | break; |
831 | 2.06k | } |
832 | 2.98k | } |
833 | 2.06k | } |
834 | 2.06k | if (!scenario->has_upload() || !has_callback_part) { |
835 | 1 | scenario->mutable_api_plan()->clear_repeat_mime_post(); |
836 | 1 | return; |
837 | 1 | } |
838 | | |
839 | 2.06k | auto* plan = scenario->mutable_api_plan(); |
840 | 2.06k | plan->set_drive_mode(curl::fuzzer::proto::API_DRIVE_MULTI_PERFORM); |
841 | 2.06k | plan->set_wake_multi(false); |
842 | 2.06k | plan->set_pause_response_once(false); |
843 | 2.06k | } |
844 | | |
845 | | /// Keep concurrent-handle work within the mock's fixed socket and operation |
846 | | /// budgets. Values are canonicalized here rather than only at runtime so LPM |
847 | | /// mutates state that the target can actually distinguish. |
848 | 36.4k | void BoundMultiPlanShape(curl::fuzzer::proto::MultiPlan* plan) { |
849 | 36.4k | const std::uint32_t minimum = static_cast<std::uint32_t>(scenario_limits::kMinMultiTransfers); |
850 | 36.4k | const std::uint32_t maximum = static_cast<std::uint32_t>(scenario_limits::kMaxMultiTransfers); |
851 | 36.4k | const std::uint32_t transfer_count = std::max(minimum, std::min(plan->transfer_count(), maximum)); |
852 | 36.4k | plan->set_transfer_count(transfer_count); |
853 | 36.4k | plan->set_max_host_connections(std::min(plan->max_host_connections(), transfer_count)); |
854 | 36.4k | plan->set_max_total_connections(std::min(plan->max_total_connections(), transfer_count)); |
855 | 36.4k | plan->set_connection_cache_size(std::min(plan->connection_cache_size(), maximum * 2U)); |
856 | 36.4k | TrimRepeated(plan->mutable_actions(), scenario_limits::kMaxMultiActions); |
857 | | |
858 | 36.4k | switch (plan->drive_mode()) { |
859 | 30.3k | case curl::fuzzer::proto::MULTI_DRIVE_PERFORM: |
860 | 36.3k | case curl::fuzzer::proto::MULTI_DRIVE_SOCKET: |
861 | 36.3k | break; |
862 | 19 | default: |
863 | 19 | plan->set_drive_mode(curl::fuzzer::proto::MULTI_DRIVE_PERFORM); |
864 | 19 | break; |
865 | 36.4k | } |
866 | | |
867 | 36.4k | switch (plan->state_probe_profile()) { |
868 | 31.9k | case curl::fuzzer::proto::MULTI_STATE_PROBE_NONE: |
869 | 36.4k | case curl::fuzzer::proto::MULTI_STATE_PROBE_PROGRESS_RATE_LIMIT: |
870 | 36.4k | break; |
871 | 14 | default: |
872 | 14 | plan->set_state_probe_profile(curl::fuzzer::proto::MULTI_STATE_PROBE_NONE); |
873 | 14 | break; |
874 | 36.4k | } |
875 | | |
876 | 62.6k | for (auto& action : *plan->mutable_actions()) { |
877 | 62.6k | action.set_transfer_selector(action.transfer_selector() % transfer_count); |
878 | 62.6k | switch (action.kind()) { |
879 | 13.8k | case curl::fuzzer::proto::MULTI_ACTION_NONE: |
880 | 17.6k | case curl::fuzzer::proto::MULTI_ACTION_PAUSE_RECV: |
881 | 20.7k | case curl::fuzzer::proto::MULTI_ACTION_PAUSE_SEND: |
882 | 23.1k | case curl::fuzzer::proto::MULTI_ACTION_PAUSE_ALL: |
883 | 25.0k | case curl::fuzzer::proto::MULTI_ACTION_RESUME: |
884 | 43.6k | case curl::fuzzer::proto::MULTI_ACTION_REMOVE: |
885 | 62.5k | case curl::fuzzer::proto::MULTI_ACTION_READD: |
886 | 62.5k | break; |
887 | 40 | default: |
888 | 40 | action.set_kind(curl::fuzzer::proto::MULTI_ACTION_NONE); |
889 | 40 | break; |
890 | 62.6k | } |
891 | 62.6k | } |
892 | 36.4k | } |
893 | | |
894 | | /// HTTP field names are lowercase RFC token bytes in the structured lane. |
895 | | /// Replacing (rather than deleting) invalid bytes retains mutation-significant |
896 | | /// positions while preventing accidental pseudo-headers and encoder failures. |
897 | 123k | void CanonicalizeHttp3HeaderName(std::string* name) { |
898 | 123k | if (name->size() > scenario_limits::kMaxHttp3HeaderNameBytes) { |
899 | 36 | name->resize(scenario_limits::kMaxHttp3HeaderNameBytes); |
900 | 36 | } |
901 | 123k | if (name->empty()) { |
902 | 750 | *name = "x-fuzz"; |
903 | 750 | return; |
904 | 750 | } |
905 | | |
906 | 1.10M | for (char& byte : *name) { |
907 | 1.10M | const unsigned char value = static_cast<unsigned char>(byte); |
908 | 1.10M | const bool alpha = (value >= 'A' && value <= 'Z') || (value >= 'a' && value <= 'z'); |
909 | 1.10M | const bool digit = value >= '0' && value <= '9'; |
910 | 1.10M | const bool punctuation = value == '!' || value == '#' || value == '$' || value == '%' || value == '&' || |
911 | 1.07M | value == '\'' || value == '*' || value == '+' || value == '-' || value == '.' || |
912 | 654k | value == '^' || value == '_' || value == '`' || value == '|' || value == '~'; |
913 | 1.10M | if (value >= 'A' && value <= 'Z') { |
914 | 1.11k | byte = static_cast<char>(value - 'A' + 'a'); |
915 | 1.09M | } else if (!alpha && !digit && !punctuation) { |
916 | 3.48k | byte = '-'; |
917 | 3.48k | } |
918 | 1.10M | } |
919 | 123k | } |
920 | | |
921 | | /// Structured field values must not inject another HTTP field or carry NUL |
922 | | /// into the encoder. Observable malformed bytes remain available in raw stream |
923 | | /// actions, while this path stays suitable for valid QPACK generation. |
924 | 123k | void CanonicalizeHttp3HeaderValue(std::string* value) { |
925 | 123k | if (value->size() > scenario_limits::kMaxHttp3HeaderValueBytes) { |
926 | 0 | value->resize(scenario_limits::kMaxHttp3HeaderValueBytes); |
927 | 0 | } |
928 | 10.0M | for (char& byte : *value) { |
929 | 10.0M | const unsigned char character = static_cast<unsigned char>(byte); |
930 | 10.0M | if ((character < 0x20U && character != '\t') || character == 0x7fU) { |
931 | 7.31k | byte = ' '; |
932 | 7.31k | } |
933 | 10.0M | } |
934 | 123k | } |
935 | | |
936 | | /// Retain only a prefix of encodable fields within both a count and a shared |
937 | | /// byte budget. A missing name is materialized as x-fuzz while budget remains, |
938 | | /// making default-initialized structured headers useful to the peer. |
939 | | template <typename RepeatedHeaders> |
940 | 97.9k | void BoundHttp3Headers(RepeatedHeaders* headers, std::size_t count_limit, std::size_t* remaining_bytes) { |
941 | 97.9k | TrimRepeated(headers, count_limit); |
942 | 97.9k | std::size_t retained = 0; |
943 | 221k | while (retained < static_cast<std::size_t>(headers->size()) && *remaining_bytes != 0) { |
944 | 123k | auto* header = headers->Mutable(static_cast<int>(retained)); |
945 | 123k | CanonicalizeHttp3HeaderName(header->mutable_name()); |
946 | 123k | CanonicalizeHttp3HeaderValue(header->mutable_value()); |
947 | | |
948 | 123k | if (header->name().size() > *remaining_bytes) { |
949 | 3 | header->mutable_name()->resize(*remaining_bytes); |
950 | 3 | header->clear_value(); |
951 | 123k | } else if (header->value().size() > *remaining_bytes - header->name().size()) { |
952 | 7 | header->mutable_value()->resize(*remaining_bytes - header->name().size()); |
953 | 7 | } |
954 | 123k | *remaining_bytes -= header->name().size() + header->value().size(); |
955 | 123k | ++retained; |
956 | 123k | } |
957 | 97.9k | TrimRepeated(headers, retained); |
958 | 97.9k | } target_policy.cc:void proto_fuzzer::(anonymous namespace)::BoundHttp3Headers<google::protobuf::RepeatedPtrField<curl::fuzzer::proto::Http3Header> >(google::protobuf::RepeatedPtrField<curl::fuzzer::proto::Http3Header>*, unsigned long, unsigned long*) Line | Count | Source | 940 | 6.60k | void BoundHttp3Headers(RepeatedHeaders* headers, std::size_t count_limit, std::size_t* remaining_bytes) { | 941 | 6.60k | TrimRepeated(headers, count_limit); | 942 | 6.60k | std::size_t retained = 0; | 943 | 10.7k | while (retained < static_cast<std::size_t>(headers->size()) && *remaining_bytes != 0) { | 944 | 4.13k | auto* header = headers->Mutable(static_cast<int>(retained)); | 945 | 4.13k | CanonicalizeHttp3HeaderName(header->mutable_name()); | 946 | 4.13k | CanonicalizeHttp3HeaderValue(header->mutable_value()); | 947 | | | 948 | 4.13k | if (header->name().size() > *remaining_bytes) { | 949 | 1 | header->mutable_name()->resize(*remaining_bytes); | 950 | 1 | header->clear_value(); | 951 | 4.13k | } else if (header->value().size() > *remaining_bytes - header->name().size()) { | 952 | 3 | header->mutable_value()->resize(*remaining_bytes - header->name().size()); | 953 | 3 | } | 954 | 4.13k | *remaining_bytes -= header->name().size() + header->value().size(); | 955 | 4.13k | ++retained; | 956 | 4.13k | } | 957 | 6.60k | TrimRepeated(headers, retained); | 958 | 6.60k | } |
target_policy.cc:void proto_fuzzer::(anonymous namespace)::BoundHttp3Headers<google::protobuf::RepeatedPtrField<curl::fuzzer::proto::Http2Header> >(google::protobuf::RepeatedPtrField<curl::fuzzer::proto::Http2Header>*, unsigned long, unsigned long*) Line | Count | Source | 940 | 91.3k | void BoundHttp3Headers(RepeatedHeaders* headers, std::size_t count_limit, std::size_t* remaining_bytes) { | 941 | 91.3k | TrimRepeated(headers, count_limit); | 942 | 91.3k | std::size_t retained = 0; | 943 | 211k | while (retained < static_cast<std::size_t>(headers->size()) && *remaining_bytes != 0) { | 944 | 119k | auto* header = headers->Mutable(static_cast<int>(retained)); | 945 | 119k | CanonicalizeHttp3HeaderName(header->mutable_name()); | 946 | 119k | CanonicalizeHttp3HeaderValue(header->mutable_value()); | 947 | | | 948 | 119k | if (header->name().size() > *remaining_bytes) { | 949 | 2 | header->mutable_name()->resize(*remaining_bytes); | 950 | 2 | header->clear_value(); | 951 | 119k | } else if (header->value().size() > *remaining_bytes - header->name().size()) { | 952 | 4 | header->mutable_value()->resize(*remaining_bytes - header->name().size()); | 953 | 4 | } | 954 | 119k | *remaining_bytes -= header->name().size() + header->value().size(); | 955 | 119k | ++retained; | 956 | 119k | } | 957 | 91.3k | TrimRepeated(headers, retained); | 958 | 91.3k | } |
|
959 | | |
960 | 2.25k | void CanonicalizeHttp3StreamRole(curl::fuzzer::proto::Http3StreamRole* role) { |
961 | 2.25k | switch (*role) { |
962 | 2.06k | case curl::fuzzer::proto::HTTP3_STREAM_RESPONSE: |
963 | 2.11k | case curl::fuzzer::proto::HTTP3_STREAM_CONTROL: |
964 | 2.15k | case curl::fuzzer::proto::HTTP3_STREAM_QPACK_ENCODER: |
965 | 2.17k | case curl::fuzzer::proto::HTTP3_STREAM_QPACK_DECODER: |
966 | 2.17k | return; |
967 | 86 | default: |
968 | 86 | *role = curl::fuzzer::proto::HTTP3_STREAM_RESPONSE; |
969 | 86 | return; |
970 | 2.25k | } |
971 | 2.25k | } |
972 | | |
973 | 2.32k | void BoundHttp3RawData(std::string* data, std::size_t* remaining_raw_bytes) { |
974 | 2.32k | const std::size_t limit = std::min(scenario_limits::kMaxHttp3RawWriteBytes, *remaining_raw_bytes); |
975 | 2.32k | if (data->size() > limit) { |
976 | 10 | data->resize(limit); |
977 | 10 | } |
978 | 2.32k | *remaining_raw_bytes -= data->size(); |
979 | 2.32k | } |
980 | | |
981 | 147k | void BoundHttp2StreamRef(curl::fuzzer::proto::Http2StreamRef* stream) { |
982 | 147k | switch (stream->target_case()) { |
983 | 6.63k | case curl::fuzzer::proto::Http2StreamRef::kRequestIndex: |
984 | 6.63k | stream->set_request_index(stream->request_index() % 16U); |
985 | 6.63k | break; |
986 | 5.17k | case curl::fuzzer::proto::Http2StreamRef::kPushIndex: |
987 | 5.17k | stream->set_push_index(stream->push_index() % 16U); |
988 | 5.17k | break; |
989 | 5.40k | case curl::fuzzer::proto::Http2StreamRef::kExplicitId: |
990 | 5.40k | stream->set_explicit_id(stream->explicit_id() & 0x7fffffffU); |
991 | 5.40k | break; |
992 | 4.83k | case curl::fuzzer::proto::Http2StreamRef::kConnection: |
993 | 8.37k | case curl::fuzzer::proto::Http2StreamRef::kLatestRequest: |
994 | 130k | case curl::fuzzer::proto::Http2StreamRef::TARGET_NOT_SET: |
995 | 130k | default: |
996 | 130k | break; |
997 | 147k | } |
998 | 147k | } |
999 | | |
1000 | 53.5k | void BoundHttp2Settings(curl::fuzzer::proto::Http2Settings* settings) { |
1001 | 53.5k | TrimRepeated(settings->mutable_entries(), scenario_limits::kMaxHttp2Settings); |
1002 | 53.5k | for (auto& entry : *settings->mutable_entries()) { |
1003 | | // SETTINGS identifiers occupy 16 bits. Preserve unknown extensions, |
1004 | | // which receivers ignore when they do not understand them. |
1005 | 32.0k | entry.set_identifier(entry.identifier() & 0xffffU); |
1006 | 32.0k | switch (entry.identifier()) { |
1007 | 2.79k | case 2U: // SETTINGS_ENABLE_PUSH |
1008 | 3.35k | case 8U: // SETTINGS_ENABLE_CONNECT_PROTOCOL |
1009 | 3.78k | case 9U: // SETTINGS_NO_RFC7540_PRIORITIES |
1010 | 3.78k | entry.set_value(entry.value() & 1U); |
1011 | 3.78k | break; |
1012 | 6.18k | case 4U: // SETTINGS_INITIAL_WINDOW_SIZE |
1013 | 6.18k | entry.set_value(entry.value() & 0x7fffffffU); |
1014 | 6.18k | break; |
1015 | 2.21k | case 5U: // SETTINGS_MAX_FRAME_SIZE |
1016 | 2.21k | if (entry.value() < 16384U || entry.value() > 0x00ffffffU) { |
1017 | 14 | entry.set_value(16384U + entry.value() % (0x00ffffffU - 16384U + 1U)); |
1018 | 14 | } |
1019 | 2.21k | break; |
1020 | 4.81k | case 1U: // SETTINGS_HEADER_TABLE_SIZE |
1021 | 7.77k | case 3U: // SETTINGS_MAX_CONCURRENT_STREAMS |
1022 | 9.23k | case 6U: // SETTINGS_MAX_HEADER_LIST_SIZE |
1023 | 19.8k | default: |
1024 | 19.8k | break; |
1025 | 32.0k | } |
1026 | 32.0k | } |
1027 | 53.5k | } |
1028 | | |
1029 | 27.6k | void BoundHttp2RawData(std::string* data, std::size_t* remaining_raw_bytes) { |
1030 | 27.6k | const std::size_t limit = std::min(scenario_limits::kMaxHttp2RawFrameBytes, *remaining_raw_bytes); |
1031 | 27.6k | if (data->size() > limit) { |
1032 | 4 | data->resize(limit); |
1033 | 4 | } |
1034 | 27.6k | *remaining_raw_bytes -= data->size(); |
1035 | 27.6k | } |
1036 | | |
1037 | | /// Bound the structured HTTP/2 sequence to the exact prefix interpreted by |
1038 | | /// H2PlanDriver. The raw escapes retain malformed frame behavior while every |
1039 | | /// ordinary header action remains HPACK and HTTP-field valid. |
1040 | 36.1k | void BoundHttp2PlanShape(curl::fuzzer::proto::Http2Plan* plan) { |
1041 | 36.1k | TrimRepeated(plan->mutable_actions(), scenario_limits::kMaxHttp2Actions); |
1042 | 36.1k | BoundHttp2Settings(plan->mutable_initial_settings()); |
1043 | 36.1k | plan->mutable_initial_settings()->set_ack(false); |
1044 | 36.1k | if (plan->stream_weight_after_headers() > 256U) { |
1045 | 2 | plan->set_stream_weight_after_headers(1U + (plan->stream_weight_after_headers() - 1U) % 256U); |
1046 | 2 | } |
1047 | 36.1k | if (plan->actions().empty()) { |
1048 | 13 | auto* response = plan->add_actions()->mutable_headers(); |
1049 | 13 | response->set_status_code(200); |
1050 | 13 | response->set_end_stream(true); |
1051 | 13 | } |
1052 | | |
1053 | 36.1k | std::size_t remaining_header_bytes = scenario_limits::kMaxHttp2HeaderBytes; |
1054 | 36.1k | std::size_t remaining_data_bytes = scenario_limits::kMaxHttp2DataBytes; |
1055 | 36.1k | std::size_t remaining_raw_bytes = scenario_limits::kMaxHttp2RawBytes; |
1056 | 195k | for (auto& action : *plan->mutable_actions()) { |
1057 | 195k | switch (action.action_case()) { |
1058 | 17.3k | case curl::fuzzer::proto::Http2Action::kSettings: |
1059 | 17.3k | BoundHttp2Settings(action.mutable_settings()); |
1060 | 17.3k | break; |
1061 | 68.8k | case curl::fuzzer::proto::Http2Action::kHeaders: { |
1062 | 68.8k | auto* headers = action.mutable_headers(); |
1063 | 68.8k | BoundHttp2StreamRef(headers->mutable_stream()); |
1064 | 68.8k | if (!headers->trailers()) { |
1065 | 66.7k | if (headers->status_code() == 0U) { |
1066 | 33 | headers->set_status_code(200U); |
1067 | 66.7k | } else if (headers->status_code() < 100U || headers->status_code() > 599U) { |
1068 | 106 | headers->set_status_code(100U + headers->status_code() % 500U); |
1069 | 106 | } |
1070 | 66.7k | } |
1071 | 68.8k | BoundHttp3Headers(headers->mutable_fields(), scenario_limits::kMaxHttp2Headers, &remaining_header_bytes); |
1072 | 68.8k | break; |
1073 | 0 | } |
1074 | 5.70k | case curl::fuzzer::proto::Http2Action::kData: { |
1075 | 5.70k | auto* data = action.mutable_data(); |
1076 | 5.70k | BoundHttp2StreamRef(data->mutable_stream()); |
1077 | 5.70k | if (data->data().size() > remaining_data_bytes) { |
1078 | 0 | data->mutable_data()->resize(remaining_data_bytes); |
1079 | 0 | } |
1080 | 5.70k | remaining_data_bytes -= data->data().size(); |
1081 | 5.70k | break; |
1082 | 0 | } |
1083 | 7.25k | case curl::fuzzer::proto::Http2Action::kWindowUpdate: { |
1084 | 7.25k | auto* update = action.mutable_window_update(); |
1085 | 7.25k | BoundHttp2StreamRef(update->mutable_stream()); |
1086 | 7.25k | update->set_increment(std::max(1U, update->increment() & 0x7fffffffU)); |
1087 | 7.25k | break; |
1088 | 0 | } |
1089 | 5.61k | case curl::fuzzer::proto::Http2Action::kRstStream: |
1090 | 5.61k | BoundHttp2StreamRef(action.mutable_rst_stream()->mutable_stream()); |
1091 | 5.61k | break; |
1092 | 11.9k | case curl::fuzzer::proto::Http2Action::kPing: |
1093 | 11.9k | if (action.ping().opaque_data().size() > 8U) { |
1094 | 37 | action.mutable_ping()->mutable_opaque_data()->resize(8U); |
1095 | 37 | } |
1096 | 11.9k | break; |
1097 | 8.58k | case curl::fuzzer::proto::Http2Action::kGoaway: |
1098 | 8.58k | BoundHttp2StreamRef(action.mutable_goaway()->mutable_last_stream()); |
1099 | 8.58k | BoundHttp2RawData(action.mutable_goaway()->mutable_debug_data(), &remaining_raw_bytes); |
1100 | 8.58k | break; |
1101 | 22.5k | case curl::fuzzer::proto::Http2Action::kPushPromise: |
1102 | 22.5k | BoundHttp2StreamRef(action.mutable_push_promise()->mutable_parent_stream()); |
1103 | 22.5k | BoundHttp2StreamRef(action.mutable_push_promise()->mutable_promised_stream()); |
1104 | 22.5k | BoundHttp3Headers(action.mutable_push_promise()->mutable_request_headers(), scenario_limits::kMaxHttp2Headers, |
1105 | 22.5k | &remaining_header_bytes); |
1106 | 22.5k | break; |
1107 | 6.65k | case curl::fuzzer::proto::Http2Action::kWait: { |
1108 | 6.65k | auto* wait = action.mutable_wait(); |
1109 | 6.65k | BoundHttp2StreamRef(wait->mutable_stream()); |
1110 | 6.65k | if (wait->event() < curl::fuzzer::proto::HTTP2_CLIENT_EVENT_SETTINGS || |
1111 | 6.63k | wait->event() > curl::fuzzer::proto::HTTP2_CLIENT_EVENT_END_STREAM) { |
1112 | 118 | wait->set_event(curl::fuzzer::proto::HTTP2_CLIENT_EVENT_SETTINGS); |
1113 | 118 | } |
1114 | 6.65k | wait->set_count(std::max(1U, std::min(wait->count(), 16U))); |
1115 | 6.65k | break; |
1116 | 0 | } |
1117 | 21.2k | case curl::fuzzer::proto::Http2Action::kYieldTurns: |
1118 | 21.2k | action.set_yield_turns(std::min<std::uint32_t>(action.yield_turns(), scenario_limits::kMaxHttp2YieldTurns)); |
1119 | 21.2k | break; |
1120 | 13.3k | case curl::fuzzer::proto::Http2Action::kWireFrame: |
1121 | 13.3k | action.mutable_wire_frame()->set_type(action.wire_frame().type() & 0xffU); |
1122 | 13.3k | action.mutable_wire_frame()->set_flags(action.wire_frame().flags() & 0xffU); |
1123 | 13.3k | action.mutable_wire_frame()->set_stream_id(action.wire_frame().stream_id() & 0x7fffffffU); |
1124 | 13.3k | action.mutable_wire_frame()->set_declared_length(action.wire_frame().declared_length() & 0x00ffffffU); |
1125 | 13.3k | BoundHttp2RawData(action.mutable_wire_frame()->mutable_payload(), &remaining_raw_bytes); |
1126 | 13.3k | break; |
1127 | 5.76k | case curl::fuzzer::proto::Http2Action::kRawBytes: |
1128 | 5.76k | BoundHttp2RawData(action.mutable_raw_bytes(), &remaining_raw_bytes); |
1129 | 5.76k | break; |
1130 | 666 | case curl::fuzzer::proto::Http2Action::ACTION_NOT_SET: { |
1131 | 666 | auto* response = action.mutable_headers(); |
1132 | 666 | response->set_status_code(200); |
1133 | 666 | response->set_end_stream(true); |
1134 | 666 | break; |
1135 | 0 | } |
1136 | 195k | } |
1137 | 195k | } |
1138 | 36.1k | } |
1139 | | |
1140 | | /// Canonicalize one ordered H3 script to the exact bounded prefix that the |
1141 | | /// QUIC peer can execute. Transport setup remains peer-owned; only plaintext |
1142 | | /// HTTP/3 operations are mutation-controlled here. |
1143 | 15.3k | void BoundHttp3PlanShape(curl::fuzzer::proto::Http3Plan* plan) { |
1144 | 15.3k | if (plan->use_h1_connect_udp_proxy()) { |
1145 | 9.46k | plan->clear_actions(); |
1146 | 9.46k | return; |
1147 | 9.46k | } |
1148 | 5.87k | TrimRepeated(plan->mutable_actions(), scenario_limits::kMaxHttp3Actions); |
1149 | 5.87k | if (plan->actions().empty()) { |
1150 | 528 | auto* response = plan->add_actions()->mutable_structured_response(); |
1151 | 528 | response->set_status_code(200); |
1152 | 528 | response->set_finish_stream(true); |
1153 | 528 | } |
1154 | | |
1155 | 5.87k | std::size_t remaining_header_bytes = scenario_limits::kMaxHttp3HeaderBytes; |
1156 | 5.87k | std::size_t remaining_body_bytes = scenario_limits::kMaxHttp3BodyBytes; |
1157 | 5.87k | std::size_t remaining_raw_bytes = scenario_limits::kMaxHttp3RawBytes; |
1158 | 5.87k | std::size_t retained_actions = 0; |
1159 | 5.87k | bool connection_closed = false; |
1160 | 9.47k | for (auto& action : *plan->mutable_actions()) { |
1161 | 9.47k | if (connection_closed) { |
1162 | 39 | break; |
1163 | 39 | } |
1164 | 9.44k | ++retained_actions; |
1165 | 9.44k | switch (action.action_case()) { |
1166 | 3.30k | case curl::fuzzer::proto::Http3Action::kStructuredResponse: { |
1167 | 3.30k | auto* response = action.mutable_structured_response(); |
1168 | 3.30k | if (response->status_code() == 0U) { |
1169 | 110 | response->set_status_code(200U); |
1170 | 3.19k | } else if (response->status_code() < 100U || response->status_code() > 599U) { |
1171 | 117 | response->set_status_code(100U + response->status_code() % 500U); |
1172 | 117 | } |
1173 | 3.30k | BoundHttp3Headers(response->mutable_response_headers(), scenario_limits::kMaxHttp3Headers, |
1174 | 3.30k | &remaining_header_bytes); |
1175 | 3.30k | BoundHttp3Headers(response->mutable_response_trailers(), scenario_limits::kMaxHttp3Trailers, |
1176 | 3.30k | &remaining_header_bytes); |
1177 | 3.30k | TrimRepeated(response->mutable_body_chunks(), scenario_limits::kMaxHttp3BodyChunks); |
1178 | 3.30k | for (std::string& chunk : *response->mutable_body_chunks()) { |
1179 | 2.07k | if (chunk.size() > remaining_body_bytes) { |
1180 | 20 | chunk.resize(remaining_body_bytes); |
1181 | 20 | } |
1182 | 2.07k | remaining_body_bytes -= chunk.size(); |
1183 | 2.07k | } |
1184 | 3.30k | break; |
1185 | 0 | } |
1186 | | |
1187 | 1.19k | case curl::fuzzer::proto::Http3Action::kStreamWrite: { |
1188 | 1.19k | auto* write = action.mutable_stream_write(); |
1189 | 1.19k | auto role = write->role(); |
1190 | 1.19k | CanonicalizeHttp3StreamRole(&role); |
1191 | 1.19k | write->set_role(role); |
1192 | 1.19k | BoundHttp3RawData(write->mutable_data(), &remaining_raw_bytes); |
1193 | 1.19k | break; |
1194 | 0 | } |
1195 | | |
1196 | 1.13k | case curl::fuzzer::proto::Http3Action::kOpenUnidirectionalStream: { |
1197 | 1.13k | auto* stream = action.mutable_open_unidirectional_stream(); |
1198 | 1.13k | BoundHttp3RawData(stream->mutable_data(), &remaining_raw_bytes); |
1199 | 1.13k | break; |
1200 | 0 | } |
1201 | | |
1202 | 1.06k | case curl::fuzzer::proto::Http3Action::kStreamReset: { |
1203 | 1.06k | auto* reset = action.mutable_stream_reset(); |
1204 | 1.06k | auto role = reset->role(); |
1205 | 1.06k | CanonicalizeHttp3StreamRole(&role); |
1206 | 1.06k | reset->set_role(role); |
1207 | 1.06k | reset->set_application_error_code(reset->application_error_code() & scenario_limits::kMaxQuicVarint); |
1208 | 1.06k | break; |
1209 | 0 | } |
1210 | | |
1211 | 1.19k | case curl::fuzzer::proto::Http3Action::kGoaway: |
1212 | 1.19k | action.mutable_goaway()->set_id(action.goaway().id() & scenario_limits::kMaxQuicVarint & ~std::uint64_t{3}); |
1213 | 1.19k | break; |
1214 | | |
1215 | 1.39k | case curl::fuzzer::proto::Http3Action::kConnectionClose: |
1216 | 1.39k | action.mutable_connection_close()->set_application_error_code( |
1217 | 1.39k | action.connection_close().application_error_code() & scenario_limits::kMaxQuicVarint); |
1218 | 1.39k | connection_closed = true; |
1219 | 1.39k | break; |
1220 | | |
1221 | 164 | case curl::fuzzer::proto::Http3Action::ACTION_NOT_SET: { |
1222 | 164 | auto* response = action.mutable_structured_response(); |
1223 | 164 | response->set_status_code(200); |
1224 | 164 | response->set_finish_stream(true); |
1225 | 164 | break; |
1226 | 0 | } |
1227 | 9.44k | } |
1228 | 9.44k | } |
1229 | 5.87k | TrimRepeated(plan->mutable_actions(), retained_actions); |
1230 | 5.87k | } |
1231 | | |
1232 | | /// Canonicalize all shape limits enforced by the runtime. This runs only in |
1233 | | /// fixed policy targets; the compatibility binary deliberately retains its |
1234 | | /// historical no-postprocessor semantics for existing OSS-Fuzz reproducers. |
1235 | 623k | void BoundScenarioShape(curl::fuzzer::proto::Scenario* scenario) { |
1236 | 623k | TrimRepeated(scenario->mutable_options(), scenario_limits::kMaxOptions); |
1237 | | |
1238 | 623k | BoundHeaderValues(scenario->mutable_request_headers(), scenario_limits::kMaxRequestHeaders); |
1239 | 623k | BoundStringValues(scenario->mutable_telnet_options(), scenario_limits::kMaxTelnetOptions, |
1240 | 623k | scenario_limits::kMaxTelnetOptionBytes); |
1241 | 623k | if (scenario->has_mime_post()) { |
1242 | 106k | BoundMimeShape(scenario->mutable_mime_post()); |
1243 | 106k | } |
1244 | 623k | if (scenario->has_upload()) { |
1245 | 66.3k | const bool telnet = scenario->scheme() == curl::fuzzer::proto::SCHEME_TELNET; |
1246 | 66.3k | const std::size_t data_limit = telnet ? scenario_limits::kMaxTelnetUploadBytes : scenario_limits::kMaxUploadBytes; |
1247 | 66.3k | const std::size_t read_step_limit = |
1248 | 66.3k | telnet ? scenario_limits::kMaxTelnetUploadReadSteps : scenario_limits::kMaxUploadReadSteps; |
1249 | 66.3k | const std::size_t read_size_limit = |
1250 | 66.3k | telnet ? scenario_limits::kMaxTelnetUploadReadSize : scenario_limits::kMaxUploadReadSize; |
1251 | 66.3k | BoundUploadShape(scenario->mutable_upload(), data_limit, read_step_limit, read_size_limit); |
1252 | 66.3k | } |
1253 | | |
1254 | 623k | BoundConnectionShape(scenario->mutable_connection()); |
1255 | 623k | TrimRepeated(scenario->mutable_subsequent_connections(), scenario_limits::kMaxConnections - 1); |
1256 | 623k | for (auto& connection : *scenario->mutable_subsequent_connections()) { |
1257 | 126k | BoundConnectionShape(&connection); |
1258 | 126k | } |
1259 | 623k | BoundStringValues(scenario->mutable_mail_rcpt(), scenario_limits::kMaxMailRecipients, |
1260 | 623k | scenario_limits::kMaxMailRecipientBytes); |
1261 | 623k | BoundFileInputs(scenario); |
1262 | 623k | } |
1263 | | |
1264 | | /// Apply schema-declared variant guards after lane selectors are normalized, |
1265 | | /// then impose the shared work bounds. Static membership has already been |
1266 | | /// enforced by the generated profile message type. |
1267 | | void PruneAndBoundScenarioShape(curl::fuzzer::proto::Scenario* scenario, TargetProfile profile, |
1268 | 623k | ConditionalEligibilityPruner prune_conditional_eligibility) { |
1269 | 623k | if (prune_conditional_eligibility != nullptr) { |
1270 | 623k | prune_conditional_eligibility(scenario, profile); |
1271 | 623k | } |
1272 | 623k | BoundScenarioShape(scenario); |
1273 | 623k | } |
1274 | | |
1275 | | /// Fold malformed deep-HTTP route selectors to their zero-valued direct |
1276 | | /// modes before generated guards evaluate dependent routing fields. |
1277 | 43.5k | void CanonicalizeDeepHttpSelectors(curl::fuzzer::proto::Scenario* scenario) { |
1278 | 43.5k | switch (scenario->http_transport_mode()) { |
1279 | 38.9k | case curl::fuzzer::proto::HTTP_TRANSPORT_DIRECT: |
1280 | 39.8k | case curl::fuzzer::proto::HTTP_TRANSPORT_FORWARD_PROXY: |
1281 | 42.5k | case curl::fuzzer::proto::HTTP_TRANSPORT_CONNECT_PROXY: |
1282 | 43.5k | case curl::fuzzer::proto::HTTP_TRANSPORT_UNIX_SOCKET: |
1283 | 43.5k | break; |
1284 | 2 | default: |
1285 | 2 | scenario->clear_http_transport_mode(); |
1286 | 2 | break; |
1287 | 43.5k | } |
1288 | 43.5k | switch (scenario->proxy_socket_option_mode()) { |
1289 | 31.8k | case curl::fuzzer::proto::PROXY_SOCKET_OPTION_DEFAULT: |
1290 | 32.6k | case curl::fuzzer::proto::PROXY_SOCKET_OPTION_NOPROXY_HOSTNAME: |
1291 | 36.1k | case curl::fuzzer::proto::PROXY_SOCKET_OPTION_NOPROXY_IPV4_CIDR: |
1292 | 42.0k | case curl::fuzzer::proto::PROXY_SOCKET_OPTION_NOPROXY_IPV6_CIDR: |
1293 | 43.2k | case curl::fuzzer::proto::PROXY_SOCKET_OPTION_ENV_HTTP_PROXY: |
1294 | 43.5k | case curl::fuzzer::proto::PROXY_SOCKET_OPTION_LOOPBACK_INTERFACE_KEEPALIVE: |
1295 | 43.5k | break; |
1296 | 2 | default: |
1297 | 2 | scenario->clear_proxy_socket_option_mode(); |
1298 | 2 | break; |
1299 | 43.5k | } |
1300 | 43.5k | } |
1301 | | |
1302 | | /// Decode an integral oneof locally before the generated option canonicalizer |
1303 | | /// runs. Protocol mode bounds are policy, not setopt mechanics: folding them |
1304 | | /// here keeps nearly every mutation on a real FTP/TFTP state while the shared |
1305 | | /// option layer remains unaware of protocol-specific numeric ranges. |
1306 | 41.3k | std::uint64_t IntegralMutationValue(const curl::fuzzer::proto::SetOption& option) { |
1307 | 41.3k | switch (option.value_case()) { |
1308 | 41.3k | case curl::fuzzer::proto::SetOption::kUintValue: |
1309 | 41.3k | return option.uint_value(); |
1310 | 0 | case curl::fuzzer::proto::SetOption::kBoolValue: |
1311 | 0 | return option.bool_value() ? 1U : 0U; |
1312 | 0 | case curl::fuzzer::proto::SetOption::kStringValue: |
1313 | 0 | case curl::fuzzer::proto::SetOption::VALUE_NOT_SET: |
1314 | 0 | return 0; |
1315 | 41.3k | } |
1316 | 0 | return 0; |
1317 | 41.3k | } |
1318 | | |
1319 | | /// Bound the synchronous local-port search for both fixed and compatibility |
1320 | | /// execution copies. The persistent compatibility input remains unchanged. |
1321 | 956k | void CanonicalizeLocalPortRange(curl::fuzzer::proto::Scenario* scenario) { |
1322 | 2.77M | for (auto& option : *scenario->mutable_options()) { |
1323 | 2.77M | if (option.option_id() == curl::fuzzer::proto::CURLOPT_LOCALPORTRANGE) { |
1324 | 8.37k | option.set_uint_value(std::min<std::uint64_t>(IntegralMutationValue(option), kMaxLocalPortRange)); |
1325 | 8.37k | } |
1326 | 2.77M | } |
1327 | 956k | } |
1328 | | |
1329 | | /// Keep prior-knowledge HTTP/2 and HTTP/3 out of the throughput-oriented HTTP |
1330 | | /// lane. HTTP/1 modes and cleartext HTTP/2 upgrade remain here because h2c's |
1331 | | /// HTTP/1 request and 101 transition are distinct from the dedicated target's |
1332 | | /// prior-knowledge transport. |
1333 | 57.9k | void CanonicalizeFastHttpVersion(curl::fuzzer::proto::Scenario* scenario) { |
1334 | 76.1k | for (auto& option : *scenario->mutable_options()) { |
1335 | 76.1k | if (option.option_id() != curl::fuzzer::proto::CURLOPT_HTTP_VERSION) { |
1336 | 53.3k | continue; |
1337 | 53.3k | } |
1338 | 22.8k | const std::uint64_t version = IntegralMutationValue(option); |
1339 | | // 2TLS remains HTTP/1.1 because this target fixes the scheme to HTTP. |
1340 | 22.8k | if (version <= CURL_HTTP_VERSION_2TLS) { |
1341 | 22.7k | option.set_uint_value(version); |
1342 | 22.7k | } else { |
1343 | 53 | option.set_uint_value(CURL_HTTP_VERSION_NONE); |
1344 | 53 | } |
1345 | 22.8k | } |
1346 | 57.9k | } |
1347 | | |
1348 | | /// Fold small FTP enums onto curl's documented domains so random uint64 values |
1349 | | /// do not overwhelmingly stop at setopt validation before issuing a command. |
1350 | 14.9k | void CanonicalizeFtpOptionModes(curl::fuzzer::proto::Scenario* scenario) { |
1351 | 39.5k | for (auto& option : *scenario->mutable_options()) { |
1352 | 39.5k | switch (option.option_id()) { |
1353 | 534 | case curl::fuzzer::proto::CURLOPT_FTP_CREATE_MISSING_DIRS: |
1354 | 534 | option.set_uint_value(IntegralMutationValue(option) % 3U); |
1355 | 534 | break; |
1356 | 1.14k | case curl::fuzzer::proto::CURLOPT_FTP_FILEMETHOD: |
1357 | 1.14k | option.set_uint_value(IntegralMutationValue(option) % 4U); |
1358 | 1.14k | break; |
1359 | 884 | case curl::fuzzer::proto::CURLOPT_FTPPORT: |
1360 | | // Never let a mutated active-mode address resolve or bind outside the |
1361 | | // process. Empty remains reachable only by omitting the option. |
1362 | 884 | option.set_string_value("127.0.0.1"); |
1363 | 884 | break; |
1364 | 829 | case curl::fuzzer::proto::CURLOPT_FTP_USE_EPRT: |
1365 | 829 | option.set_bool_value(IntegralMutationValue(option) != 0U); |
1366 | 829 | break; |
1367 | 36.1k | default: |
1368 | 36.1k | break; |
1369 | 39.5k | } |
1370 | 39.5k | } |
1371 | 14.9k | } |
1372 | | |
1373 | | /// TFTP accepts block sizes from 8 through 65464. Mapping zero or a mismatched |
1374 | | /// oneof to the default 512 preserves a common valid request, while saturating |
1375 | | /// other values retains both lower/upper parser boundaries under mutation. |
1376 | 4.77k | void CanonicalizeTftpOptionModes(curl::fuzzer::proto::Scenario* scenario) { |
1377 | 13.9k | for (auto& option : *scenario->mutable_options()) { |
1378 | 13.9k | if (option.option_id() != curl::fuzzer::proto::CURLOPT_TFTP_BLKSIZE) { |
1379 | 11.9k | continue; |
1380 | 11.9k | } |
1381 | 2.07k | std::uint64_t value = IntegralMutationValue(option); |
1382 | 2.07k | if (value == 0) { |
1383 | 503 | value = 512; |
1384 | 503 | } |
1385 | 2.07k | option.set_uint_value(std::max<std::uint64_t>(8, std::min<std::uint64_t>(value, 65464))); |
1386 | 2.07k | } |
1387 | 4.77k | } |
1388 | | |
1389 | | /// Fold the RTSP request selector onto curl's documented 1..11 domain so |
1390 | | /// random uint64 mutations still issue a method instead of failing setopt |
1391 | | /// validation. A zero or out-of-range value becomes the default OPTIONS. |
1392 | | /// Sequence overrides are clamped to curl's int range; zero remains meaningful |
1393 | | /// because curl rewrites it to its default on connect. |
1394 | 15.7k | void CanonicalizeRtspOptionModes(curl::fuzzer::proto::Scenario* scenario) { |
1395 | 38.0k | for (auto& option : *scenario->mutable_options()) { |
1396 | 38.0k | switch (option.option_id()) { |
1397 | 3.45k | case curl::fuzzer::proto::CURLOPT_RTSP_REQUEST: { |
1398 | 3.45k | const std::uint64_t value = IntegralMutationValue(option); |
1399 | | // RECEIVE sends no request and instead waits for server-initiated |
1400 | | // stream data, which the request-aligned peer never emits. Fold it |
1401 | | // onto the default OPTIONS like zero and out-of-range values so every |
1402 | | // retained request still issues a scripted exchange. |
1403 | 3.45k | const bool supported = |
1404 | 3.45k | value >= CURL_RTSPREQ_OPTIONS && value < CURL_RTSPREQ_LAST && value != CURL_RTSPREQ_RECEIVE; |
1405 | 3.45k | option.set_uint_value(supported ? value : CURL_RTSPREQ_OPTIONS); |
1406 | 3.45k | break; |
1407 | 0 | } |
1408 | 1.23k | case curl::fuzzer::proto::CURLOPT_RTSP_CLIENT_CSEQ: |
1409 | 2.11k | case curl::fuzzer::proto::CURLOPT_RTSP_SERVER_CSEQ: |
1410 | 2.11k | option.set_uint_value(std::min<std::uint64_t>(IntegralMutationValue(option), |
1411 | 2.11k | static_cast<std::uint64_t>(std::numeric_limits<int>::max()))); |
1412 | 2.11k | break; |
1413 | 32.4k | default: |
1414 | 32.4k | break; |
1415 | 38.0k | } |
1416 | 38.0k | } |
1417 | 15.7k | } |
1418 | | |
1419 | | /// Remove the stateful shapes assigned to the deep HTTP target. This happens |
1420 | | /// before BoundScenarioShape so a fast iteration never walks or normalizes a |
1421 | | /// MIME tree, upload script, or follow-on connection that it will discard. |
1422 | | /// Raw response chunks and request headers stay intact because they reach the |
1423 | | /// core HTTP parser cheaply and preserve broad parser coverage. |
1424 | 107k | void RemoveDeepHttpShape(curl::fuzzer::proto::Scenario* scenario) { |
1425 | 107k | scenario->clear_mime_post(); |
1426 | 107k | scenario->clear_upload(); |
1427 | 107k | scenario->clear_subsequent_connections(); |
1428 | | |
1429 | 107k | auto* connection = scenario->mutable_connection(); |
1430 | 107k | connection->clear_server_frames(); |
1431 | 107k | connection->clear_manual_probes(); |
1432 | 107k | connection->clear_backpressure(); |
1433 | 107k | } |
1434 | | |
1435 | | /// Remove response forms the proxy peer cannot interpret. Raw chunks are the |
1436 | | /// HTTP/2 frame stream; WebSocket frames would merely add a second unrelated |
1437 | | /// binary grammar, and follow-on Connection messages cannot describe later |
1438 | | /// streams multiplexed on the already-open proxy socket. |
1439 | 90.6k | void RemoveIgnoredH2ProxyShape(curl::fuzzer::proto::Scenario* scenario) { |
1440 | 90.6k | scenario->clear_subsequent_connections(); |
1441 | 90.6k | auto* connection = scenario->mutable_connection(); |
1442 | 90.6k | connection->clear_server_frames(); |
1443 | 90.6k | connection->clear_manual_probes(); |
1444 | 90.6k | connection->clear_backpressure(); |
1445 | 90.6k | } |
1446 | | |
1447 | | /// Remove fields the single-socket WebSocket driver cannot consume. MIME also |
1448 | | /// changes the HTTP request away from a useful Upgrade handshake, so retaining |
1449 | | /// either shape in fixed WS lanes gives LPM mutation work with no WS coverage |
1450 | | /// payoff. The mixed compatibility target has no postprocessor and keeps its |
1451 | | /// historical behavior. |
1452 | 49.9k | void RemoveIgnoredWebSocketShape(curl::fuzzer::proto::Scenario* scenario) { |
1453 | 49.9k | scenario->clear_subsequent_connections(); |
1454 | 49.9k | scenario->clear_mime_post(); |
1455 | 49.9k | } |
1456 | | |
1457 | | /// Remove fields whose only effect in a TELNET lane would be protobuf work or |
1458 | | /// unsafe socket timing. TELNET's curl driver owns the thread until the peer |
1459 | | /// closes, so response backpressure and follow-on sockets cannot be serviced |
1460 | | /// by the outer event loop. Raw response fragments and the bounded upload stay |
1461 | | /// mutation-controlled because the dedicated mock can preload and drain them. |
1462 | 9.08k | void RemoveNonTelnetShape(curl::fuzzer::proto::Scenario* scenario) { |
1463 | 9.08k | scenario->clear_subsequent_connections(); |
1464 | 9.08k | scenario->clear_request_headers(); |
1465 | 9.08k | scenario->clear_mime_post(); |
1466 | | |
1467 | 9.08k | auto* connection = scenario->mutable_connection(); |
1468 | 9.08k | connection->clear_server_frames(); |
1469 | 9.08k | connection->clear_manual_probes(); |
1470 | 9.08k | connection->clear_backpressure(); |
1471 | 9.08k | } |
1472 | | |
1473 | | /// Remove the TELNET-only list and pause outcome from fixed event-driven |
1474 | | /// targets. The compatibility target skips postprocessing, so the runtime |
1475 | | /// repeats the pause-to-EOF guard before installing callbacks. |
1476 | 614k | void RemoveTelnetOnlyShape(curl::fuzzer::proto::Scenario* scenario) { |
1477 | 614k | scenario->clear_telnet_options(); |
1478 | 614k | if (scenario->has_upload() && scenario->upload().terminal() == curl::fuzzer::proto::UPLOAD_TERMINAL_PAUSE) { |
1479 | 22 | scenario->mutable_upload()->set_terminal(curl::fuzzer::proto::UPLOAD_TERMINAL_EOF); |
1480 | 22 | } |
1481 | 614k | } |
1482 | | |
1483 | | /// Keep lifecycle work out of protocol-focused lanes. The API binary retains |
1484 | | /// this message explicitly; compatibility inputs have no postprocessor so |
1485 | | /// existing reproducers keep their historical serialized meaning. |
1486 | 583k | void RemoveApiOnlyShape(curl::fuzzer::proto::Scenario* scenario) { scenario->clear_api_plan(); } |
1487 | | |
1488 | | /// Keep concurrent multi-handle work out of every other fixed lane. The |
1489 | | /// compatibility binary deliberately preserves newly-added unknown fields. |
1490 | 587k | void RemoveMultiOnlyShape(curl::fuzzer::proto::Scenario* scenario) { scenario->clear_multi_plan(); } |
1491 | | |
1492 | | /// The QUIC peer consumes Http3Plan rather than the stream-socket response |
1493 | | /// script. Request headers, MIME, upload state, and HTTP options remain useful |
1494 | | /// because curl serializes those onto its client-initiated request stream. |
1495 | 15.3k | void RemoveIgnoredHttp3Shape(curl::fuzzer::proto::Scenario* scenario) { |
1496 | 15.3k | if (!scenario->http3_plan().use_h1_connect_udp_proxy()) { |
1497 | 5.87k | scenario->clear_connection(); |
1498 | 5.87k | } |
1499 | 15.3k | scenario->clear_subsequent_connections(); |
1500 | 15.3k | RemoveTelnetOnlyShape(scenario); |
1501 | 15.3k | RemoveApiOnlyShape(scenario); |
1502 | 15.3k | RemoveMultiOnlyShape(scenario); |
1503 | 15.3k | } |
1504 | | |
1505 | | /// Remove stream-driver controls unused by a protocol peer. FTP and TFTP |
1506 | | /// discard every such control; the line-oriented IMAP and POP3 peers opt in to |
1507 | | /// retaining recv-buffer pressure before a later mail-specific canonicalizer |
1508 | | /// removes drain throttling. |
1509 | | void RemoveUnusedFileTransferConnectionShape(curl::fuzzer::proto::Connection* connection, |
1510 | 123k | bool retain_backpressure = false) { |
1511 | 123k | connection->clear_server_frames(); |
1512 | 123k | connection->clear_manual_probes(); |
1513 | 123k | if (!retain_backpressure) { |
1514 | 102k | connection->clear_backpressure(); |
1515 | 102k | } |
1516 | 123k | } |
1517 | | |
1518 | | /// Retain only the reusable shapes consumed by the FTP peer: one raw control |
1519 | | /// script, a bounded sequence of passive-data scripts, and optional upload |
1520 | | /// input. HTTP, TELNET, WebSocket, and public-API fields would otherwise absorb |
1521 | | /// mutations despite having no representation in an FTP exchange. |
1522 | 14.9k | void RemoveIgnoredFtpShape(curl::fuzzer::proto::Scenario* scenario) { |
1523 | 14.9k | scenario->clear_request_headers(); |
1524 | 14.9k | scenario->clear_mime_post(); |
1525 | 14.9k | RemoveTelnetOnlyShape(scenario); |
1526 | 14.9k | RemoveApiOnlyShape(scenario); |
1527 | 14.9k | RemoveMultiOnlyShape(scenario); |
1528 | | |
1529 | 14.9k | RemoveUnusedFileTransferConnectionShape(scenario->mutable_connection()); |
1530 | 14.9k | TrimRepeated(scenario->mutable_subsequent_connections(), scenario_limits::kMaxConnections - 1); |
1531 | 14.9k | for (auto& connection : *scenario->mutable_subsequent_connections()) { |
1532 | 8.96k | RemoveUnusedFileTransferConnectionShape(&connection); |
1533 | 8.96k | } |
1534 | 14.9k | } |
1535 | | |
1536 | | /// Retain the primary raw response script because its entries are the ordered |
1537 | | /// UDP datagrams seen by curl, plus optional upload input for WRQ. TFTP cannot |
1538 | | /// consume follow-on stream connections or any higher-level protocol shape. |
1539 | 4.77k | void RemoveIgnoredTftpShape(curl::fuzzer::proto::Scenario* scenario) { |
1540 | 4.77k | scenario->clear_subsequent_connections(); |
1541 | 4.77k | scenario->clear_request_headers(); |
1542 | 4.77k | scenario->clear_mime_post(); |
1543 | 4.77k | RemoveTelnetOnlyShape(scenario); |
1544 | 4.77k | RemoveApiOnlyShape(scenario); |
1545 | 4.77k | RemoveMultiOnlyShape(scenario); |
1546 | 4.77k | RemoveUnusedFileTransferConnectionShape(scenario->mutable_connection()); |
1547 | 4.77k | } |
1548 | | |
1549 | | /// Retain the single command-aligned control script and optional upload body |
1550 | | /// consumed by the SMTP peer. SMTP cannot open follow-on sockets, and HTTP |
1551 | | /// headers, TELNET negotiation, API plans, and stream-only connection controls |
1552 | | /// have no representation in its exchange. MIME remains meaningful because |
1553 | | /// curl can serialize it as the DATA body. |
1554 | 12.0k | void RemoveIgnoredSmtpShape(curl::fuzzer::proto::Scenario* scenario) { |
1555 | 12.0k | scenario->clear_subsequent_connections(); |
1556 | 12.0k | scenario->clear_request_headers(); |
1557 | 12.0k | RemoveTelnetOnlyShape(scenario); |
1558 | 12.0k | RemoveApiOnlyShape(scenario); |
1559 | 12.0k | RemoveMultiOnlyShape(scenario); |
1560 | 12.0k | RemoveUnusedFileTransferConnectionShape(scenario->mutable_connection()); |
1561 | 12.0k | } |
1562 | | |
1563 | | /// Retain the one command-aligned control script and optional APPEND body |
1564 | | /// consumed by the IMAP peer. IMAP cannot open follow-on sockets, and HTTP |
1565 | | /// headers and structured stream controls have no representation in its |
1566 | | /// exchange. MIME remains meaningful because curl serializes it as an APPEND |
1567 | | /// literal. |
1568 | 12.9k | void RemoveIgnoredImapShape(curl::fuzzer::proto::Scenario* scenario) { |
1569 | 12.9k | scenario->clear_subsequent_connections(); |
1570 | 12.9k | scenario->clear_request_headers(); |
1571 | 12.9k | RemoveTelnetOnlyShape(scenario); |
1572 | 12.9k | RemoveApiOnlyShape(scenario); |
1573 | 12.9k | RemoveMultiOnlyShape(scenario); |
1574 | 12.9k | RemoveUnusedFileTransferConnectionShape(scenario->mutable_connection(), true); |
1575 | 12.9k | } |
1576 | | |
1577 | | /// Retain only the command-aligned control script. POP3 is a download-only |
1578 | | /// protocol: upload state, MIME bodies, HTTP headers, and follow-on sockets |
1579 | | /// cannot reach its state machine. |
1580 | 8.29k | void RemoveIgnoredPop3Shape(curl::fuzzer::proto::Scenario* scenario) { |
1581 | 8.29k | scenario->clear_subsequent_connections(); |
1582 | 8.29k | scenario->clear_request_headers(); |
1583 | 8.29k | scenario->clear_mime_post(); |
1584 | 8.29k | scenario->clear_upload(); |
1585 | 8.29k | RemoveTelnetOnlyShape(scenario); |
1586 | 8.29k | RemoveApiOnlyShape(scenario); |
1587 | 8.29k | RemoveMultiOnlyShape(scenario); |
1588 | 8.29k | RemoveUnusedFileTransferConnectionShape(scenario->mutable_connection(), true); |
1589 | 8.29k | } |
1590 | | |
1591 | 17.9k | void RemoveIgnoredGopherShape(curl::fuzzer::proto::Scenario* scenario) { |
1592 | 17.9k | scenario->clear_subsequent_connections(); |
1593 | 17.9k | scenario->clear_request_headers(); |
1594 | 17.9k | scenario->clear_mime_post(); |
1595 | 17.9k | scenario->clear_upload(); |
1596 | 17.9k | RemoveTelnetOnlyShape(scenario); |
1597 | 17.9k | RemoveApiOnlyShape(scenario); |
1598 | 17.9k | RemoveMultiOnlyShape(scenario); |
1599 | 17.9k | RemoveUnusedFileTransferConnectionShape(scenario->mutable_connection()); |
1600 | 17.9k | } |
1601 | | |
1602 | | /// Retain only the command-aligned control script. DICT is a download-only |
1603 | | /// protocol: upload state, MIME bodies, HTTP headers, and follow-on sockets |
1604 | | /// cannot reach its state machine. |
1605 | 6.07k | void RemoveIgnoredDictShape(curl::fuzzer::proto::Scenario* scenario) { |
1606 | 6.07k | scenario->clear_subsequent_connections(); |
1607 | 6.07k | scenario->clear_request_headers(); |
1608 | 6.07k | scenario->clear_mime_post(); |
1609 | 6.07k | scenario->clear_upload(); |
1610 | 6.07k | RemoveTelnetOnlyShape(scenario); |
1611 | 6.07k | RemoveApiOnlyShape(scenario); |
1612 | 6.07k | RemoveMultiOnlyShape(scenario); |
1613 | 6.07k | RemoveUnusedFileTransferConnectionShape(scenario->mutable_connection()); |
1614 | | // curl writes CLIENT, one lookup command, and QUIT in a single send, then |
1615 | | // reads an EOF-framed body. The peer consumes only the first non-CLIENT |
1616 | | // reply chunk and half-closes, so any later chunk is permanently dead work |
1617 | | // the mutator keeps rediscovering. |
1618 | 6.07k | TrimRepeated(scenario->mutable_connection()->mutable_on_readable(), 1); |
1619 | 6.07k | } |
1620 | | |
1621 | | /// Retain the one binary server script and the scalar publish payload. MQTT |
1622 | | /// cannot open follow-on sockets, does not use HTTP headers or MIME, and takes |
1623 | | /// its publish body from CURLOPT_POSTFIELDS rather than curl's read callback. |
1624 | | /// The remaining connection fields (initial CONNACK plus server packets) are |
1625 | | /// exactly what the packet-aware peer consumes. |
1626 | 8.42k | void RemoveIgnoredMqttShape(curl::fuzzer::proto::Scenario* scenario) { |
1627 | 8.42k | scenario->clear_subsequent_connections(); |
1628 | 8.42k | scenario->clear_request_headers(); |
1629 | 8.42k | scenario->clear_mime_post(); |
1630 | 8.42k | scenario->clear_upload(); |
1631 | 8.42k | RemoveTelnetOnlyShape(scenario); |
1632 | 8.42k | RemoveApiOnlyShape(scenario); |
1633 | 8.42k | RemoveMultiOnlyShape(scenario); |
1634 | 8.42k | RemoveUnusedFileTransferConnectionShape(scenario->mutable_connection()); |
1635 | 8.42k | } |
1636 | | |
1637 | | /// FILE has no peer, so response scripts, connection controls, MIME, and |
1638 | | /// HTTP/TELNET/API state are inert. Retain the bounded source and upload |
1639 | | /// script because the runtime exposes them only through a session-owned |
1640 | | /// anonymous descriptor. |
1641 | 8.26k | void RemoveIgnoredFileShape(curl::fuzzer::proto::Scenario* scenario) { |
1642 | 8.26k | scenario->clear_connection(); |
1643 | 8.26k | scenario->clear_subsequent_connections(); |
1644 | 8.26k | scenario->clear_request_headers(); |
1645 | 8.26k | scenario->clear_mime_post(); |
1646 | 8.26k | RemoveTelnetOnlyShape(scenario); |
1647 | 8.26k | RemoveApiOnlyShape(scenario); |
1648 | 8.26k | RemoveMultiOnlyShape(scenario); |
1649 | 8.26k | } |
1650 | | |
1651 | | /// Retain the scripted bind reply and BER search-result messages consumed by |
1652 | | /// the LDAP peer. LDAP cannot open follow-on sockets, and HTTP headers, MIME, |
1653 | | /// upload state, and TELNET negotiation have no representation in its |
1654 | | /// exchange. The primary connection's initial_response is the bind reply, so |
1655 | | /// unlike the file-transfer and mail lanes it must survive pruning. |
1656 | 13.3k | void RemoveIgnoredLdapShape(curl::fuzzer::proto::Scenario* scenario) { |
1657 | 13.3k | scenario->clear_subsequent_connections(); |
1658 | 13.3k | scenario->clear_request_headers(); |
1659 | 13.3k | scenario->clear_mime_post(); |
1660 | 13.3k | scenario->clear_upload(); |
1661 | 13.3k | RemoveTelnetOnlyShape(scenario); |
1662 | 13.3k | RemoveApiOnlyShape(scenario); |
1663 | 13.3k | RemoveMultiOnlyShape(scenario); |
1664 | 13.3k | RemoveUnusedFileTransferConnectionShape(scenario->mutable_connection()); |
1665 | 13.3k | } |
1666 | | |
1667 | | /// Retain the request-aligned control script and the fields curl serializes |
1668 | | /// into an RTSP request. Custom request headers, upload/postfields bodies for |
1669 | | /// ANNOUNCE and SET_PARAMETER, and MIME-free options stay meaningful. RTSP has |
1670 | | /// no server greeting, cannot consume follow-on stream scripts, and does not |
1671 | | /// use MIME bodies, so those shapes are removed before general bounds. |
1672 | 15.7k | void RemoveIgnoredRtspShape(curl::fuzzer::proto::Scenario* scenario) { |
1673 | 15.7k | scenario->clear_subsequent_connections(); |
1674 | 15.7k | scenario->clear_mime_post(); |
1675 | 15.7k | RemoveTelnetOnlyShape(scenario); |
1676 | 15.7k | RemoveApiOnlyShape(scenario); |
1677 | 15.7k | RemoveMultiOnlyShape(scenario); |
1678 | | |
1679 | 15.7k | auto* connection = scenario->mutable_connection(); |
1680 | 15.7k | connection->clear_initial_response(); |
1681 | 15.7k | RemoveUnusedFileTransferConnectionShape(connection); |
1682 | 15.7k | } |
1683 | | |
1684 | | /// Retain the shapes an ordinary gateway GET can consume. The IPFS/IPNS lane |
1685 | | /// runs through the same HTTP mock as the fast HTTP lane, so raw response |
1686 | | /// chunks, request headers, and HTTP options stay meaningful while MIME, |
1687 | | /// uploads, structured frames, and follow-on sockets are removed. |
1688 | 24.2k | void RemoveIgnoredIpfsShape(curl::fuzzer::proto::Scenario* scenario) { |
1689 | 24.2k | RemoveApiOnlyShape(scenario); |
1690 | 24.2k | RemoveMultiOnlyShape(scenario); |
1691 | 24.2k | RemoveTelnetOnlyShape(scenario); |
1692 | 24.2k | RemoveDeepHttpShape(scenario); |
1693 | 24.2k | } |
1694 | | |
1695 | | /// Preserve useful in-range mutations while folding ineffective extremes onto |
1696 | | /// meaningful boundaries. Zero remains special: it disables that individual |
1697 | | /// control and lets the other control provide the timing target's pressure. |
1698 | 85.9k | std::uint32_t CanonicalizeNonZero(std::uint32_t value, std::uint32_t minimum, std::uint32_t maximum) { |
1699 | 85.9k | if (value == 0) { |
1700 | 34.5k | return 0; |
1701 | 34.5k | } |
1702 | 51.3k | return std::max(minimum, std::min(value, maximum)); |
1703 | 85.9k | } |
1704 | | |
1705 | | /// Keep the timing target on a protocol the timing run mode can actually |
1706 | | /// drive. TLS setup has its own cost profile and would obscure whether |
1707 | | /// backpressure mutations are exploring curl's send/receive state machines |
1708 | | /// effectively. Only WebSocket has a plaintext peer in kProtocolCoverage mode, |
1709 | | /// so WSS folds onto WS; every other scheme — including the mail, MQTT, and |
1710 | | /// file-transfer families whose peers are gated on their dedicated run modes — |
1711 | | /// falls back to the always-served HTTP peer rather than leaving the runner |
1712 | | /// without a transport. |
1713 | 33.9k | curl::fuzzer::proto::Scheme PlaintextScheme(curl::fuzzer::proto::Scheme scheme) { |
1714 | 33.9k | switch (scheme) { |
1715 | 6.43k | case curl::fuzzer::proto::SCHEME_WS: |
1716 | 6.44k | case curl::fuzzer::proto::SCHEME_WSS: |
1717 | 6.44k | return curl::fuzzer::proto::SCHEME_WS; |
1718 | 27.1k | case curl::fuzzer::proto::SCHEME_HTTP: |
1719 | 27.1k | case curl::fuzzer::proto::SCHEME_HTTPS: |
1720 | 27.1k | case curl::fuzzer::proto::SCHEME_TELNET: |
1721 | 27.1k | case curl::fuzzer::proto::SCHEME_FTP: |
1722 | 27.2k | case curl::fuzzer::proto::SCHEME_TFTP: |
1723 | 27.2k | case curl::fuzzer::proto::SCHEME_DICT: |
1724 | 27.2k | case curl::fuzzer::proto::SCHEME_FILE: |
1725 | 27.3k | case curl::fuzzer::proto::SCHEME_UNSPECIFIED: |
1726 | 27.5k | default: |
1727 | 27.5k | return curl::fuzzer::proto::SCHEME_HTTP; |
1728 | 33.9k | } |
1729 | 33.9k | } |
1730 | | |
1731 | | /// Remove timing controls from every connection the structured message can |
1732 | | /// carry. Clearing only the primary script would let a mutated redirect turn a |
1733 | | /// fixed fast lane into the timed drive loop after its second socket opens. |
1734 | 243k | void ClearAllBackpressure(curl::fuzzer::proto::Scenario* scenario) { |
1735 | 243k | if (scenario->has_connection()) { |
1736 | 243k | scenario->mutable_connection()->clear_backpressure(); |
1737 | 243k | } |
1738 | 243k | for (auto& connection : *scenario->mutable_subsequent_connections()) { |
1739 | 96.8k | connection.clear_backpressure(); |
1740 | 96.8k | } |
1741 | 243k | } |
1742 | | |
1743 | | /// Clamp one explicitly pressure-bearing follow-on script to the same useful |
1744 | | /// ranges as the timing lane's primary connection. An absent configuration is |
1745 | | /// left absent so merely adding a redirect response does not add waits. |
1746 | 19.6k | void CanonicalizeOptionalBackpressure(curl::fuzzer::proto::Connection* connection) { |
1747 | 19.6k | if (!connection->has_backpressure()) { |
1748 | 11.0k | return; |
1749 | 11.0k | } |
1750 | 8.59k | auto* backpressure = connection->mutable_backpressure(); |
1751 | 8.59k | if (backpressure->recv_buf_bytes() == 0 && backpressure->drain_limit() != 0) { |
1752 | 13 | backpressure->set_recv_buf_bytes(kDefaultBackpressureBufferBytes); |
1753 | 8.57k | } else { |
1754 | 8.57k | backpressure->set_recv_buf_bytes( |
1755 | 8.57k | CanonicalizeNonZero(backpressure->recv_buf_bytes(), kMinBackpressureBufferBytes, kMaxBackpressureBufferBytes)); |
1756 | 8.57k | } |
1757 | 8.59k | backpressure->set_drain_limit(CanonicalizeNonZero(backpressure->drain_limit(), 1, kMaxDrainBytesPerIteration)); |
1758 | 8.59k | } |
1759 | | |
1760 | | /// Keep mail pressure cheap and deterministic: only a small receive buffer is |
1761 | | /// meaningful to the immediate-service loop. Drain throttling belongs to the |
1762 | | /// timing lane, and a zero receive-buffer request is no pressure at all. |
1763 | 21.2k | void CanonicalizeMailBackpressure(curl::fuzzer::proto::Connection* connection) { |
1764 | 21.2k | if (!connection->has_backpressure()) { |
1765 | 19.9k | return; |
1766 | 19.9k | } |
1767 | 1.33k | auto* backpressure = connection->mutable_backpressure(); |
1768 | 1.33k | if (backpressure->recv_buf_bytes() == 0) { |
1769 | 4 | connection->clear_backpressure(); |
1770 | 4 | return; |
1771 | 4 | } |
1772 | 1.32k | backpressure->set_recv_buf_bytes( |
1773 | 1.32k | CanonicalizeNonZero(backpressure->recv_buf_bytes(), kMinBackpressureBufferBytes, kMaxBackpressureBufferBytes)); |
1774 | 1.32k | backpressure->clear_drain_limit(); |
1775 | 1.32k | } |
1776 | | |
1777 | | /// Canonicalize the fields that determine which server and drive-loop policy |
1778 | | /// execute. Fast targets normally discard backpressure because one mutated |
1779 | | /// non-zero scalar otherwise opts an ordinary input into hundreds of timed |
1780 | | /// waits; mail retains only recv-buffer pressure. The timing target keeps both |
1781 | | /// controls and guarantees a non-default buffer setting. |
1782 | | void ApplyLanePolicy(curl::fuzzer::proto::Scenario* scenario, TargetProfile profile, |
1783 | 623k | ConditionalEligibilityPruner prune_conditional_eligibility) { |
1784 | 623k | if (scenario == nullptr) { |
1785 | 0 | return; |
1786 | 0 | } |
1787 | | |
1788 | 623k | if (profile == TargetProfile::kCompatibility) { |
1789 | | // The original target's existing corpus predates profile splitting. A |
1790 | | // no-op here makes the type safe to pass around while its binary continues |
1791 | | // to omit postprocessor registration altogether. The append-only FTP/FTPS |
1792 | | // and TFTP scheme values do not justify rewriting historical mixed-lane |
1793 | | // inputs. |
1794 | 0 | return; |
1795 | 0 | } |
1796 | | |
1797 | | // Only FastFile may turn protobuf bytes into a local descriptor. Generated |
1798 | | // profiles already enforce this ownership; repeat it for direct callers of |
1799 | | // the full runtime Scenario before any generic bounds inspect the field. |
1800 | 623k | if (profile != TargetProfile::kFastFile) { |
1801 | 615k | scenario->clear_file_source(); |
1802 | 615k | } |
1803 | | |
1804 | | // The nested selector belongs exclusively to the HTTPS CONNECT proxy lane. |
1805 | | // Compatibility returned above and therefore preserves accumulated inputs; |
1806 | | // every unrelated fixed lane drops work its peer cannot observe. |
1807 | 623k | if (profile != TargetProfile::kH2Proxy) { |
1808 | 596k | scenario->mutable_connection()->clear_proxy_protocol(); |
1809 | 596k | for (auto& connection : *scenario->mutable_subsequent_connections()) { |
1810 | 151k | connection.clear_proxy_protocol(); |
1811 | 151k | } |
1812 | 596k | } |
1813 | | |
1814 | | // MQTT is append-only as well. No other fixed lane may reinterpret one of |
1815 | | // its packet scripts, so clear the selector before the lane-specific early |
1816 | | // paths install their own scheme. Compatibility returned above and keeps |
1817 | | // historical unknown-field semantics. |
1818 | 623k | if (profile != TargetProfile::kFastMqtt && scenario->scheme() == curl::fuzzer::proto::SCHEME_MQTT) { |
1819 | 11 | scenario->clear_scheme(); |
1820 | 11 | } |
1821 | | |
1822 | | // DICT is append-only too. Only the dedicated lane may reinterpret a lookup |
1823 | | // script; every other fixed lane clears the selector before installing its |
1824 | | // own scheme. |
1825 | 623k | if (profile != TargetProfile::kFastDict && scenario->scheme() == curl::fuzzer::proto::SCHEME_DICT) { |
1826 | 11 | scenario->clear_scheme(); |
1827 | 11 | } |
1828 | | |
1829 | | // FILE is append-only as well. Other fixed lanes must not inherit a local |
1830 | | // filesystem selector from a corpus input; only the dedicated lane may run |
1831 | | // the peerless file:// path. |
1832 | 623k | if (profile != TargetProfile::kFastFile && scenario->scheme() == curl::fuzzer::proto::SCHEME_FILE) { |
1833 | 22 | scenario->clear_scheme(); |
1834 | 22 | } |
1835 | | |
1836 | | // LDAP and LDAPS are append-only too. Only the fixed BER lane may turn one |
1837 | | // of their scripted bind/search exchanges into a live OpenLDAP session. |
1838 | 623k | if (profile != TargetProfile::kFastLdap && (scenario->scheme() == curl::fuzzer::proto::SCHEME_LDAP || |
1839 | 610k | scenario->scheme() == curl::fuzzer::proto::SCHEME_LDAPS)) { |
1840 | 22 | scenario->clear_scheme(); |
1841 | 22 | } |
1842 | | |
1843 | | // RTSP is append-only too. Keep its selector away from every fixed lane |
1844 | | // that cannot service a request-aligned RTSP exchange. Static option |
1845 | | // membership is carried by each generated profile descriptor. |
1846 | 623k | if (profile != TargetProfile::kFastRtsp && scenario->scheme() == curl::fuzzer::proto::SCHEME_RTSP) { |
1847 | 13 | scenario->clear_scheme(); |
1848 | 13 | } |
1849 | | // FTPS is append-only too. Only the fixed FTP lane may turn one of its |
1850 | | // scenarios into a TLS-wrapped control/data exchange. |
1851 | 623k | if (profile != TargetProfile::kFastFtp && scenario->scheme() == curl::fuzzer::proto::SCHEME_FTPS) { |
1852 | 23 | scenario->clear_scheme(); |
1853 | 23 | } |
1854 | | |
1855 | | // IPFS/IPNS are append-only as well. Their identifiers and gateway paths |
1856 | | // would be inert in every other fixed lane, so clear the selector before |
1857 | | // the lane-specific early paths install their own scheme. |
1858 | 623k | if (profile != TargetProfile::kFastIpfs && (scenario->scheme() == curl::fuzzer::proto::SCHEME_IPFS || |
1859 | 599k | scenario->scheme() == curl::fuzzer::proto::SCHEME_IPNS)) { |
1860 | 19 | scenario->clear_scheme(); |
1861 | 19 | } |
1862 | | |
1863 | | // Accepted server push adds a harness-owned easy handle and therefore |
1864 | | // belongs only in the fixed H2 origin lanes. Compatibility remains a no-op |
1865 | | // above so accumulated mixed corpus entries keep their wire meaning. |
1866 | 623k | if (profile != TargetProfile::kHttpsH2 && profile != TargetProfile::kFastHttp2) { |
1867 | 560k | scenario->clear_accept_h2_push(); |
1868 | 560k | } |
1869 | | |
1870 | | // Only the dedicated TLS and QUIC peers consume a certificate-chain |
1871 | | // selector. Remove it before protocol-specific early returns so other fixed |
1872 | | // targets do not spend mutations on inert TLS server state. |
1873 | 623k | if (profile != TargetProfile::kFastHttps && profile != TargetProfile::kHttpsH2 && |
1874 | 512k | profile != TargetProfile::kFastHttp3 && profile != TargetProfile::kFastSecureWebSocket) { |
1875 | 477k | scenario->clear_tls_certificate_chain(); |
1876 | 477k | } |
1877 | | |
1878 | | // Only the dedicated TLS HTTP/2 origin consumes the group selector. The |
1879 | | // compatibility profile returned above so unknown fields remain stable. |
1880 | 623k | if (profile != TargetProfile::kHttpsH2) { |
1881 | 594k | scenario->clear_tls_group_profile(); |
1882 | 594k | } |
1883 | | |
1884 | | // Field 13 is append-only so the compatibility target can round-trip it, |
1885 | | // but every other fixed lane must discard work its peer cannot consume. |
1886 | 623k | if (profile != TargetProfile::kFastHttp3) { |
1887 | 608k | scenario->clear_http3_plan(); |
1888 | 608k | } |
1889 | | |
1890 | 623k | const bool resolver_uses_doh = profile == TargetProfile::kResolver && scenario->has_doh(); |
1891 | 623k | if (profile != TargetProfile::kHttpsH2 && profile != TargetProfile::kFastHttp2 && !resolver_uses_doh) { |
1892 | 560k | scenario->clear_http2_plan(); |
1893 | 560k | } |
1894 | | |
1895 | 623k | const bool deep_http_haproxy = profile == TargetProfile::kDeepHttp && |
1896 | 43.5k | scenario->http_transport_mode() == curl::fuzzer::proto::HTTP_TRANSPORT_CONNECT_PROXY; |
1897 | 623k | if (profile != TargetProfile::kProxyTransport) { |
1898 | 595k | scenario->clear_socks_proxy_mode(); |
1899 | 595k | if (!deep_http_haproxy) { |
1900 | 592k | scenario->clear_haproxy_protocol(); |
1901 | 592k | } |
1902 | 595k | } |
1903 | | |
1904 | | // StartTLS is a correlated LDAP transport mode rather than a transferable |
1905 | | // scalar option. Other fixed lanes discard it before their early returns. |
1906 | 623k | if (profile != TargetProfile::kFastLdap) { |
1907 | 610k | scenario->clear_ldap_starttls(); |
1908 | 610k | } |
1909 | | |
1910 | 623k | if (profile != TargetProfile::kFastPop3) { |
1911 | 615k | scenario->clear_pop3_starttls_filter_allocation_failure(); |
1912 | 615k | } |
1913 | | |
1914 | 623k | if (profile != TargetProfile::kFastFtp) { |
1915 | 608k | scenario->clear_ftp_auth_tls_filter_allocation_failure(); |
1916 | 608k | } |
1917 | | |
1918 | 623k | if (profile != TargetProfile::kFastGopher) { |
1919 | 605k | scenario->clear_gopher_probe_mode(); |
1920 | 605k | } |
1921 | | |
1922 | 623k | if (profile != TargetProfile::kFastRtsp) { |
1923 | 608k | scenario->clear_rtsp_probe_mode(); |
1924 | 608k | } |
1925 | | |
1926 | 623k | if (profile != TargetProfile::kFastMqtt) { |
1927 | 615k | scenario->clear_mqtt_probe_mode(); |
1928 | 615k | } |
1929 | | |
1930 | 623k | if (profile != TargetProfile::kFastSmtp) { |
1931 | 611k | scenario->clear_smtp_probe_mode(); |
1932 | 611k | } |
1933 | | |
1934 | 623k | if (profile != TargetProfile::kFastHttp2) { |
1935 | 589k | scenario->clear_http2_connect_flush_probe(); |
1936 | 589k | } |
1937 | | |
1938 | 623k | if (profile != TargetProfile::kDeepHttp) { |
1939 | 580k | scenario->clear_http_transport_mode(); |
1940 | 580k | scenario->clear_proxy_socket_option_mode(); |
1941 | 580k | } |
1942 | | |
1943 | 623k | if (profile != TargetProfile::kResolver) { |
1944 | 602k | scenario->clear_resolve_entries(); |
1945 | 602k | scenario->clear_happy_eyeballs(); |
1946 | 602k | scenario->clear_doh(); |
1947 | 602k | scenario->clear_resolver_mode(); |
1948 | 602k | } |
1949 | | |
1950 | | // SMTP's schema-native recipient list has no meaning in another protocol's |
1951 | | // exchange. Clearing it before early returns keeps other fixed lanes from |
1952 | | // carrying inert envelope work. |
1953 | 623k | if (profile != TargetProfile::kFastSmtp) { |
1954 | 611k | scenario->clear_mail_rcpt(); |
1955 | 611k | } |
1956 | | |
1957 | | // Only these protocol peers currently interleave zero-timeout public multi |
1958 | | // polling with immediate service of their live connection. |
1959 | | // Keep the opt-in out of fixed lanes whose driver cannot honor that timing |
1960 | | // contract; compatibility returned above and preserves its wire input. |
1961 | 623k | if (profile != TargetProfile::kFastSmtp && profile != TargetProfile::kFastImap && |
1962 | 598k | profile != TargetProfile::kFastPop3 && profile != TargetProfile::kFastFtp && |
1963 | 575k | profile != TargetProfile::kFastMqtt && profile != TargetProfile::kProxyTransport && |
1964 | 538k | profile != TargetProfile::kDeepHttp) { |
1965 | 495k | scenario->clear_probe_multi_pollset(); |
1966 | 495k | } |
1967 | | |
1968 | | // Direct forwarding changes the H2 proxy stream from CONNECT authority-form |
1969 | | // to an absolute-form origin request. No other peer implements that shape. |
1970 | 623k | if (profile != TargetProfile::kH2Proxy) { |
1971 | 596k | scenario->clear_h2_forward_proxy(); |
1972 | 596k | } |
1973 | | |
1974 | | // Anonymous parser files add syscalls and line parsing that belong only in |
1975 | | // the deep HTTP lane. Clear them before every protocol-specific early path |
1976 | | // so fast targets never pay to normalize content they cannot consume. |
1977 | 623k | if (profile != TargetProfile::kDeepHttp) { |
1978 | 580k | scenario->clear_cookie_file(); |
1979 | 580k | scenario->clear_altsvc_file(); |
1980 | 580k | scenario->clear_hsts_file(); |
1981 | 580k | scenario->clear_netrc_file(); |
1982 | 580k | } |
1983 | | |
1984 | | // A CRL is useful only when the target completes a real origin TLS setup. |
1985 | | // Keep malformed or oversized CRLs from turning every other lane into an |
1986 | | // early TLS-option failure. |
1987 | 623k | if (profile != TargetProfile::kFastHttps) { |
1988 | 542k | scenario->clear_crl_file(); |
1989 | 542k | scenario->clear_tls_client_credential_profile(); |
1990 | 542k | scenario->clear_tls_handshake_profile(); |
1991 | 542k | } |
1992 | | |
1993 | 623k | if (profile == TargetProfile::kFastHttp3) { |
1994 | 15.3k | scenario->set_scheme(curl::fuzzer::proto::SCHEME_HTTPS); |
1995 | 15.3k | RemoveIgnoredHttp3Shape(scenario); |
1996 | 15.3k | PruneAndBoundScenarioShape(scenario, profile, prune_conditional_eligibility); |
1997 | | // The ordinary QUIC peer consumes Http3Plan and has no use for a stream |
1998 | | // response. CONNECT-UDP proxy mode instead feeds the retained Connection |
1999 | | // bytes to curl's HTTP/1.1 proxy state machine and capsule filter. |
2000 | 15.3k | if (!scenario->http3_plan().use_h1_connect_udp_proxy()) { |
2001 | 5.87k | scenario->clear_connection(); |
2002 | 5.87k | } |
2003 | 15.3k | BoundHttp3PlanShape(scenario->mutable_http3_plan()); |
2004 | 15.3k | CanonicalizeHttp3Authority(scenario); |
2005 | 15.3k | CanonicalizeTlsCertificateChain(scenario); |
2006 | 15.3k | return; |
2007 | 15.3k | } |
2008 | | |
2009 | 608k | if (profile == TargetProfile::kFastTelnet) { |
2010 | | // Set the scheme before general bounds so the TELNET-specific upload and |
2011 | | // PAUSE budgets are selected rather than event-driven compatibility ones. |
2012 | 9.08k | scenario->set_scheme(curl::fuzzer::proto::SCHEME_TELNET); |
2013 | 9.08k | RemoveApiOnlyShape(scenario); |
2014 | 9.08k | RemoveMultiOnlyShape(scenario); |
2015 | 9.08k | RemoveNonTelnetShape(scenario); |
2016 | 9.08k | PruneAndBoundScenarioShape(scenario, profile, prune_conditional_eligibility); |
2017 | 9.08k | BoundTelnetResponse(scenario->mutable_connection()); |
2018 | 9.08k | return; |
2019 | 9.08k | } |
2020 | | |
2021 | 599k | if (profile == TargetProfile::kFastHttp) { |
2022 | 33.6k | scenario->set_scheme(curl::fuzzer::proto::SCHEME_HTTP); |
2023 | 33.6k | RemoveApiOnlyShape(scenario); |
2024 | 33.6k | RemoveMultiOnlyShape(scenario); |
2025 | 33.6k | RemoveTelnetOnlyShape(scenario); |
2026 | 33.6k | RemoveDeepHttpShape(scenario); |
2027 | 33.6k | CanonicalizeFastHttpVersion(scenario); |
2028 | 33.6k | PruneAndBoundScenarioShape(scenario, profile, prune_conditional_eligibility); |
2029 | 33.6k | return; |
2030 | 33.6k | } |
2031 | | |
2032 | 565k | if (profile == TargetProfile::kH2Proxy) { |
2033 | 27.0k | scenario->set_scheme(curl::fuzzer::proto::SCHEME_HTTP); |
2034 | 27.0k | RemoveApiOnlyShape(scenario); |
2035 | 27.0k | RemoveMultiOnlyShape(scenario); |
2036 | 27.0k | RemoveTelnetOnlyShape(scenario); |
2037 | 27.0k | RemoveIgnoredH2ProxyShape(scenario); |
2038 | 27.0k | switch (scenario->connection().proxy_protocol()) { |
2039 | 25.5k | case curl::fuzzer::proto::PROXY_PROTOCOL_HTTP2: |
2040 | 27.0k | case curl::fuzzer::proto::PROXY_PROTOCOL_HTTP1: |
2041 | 27.0k | break; |
2042 | 2 | default: |
2043 | 2 | scenario->mutable_connection()->set_proxy_protocol(curl::fuzzer::proto::PROXY_PROTOCOL_HTTP2); |
2044 | 2 | break; |
2045 | 27.0k | } |
2046 | 27.0k | if (scenario->connection().proxy_protocol() == curl::fuzzer::proto::PROXY_PROTOCOL_HTTP1) { |
2047 | 1.48k | scenario->clear_h2_forward_proxy(); |
2048 | 1.48k | } |
2049 | 27.0k | PruneAndBoundScenarioShape(scenario, profile, prune_conditional_eligibility); |
2050 | 27.0k | CanonicalizeH2ProxyOriginAuthority(scenario); |
2051 | 27.0k | return; |
2052 | 27.0k | } |
2053 | | |
2054 | 538k | if (profile == TargetProfile::kHttpsH2 || profile == TargetProfile::kFastHttp2) { |
2055 | 63.5k | scenario->set_scheme(profile == TargetProfile::kHttpsH2 ? curl::fuzzer::proto::SCHEME_HTTPS |
2056 | 63.5k | : curl::fuzzer::proto::SCHEME_HTTP); |
2057 | 63.5k | RemoveApiOnlyShape(scenario); |
2058 | 63.5k | RemoveMultiOnlyShape(scenario); |
2059 | 63.5k | RemoveTelnetOnlyShape(scenario); |
2060 | 63.5k | RemoveIgnoredH2ProxyShape(scenario); |
2061 | 63.5k | PruneAndBoundScenarioShape(scenario, profile, prune_conditional_eligibility); |
2062 | 63.5k | if (scenario->http2_connect_flush_probe()) { |
2063 | | // CONNECT_ONLY supplies no HTTP response plan. Clear competing peer |
2064 | | // bytes so mutations stay focused on the connection-filter lifecycle. |
2065 | 306 | scenario->clear_http2_plan(); |
2066 | 306 | scenario->clear_connection(); |
2067 | 306 | scenario->clear_subsequent_connections(); |
2068 | 306 | } |
2069 | 63.5k | if (scenario->has_http2_plan()) { |
2070 | 36.0k | auto* connection = scenario->mutable_connection(); |
2071 | 36.0k | connection->clear_initial_response(); |
2072 | 36.0k | connection->clear_on_readable(); |
2073 | 36.0k | connection->clear_server_frames(); |
2074 | 36.0k | BoundHttp2PlanShape(scenario->mutable_http2_plan()); |
2075 | 36.0k | } |
2076 | 63.5k | CanonicalizeTlsAuthority(scenario); |
2077 | 63.5k | if (profile == TargetProfile::kHttpsH2) { |
2078 | 29.5k | CanonicalizeTlsCertificateChain(scenario); |
2079 | 29.5k | CanonicalizeTlsGroupProfile(scenario); |
2080 | 29.5k | } |
2081 | 63.5k | return; |
2082 | 63.5k | } |
2083 | | |
2084 | 475k | if (profile == TargetProfile::kProxyTransport) { |
2085 | 28.3k | scenario->set_scheme(curl::fuzzer::proto::SCHEME_HTTP); |
2086 | 28.3k | switch (scenario->socks_proxy_mode()) { |
2087 | 25.7k | case curl::fuzzer::proto::SOCKS_PROXY_SOCKS4: |
2088 | 27.6k | case curl::fuzzer::proto::SOCKS_PROXY_SOCKS4A: |
2089 | 28.1k | case curl::fuzzer::proto::SOCKS_PROXY_SOCKS5: |
2090 | 28.3k | case curl::fuzzer::proto::SOCKS_PROXY_SOCKS5_HOSTNAME: |
2091 | 28.3k | break; |
2092 | 33 | default: |
2093 | 33 | scenario->set_socks_proxy_mode(curl::fuzzer::proto::SOCKS_PROXY_SOCKS4); |
2094 | 33 | break; |
2095 | 28.3k | } |
2096 | 28.3k | RemoveApiOnlyShape(scenario); |
2097 | 28.3k | RemoveMultiOnlyShape(scenario); |
2098 | 28.3k | RemoveTelnetOnlyShape(scenario); |
2099 | 28.3k | RemoveDeepHttpShape(scenario); |
2100 | 28.3k | scenario->mutable_connection()->clear_initial_response(); |
2101 | 28.3k | PruneAndBoundScenarioShape(scenario, profile, prune_conditional_eligibility); |
2102 | 28.3k | CanonicalizeSocksAuthority(scenario); |
2103 | 28.3k | return; |
2104 | 28.3k | } |
2105 | | |
2106 | 446k | if (profile == TargetProfile::kResolver) { |
2107 | | // The DoH variant owns the outer HTTPS exchange through a verified |
2108 | | // TLS/ALPN h2 peer, so its response is an Http2Plan rather than a raw |
2109 | | // stream script. The ordinary resolver lanes keep plaintext HTTP. |
2110 | 20.9k | switch (scenario->resolver_mode()) { |
2111 | 16.1k | case curl::fuzzer::proto::RESOLVER_MODE_DEFAULT: |
2112 | 16.8k | case curl::fuzzer::proto::RESOLVER_MODE_THREADED_POSITIVE: |
2113 | 16.9k | case curl::fuzzer::proto::RESOLVER_MODE_THREADED_NEGATIVE: |
2114 | 17.3k | case curl::fuzzer::proto::RESOLVER_MODE_THREADED_LINK_LOCAL: |
2115 | 17.9k | case curl::fuzzer::proto::RESOLVER_MODE_UNIX_SOCKET: |
2116 | 18.9k | case curl::fuzzer::proto::RESOLVER_MODE_THREADED_PARTIAL: |
2117 | 20.4k | case curl::fuzzer::proto::RESOLVER_MODE_GLOBAL_LIFECYCLE: |
2118 | 20.9k | case curl::fuzzer::proto::RESOLVER_MODE_THREADED_QUEUED_CANCEL: |
2119 | 20.9k | break; |
2120 | 35 | default: |
2121 | 35 | scenario->clear_resolver_mode(); |
2122 | 35 | break; |
2123 | 20.9k | } |
2124 | 20.9k | if (scenario->has_doh()) { |
2125 | 10 | switch (scenario->doh().response_mode()) { |
2126 | 6 | case curl::fuzzer::proto::DOH_RESPONSE_MODE_NORMAL: |
2127 | 8 | case curl::fuzzer::proto::DOH_RESPONSE_MODE_MALFORMED_DNS: |
2128 | 10 | case curl::fuzzer::proto::DOH_RESPONSE_MODE_HTTP_ERROR: |
2129 | 10 | break; |
2130 | 0 | default: |
2131 | 0 | scenario->mutable_doh()->set_response_mode(curl::fuzzer::proto::DOH_RESPONSE_MODE_NORMAL); |
2132 | 0 | break; |
2133 | 10 | } |
2134 | 10 | } |
2135 | 20.9k | const bool fixed_resolver_mode = scenario->resolver_mode() != curl::fuzzer::proto::RESOLVER_MODE_DEFAULT; |
2136 | 20.9k | if (fixed_resolver_mode) { |
2137 | 4.76k | scenario->clear_resolve_entries(); |
2138 | 4.76k | scenario->clear_happy_eyeballs(); |
2139 | 4.76k | scenario->clear_doh(); |
2140 | 4.76k | } |
2141 | 20.9k | const bool uses_doh = scenario->has_doh(); |
2142 | 20.9k | scenario->set_scheme(uses_doh ? curl::fuzzer::proto::SCHEME_HTTPS : curl::fuzzer::proto::SCHEME_HTTP); |
2143 | 20.9k | RemoveApiOnlyShape(scenario); |
2144 | 20.9k | RemoveMultiOnlyShape(scenario); |
2145 | 20.9k | RemoveTelnetOnlyShape(scenario); |
2146 | 20.9k | RemoveDeepHttpShape(scenario); |
2147 | | // The generic fast-lane pruning above removes fuzz-controlled timing |
2148 | | // knobs. Threaded resolver modes add back one fixed marker so their |
2149 | | // bounded drive performs a pollset probe and short fdset waits while the |
2150 | | // target-local resolver work is outstanding. |
2151 | 20.9k | if (IsThreadedResolverMode(scenario->resolver_mode())) { |
2152 | 2.60k | scenario->mutable_connection()->mutable_backpressure()->set_drain_limit(1); |
2153 | 2.60k | } |
2154 | 20.9k | if (scenario->resolver_mode() == curl::fuzzer::proto::RESOLVER_MODE_THREADED_QUEUED_CANCEL) { |
2155 | | // The runner observes the pool's public THREADS trace after releasing |
2156 | | // its lookup gate. Seeing an idle worker proves it entered the configured |
2157 | | // timed condition wait; mutated trace controls must not remove that |
2158 | | // lifecycle contract. |
2159 | 522 | scenario->set_trace_config("+THREADS"); |
2160 | 522 | } |
2161 | 20.9k | if (uses_doh) { |
2162 | | // CURLOPT_RESOLVE cannot carry an HTTPS record, and the responder owns |
2163 | | // both the address and HTTPS answers. Clearing the address entries keeps |
2164 | | // the DoH query on the only path that can reach the ALPN selector. |
2165 | 10 | scenario->clear_resolve_entries(); |
2166 | 10 | scenario->clear_happy_eyeballs(); |
2167 | 10 | if (scenario->has_http2_plan()) { |
2168 | 10 | auto* connection = scenario->mutable_connection(); |
2169 | 10 | connection->clear_initial_response(); |
2170 | 10 | connection->clear_on_readable(); |
2171 | 10 | connection->clear_server_frames(); |
2172 | 10 | BoundHttp2PlanShape(scenario->mutable_http2_plan()); |
2173 | 10 | } |
2174 | 20.9k | } else { |
2175 | 20.9k | scenario->clear_http2_plan(); |
2176 | 20.9k | BoundStringValues(scenario->mutable_resolve_entries(), scenario_limits::kMaxResolveEntries, |
2177 | 20.9k | scenario_limits::kMaxResolveEntryBytes); |
2178 | 20.9k | } |
2179 | 20.9k | PruneAndBoundScenarioShape(scenario, profile, prune_conditional_eligibility); |
2180 | 20.9k | CanonicalizeResolverAuthority(scenario); |
2181 | 20.9k | return; |
2182 | 20.9k | } |
2183 | | |
2184 | 425k | if (profile == TargetProfile::kFastFtp) { |
2185 | | // The same lane services plaintext FTP and implicit-TLS FTPS through one |
2186 | | // command/data parser. Preserve an explicitly supplied FTPS scheme so the |
2187 | | // seed and mutations can select the TLS peer; every other scheme falls |
2188 | | // back to the historical plaintext lane. |
2189 | 14.9k | const auto scheme = scenario->scheme(); |
2190 | 14.9k | const bool implicit_tls = scheme == curl::fuzzer::proto::SCHEME_FTPS; |
2191 | 14.9k | scenario->set_scheme(implicit_tls ? curl::fuzzer::proto::SCHEME_FTPS : curl::fuzzer::proto::SCHEME_FTP); |
2192 | 14.9k | if (implicit_tls) { |
2193 | 4.05k | scenario->clear_ftp_auth_tls_filter_allocation_failure(); |
2194 | 4.05k | } |
2195 | 14.9k | if (scenario->ftp_auth_tls_filter_allocation_failure()) { |
2196 | 8 | scenario->clear_fail_allocations(); |
2197 | 8 | } |
2198 | 14.9k | RemoveIgnoredFtpShape(scenario); |
2199 | 14.9k | CanonicalizeFtpOptionModes(scenario); |
2200 | 14.9k | PruneAndBoundScenarioShape(scenario, profile, prune_conditional_eligibility); |
2201 | 14.9k | CanonicalizeFtpAuthority(scenario); |
2202 | 14.9k | return; |
2203 | 14.9k | } |
2204 | | |
2205 | 410k | if (profile == TargetProfile::kFastTftp) { |
2206 | 4.77k | scenario->set_scheme(curl::fuzzer::proto::SCHEME_TFTP); |
2207 | 4.77k | RemoveIgnoredTftpShape(scenario); |
2208 | 4.77k | CanonicalizeTftpOptionModes(scenario); |
2209 | 4.77k | PruneAndBoundScenarioShape(scenario, profile, prune_conditional_eligibility); |
2210 | 4.77k | CanonicalizeTftpAuthority(scenario); |
2211 | 4.77k | return; |
2212 | 4.77k | } |
2213 | | |
2214 | 405k | if (profile == TargetProfile::kFastSmtp) { |
2215 | | // One command/reply parser services plaintext SMTP and implicit-TLS SMTPS. |
2216 | | // Preserve an explicitly supplied SMTPS scheme so the seed and mutations |
2217 | | // can select the TLS peer; every other scheme falls back to the historical |
2218 | | // plaintext lane. |
2219 | 12.0k | const auto scheme = scenario->scheme(); |
2220 | 12.0k | scenario->set_scheme(scheme == curl::fuzzer::proto::SCHEME_SMTPS ? curl::fuzzer::proto::SCHEME_SMTPS |
2221 | 12.0k | : curl::fuzzer::proto::SCHEME_SMTP); |
2222 | 12.0k | CanonicalizeSmtpProbeMode(scenario); |
2223 | 12.0k | if (scenario->scheme() == curl::fuzzer::proto::SCHEME_SMTPS) { |
2224 | 6.97k | scenario->clear_smtp_probe_mode(); |
2225 | 6.97k | } |
2226 | 12.0k | if (scenario->smtp_probe_mode() == curl::fuzzer::proto::SMTP_PROBE_STARTTLS_FILTER_ALLOCATION_FAILURE) { |
2227 | 2 | scenario->clear_fail_allocations(); |
2228 | 2 | } |
2229 | 12.0k | if (scenario->smtp_probe_mode() == curl::fuzzer::proto::SMTP_PROBE_SEND_BACKPRESSURE) { |
2230 | 2 | scenario->clear_mail_rcpt(); |
2231 | 2 | scenario->clear_upload(); |
2232 | 2 | scenario->clear_mime_post(); |
2233 | 2 | } |
2234 | 12.0k | RemoveIgnoredSmtpShape(scenario); |
2235 | 12.0k | PruneAndBoundScenarioShape(scenario, profile, prune_conditional_eligibility); |
2236 | 12.0k | if (scenario->smtp_probe_mode() == curl::fuzzer::proto::SMTP_PROBE_SEND_BACKPRESSURE) { |
2237 | 2 | scenario->set_probe_multi_pollset(true); |
2238 | 2 | auto* backpressure = scenario->mutable_connection()->mutable_backpressure(); |
2239 | 2 | backpressure->set_recv_buf_bytes(kSmtpProbeBufferBytes); |
2240 | 2 | backpressure->set_drain_limit(kSmtpProbeDrainBytes); |
2241 | 2 | } |
2242 | 12.0k | CanonicalizeSmtpAuthority(scenario); |
2243 | 12.0k | return; |
2244 | 12.0k | } |
2245 | | |
2246 | 393k | if (profile == TargetProfile::kFastImap) { |
2247 | | // Preserve an explicitly supplied IMAPS scheme so seeds and mutations can |
2248 | | // select the implicit-TLS peer; every other scheme falls back to the |
2249 | | // historical plaintext lane. Both values reuse this tag-aware parser. |
2250 | 12.9k | const auto scheme = scenario->scheme(); |
2251 | 12.9k | scenario->set_scheme(scheme == curl::fuzzer::proto::SCHEME_IMAPS ? curl::fuzzer::proto::SCHEME_IMAPS |
2252 | 12.9k | : curl::fuzzer::proto::SCHEME_IMAP); |
2253 | 12.9k | RemoveIgnoredImapShape(scenario); |
2254 | 12.9k | PruneAndBoundScenarioShape(scenario, profile, prune_conditional_eligibility); |
2255 | 12.9k | CanonicalizeMailBackpressure(scenario->mutable_connection()); |
2256 | 12.9k | CanonicalizeImapAuthority(scenario); |
2257 | 12.9k | return; |
2258 | 12.9k | } |
2259 | | |
2260 | 380k | if (profile == TargetProfile::kFastPop3) { |
2261 | | // Preserve an explicitly supplied POP3S scheme so seeds and mutations can |
2262 | | // select the implicit-TLS peer; every other scheme falls back to the |
2263 | | // historical plaintext lane. Both values reuse this status-line parser. |
2264 | 8.29k | const auto scheme = scenario->scheme(); |
2265 | 8.29k | scenario->set_scheme(scheme == curl::fuzzer::proto::SCHEME_POP3S ? curl::fuzzer::proto::SCHEME_POP3S |
2266 | 8.29k | : curl::fuzzer::proto::SCHEME_POP3); |
2267 | 8.29k | if (scenario->scheme() == curl::fuzzer::proto::SCHEME_POP3S) { |
2268 | 6.34k | scenario->clear_pop3_starttls_filter_allocation_failure(); |
2269 | 6.34k | } |
2270 | 8.29k | if (scenario->pop3_starttls_filter_allocation_failure()) { |
2271 | 422 | scenario->clear_fail_allocations(); |
2272 | 422 | } |
2273 | 8.29k | RemoveIgnoredPop3Shape(scenario); |
2274 | 8.29k | PruneAndBoundScenarioShape(scenario, profile, prune_conditional_eligibility); |
2275 | 8.29k | CanonicalizeMailBackpressure(scenario->mutable_connection()); |
2276 | 8.29k | CanonicalizePop3Authority(scenario); |
2277 | 8.29k | return; |
2278 | 8.29k | } |
2279 | | |
2280 | 372k | if (profile == TargetProfile::kFastMqtt) { |
2281 | | // The dedicated MQTT lane services both the plaintext and implicit-TLS |
2282 | | // variants through one packet-aware parser. Preserve an explicitly |
2283 | | // supplied MQTTS scheme so the seed and mutations can select the TLS peer; |
2284 | | // every other scheme falls back to the historical plaintext lane. |
2285 | 8.42k | CanonicalizeMqttProbeMode(scenario); |
2286 | 8.42k | const auto probe = scenario->mqtt_probe_mode(); |
2287 | 8.42k | const auto scheme = scenario->scheme(); |
2288 | 8.42k | scenario->set_scheme(probe == curl::fuzzer::proto::MQTT_PROBE_DEFAULT && scheme == curl::fuzzer::proto::SCHEME_MQTTS |
2289 | 8.42k | ? curl::fuzzer::proto::SCHEME_MQTTS |
2290 | 8.42k | : curl::fuzzer::proto::SCHEME_MQTT); |
2291 | 8.42k | RemoveIgnoredMqttShape(scenario); |
2292 | 8.42k | PruneAndBoundScenarioShape(scenario, profile, prune_conditional_eligibility); |
2293 | 8.42k | if (probe == curl::fuzzer::proto::MQTT_PROBE_SEND_BACKPRESSURE) { |
2294 | 2 | auto* backpressure = scenario->mutable_connection()->mutable_backpressure(); |
2295 | 2 | backpressure->set_recv_buf_bytes(kMqttProbeBufferBytes); |
2296 | 2 | backpressure->set_drain_limit(kMqttProbeDrainBytes); |
2297 | 2 | scenario->set_probe_multi_pollset(true); |
2298 | 2 | } |
2299 | 8.42k | CanonicalizeMqttAuthority(scenario); |
2300 | 8.42k | return; |
2301 | 8.42k | } |
2302 | | |
2303 | 364k | if (profile == TargetProfile::kFastDict) { |
2304 | 6.07k | scenario->set_scheme(curl::fuzzer::proto::SCHEME_DICT); |
2305 | 6.07k | RemoveIgnoredDictShape(scenario); |
2306 | 6.07k | PruneAndBoundScenarioShape(scenario, profile, prune_conditional_eligibility); |
2307 | 6.07k | CanonicalizeDictAuthority(scenario); |
2308 | 6.07k | return; |
2309 | 6.07k | } |
2310 | | |
2311 | 358k | if (profile == TargetProfile::kFastGopher) { |
2312 | 17.9k | CanonicalizeGopherProbeMode(scenario); |
2313 | 17.9k | const auto probe = scenario->gopher_probe_mode(); |
2314 | 17.9k | if (probe == curl::fuzzer::proto::GOPHER_PROBE_TLS_SESSION_KEY_LIMIT) { |
2315 | 32 | scenario->set_scheme(curl::fuzzer::proto::SCHEME_GOPHERS); |
2316 | 17.8k | } else if (probe != curl::fuzzer::proto::GOPHER_PROBE_DEFAULT) { |
2317 | 266 | scenario->set_scheme(curl::fuzzer::proto::SCHEME_GOPHER); |
2318 | 17.6k | } else { |
2319 | 17.6k | scenario->set_scheme(scenario->scheme() == curl::fuzzer::proto::SCHEME_GOPHERS |
2320 | 17.6k | ? curl::fuzzer::proto::SCHEME_GOPHERS |
2321 | 17.6k | : curl::fuzzer::proto::SCHEME_GOPHER); |
2322 | 17.6k | } |
2323 | 17.9k | RemoveIgnoredGopherShape(scenario); |
2324 | 17.9k | PruneAndBoundScenarioShape(scenario, profile, prune_conditional_eligibility); |
2325 | 17.9k | if (probe == curl::fuzzer::proto::GOPHER_PROBE_TLS_SESSION_KEY_LIMIT) { |
2326 | 32 | scenario->set_host_path(std::string(kGopherTlsPeerKeyHostBytes, 'g') + "/1/session-key-limit"); |
2327 | 17.8k | } else { |
2328 | 17.8k | CanonicalizeTlsAuthority(scenario); |
2329 | 17.8k | } |
2330 | 17.9k | return; |
2331 | 17.9k | } |
2332 | | |
2333 | 340k | if (profile == TargetProfile::kFastFile) { |
2334 | 8.26k | scenario->set_scheme(curl::fuzzer::proto::SCHEME_FILE); |
2335 | 8.26k | scenario->clear_host_path(); |
2336 | 8.26k | RemoveIgnoredFileShape(scenario); |
2337 | 8.26k | PruneAndBoundScenarioShape(scenario, profile, prune_conditional_eligibility); |
2338 | 8.26k | if (scenario->file_source().size() > scenario_limits::kMaxFileInputBytes) { |
2339 | 0 | scenario->mutable_file_source()->resize(scenario_limits::kMaxFileInputBytes); |
2340 | 0 | } |
2341 | 8.26k | return; |
2342 | 8.26k | } |
2343 | | |
2344 | 331k | if (profile == TargetProfile::kFastLdap) { |
2345 | | // The single LDAP target services plaintext LDAP and implicit-TLS LDAPS |
2346 | | // through one BER parser. Preserve an explicitly supplied LDAPS scheme so |
2347 | | // the seed and mutations can select the TLS peer; every other scheme falls |
2348 | | // back to the historical plaintext lane. |
2349 | 13.3k | const auto scheme = scenario->scheme(); |
2350 | 13.3k | scenario->set_scheme(scheme == curl::fuzzer::proto::SCHEME_LDAPS ? curl::fuzzer::proto::SCHEME_LDAPS |
2351 | 13.3k | : curl::fuzzer::proto::SCHEME_LDAP); |
2352 | 13.3k | if (scenario->scheme() == curl::fuzzer::proto::SCHEME_LDAPS) { |
2353 | 9.05k | scenario->clear_ldap_starttls(); |
2354 | 9.05k | } |
2355 | 13.3k | RemoveIgnoredLdapShape(scenario); |
2356 | 13.3k | PruneAndBoundScenarioShape(scenario, profile, prune_conditional_eligibility); |
2357 | 13.3k | CanonicalizeLdapAuthority(scenario); |
2358 | 13.3k | return; |
2359 | 13.3k | } |
2360 | | |
2361 | 318k | if (profile == TargetProfile::kFastRtsp) { |
2362 | 15.7k | scenario->set_scheme(curl::fuzzer::proto::SCHEME_RTSP); |
2363 | 15.7k | RemoveIgnoredRtspShape(scenario); |
2364 | 15.7k | CanonicalizeRtspOptionModes(scenario); |
2365 | 15.7k | CanonicalizeRtspProbeMode(scenario); |
2366 | 15.7k | PruneAndBoundScenarioShape(scenario, profile, prune_conditional_eligibility); |
2367 | 15.7k | CanonicalizeRtspAuthority(scenario); |
2368 | 15.7k | return; |
2369 | 15.7k | } |
2370 | | |
2371 | 302k | if (profile == TargetProfile::kFastIpfs) { |
2372 | | // Preserve an explicitly selected IPNS name; every other pre-policy value |
2373 | | // falls back to the historical IPFS lane so one binary covers both. |
2374 | 24.2k | scenario->set_scheme(scenario->scheme() == curl::fuzzer::proto::SCHEME_IPNS ? curl::fuzzer::proto::SCHEME_IPNS |
2375 | 24.2k | : curl::fuzzer::proto::SCHEME_IPFS); |
2376 | 24.2k | RemoveIgnoredIpfsShape(scenario); |
2377 | 24.2k | CanonicalizeFastHttpVersion(scenario); |
2378 | 24.2k | PruneAndBoundScenarioShape(scenario, profile, prune_conditional_eligibility); |
2379 | 24.2k | CanonicalizeIpfsAuthority(scenario); |
2380 | 24.2k | return; |
2381 | 24.2k | } |
2382 | | |
2383 | | // Select the lane's scheme before applying scheme-sensitive upload bounds. |
2384 | | // The scheme field is itself mutable, so bounding first could accidentally |
2385 | | // give an HTTP/WS case TELNET's smaller payload budget merely because that |
2386 | | // was the input's pre-policy value. |
2387 | 278k | switch (profile) { |
2388 | 0 | case TargetProfile::kCompatibility: |
2389 | 0 | return; |
2390 | 43.5k | case TargetProfile::kDeepHttp: |
2391 | 43.5k | scenario->set_scheme(curl::fuzzer::proto::SCHEME_HTTP); |
2392 | 43.5k | break; |
2393 | 39.9k | case TargetProfile::kApi: |
2394 | 39.9k | scenario->set_scheme(curl::fuzzer::proto::SCHEME_HTTP); |
2395 | 39.9k | break; |
2396 | 36.4k | case TargetProfile::kMulti: |
2397 | 36.4k | scenario->set_scheme(curl::fuzzer::proto::SCHEME_HTTP); |
2398 | 36.4k | break; |
2399 | 81.3k | case TargetProfile::kFastHttps: |
2400 | 81.3k | scenario->set_scheme(curl::fuzzer::proto::SCHEME_HTTPS); |
2401 | 81.3k | break; |
2402 | 0 | case TargetProfile::kHttpsH2: |
2403 | | // The protocol-specific early path fixes ALPN and prunes incompatible |
2404 | | // response shapes while retaining the raw frame script. |
2405 | 0 | return; |
2406 | 0 | case TargetProfile::kFastHttp2: |
2407 | | // The protocol-specific early path fixes prior-knowledge H2 and prunes |
2408 | | // incompatible response shapes while retaining its frame script. |
2409 | 0 | return; |
2410 | 0 | case TargetProfile::kFastHttp3: |
2411 | | // The protocol-specific early path owns the QUIC response plan. |
2412 | 0 | return; |
2413 | 0 | case TargetProfile::kH2Proxy: |
2414 | | // The early path removes proxy-incompatible fields before general |
2415 | | // bounds, keeping raw frame mutation dense. |
2416 | 0 | return; |
2417 | 0 | case TargetProfile::kProxyTransport: |
2418 | | // The early path fixes proxy routing and request-triggered replies. |
2419 | 0 | return; |
2420 | 0 | case TargetProfile::kResolver: |
2421 | | // The early path fixes safe DNS/cache routing and bounds its slist. |
2422 | 0 | return; |
2423 | 23.7k | case TargetProfile::kFastWebSocket: |
2424 | 23.7k | scenario->set_scheme(curl::fuzzer::proto::SCHEME_WS); |
2425 | 23.7k | break; |
2426 | 19.7k | case TargetProfile::kFastSecureWebSocket: |
2427 | 19.7k | scenario->set_scheme(curl::fuzzer::proto::SCHEME_WSS); |
2428 | 19.7k | break; |
2429 | 33.9k | case TargetProfile::kTiming: |
2430 | 33.9k | scenario->set_scheme(PlaintextScheme(scenario->scheme())); |
2431 | 33.9k | break; |
2432 | 0 | case TargetProfile::kFastHttp: |
2433 | 0 | case TargetProfile::kFastTelnet: |
2434 | 0 | case TargetProfile::kFastFtp: |
2435 | 0 | case TargetProfile::kFastTftp: |
2436 | 0 | case TargetProfile::kFastSmtp: |
2437 | 0 | case TargetProfile::kFastImap: |
2438 | 0 | case TargetProfile::kFastPop3: |
2439 | 0 | case TargetProfile::kFastMqtt: |
2440 | 0 | case TargetProfile::kFastDict: |
2441 | 0 | case TargetProfile::kFastGopher: |
2442 | 0 | case TargetProfile::kFastFile: |
2443 | 0 | case TargetProfile::kFastLdap: |
2444 | 0 | case TargetProfile::kFastRtsp: |
2445 | 0 | case TargetProfile::kFastIpfs: |
2446 | | // Protocol-specific early-return paths selected their scheme above. |
2447 | 0 | return; |
2448 | 278k | } |
2449 | | |
2450 | | // TELNET's retained slist and synchronous pause have no observable, safe |
2451 | | // meaning in the fixed event-driven lanes. Clear them before walking the |
2452 | | // general shape so only the compatibility and TELNET targets can retain |
2453 | | // those values. |
2454 | 278k | RemoveTelnetOnlyShape(scenario); |
2455 | 278k | if (profile != TargetProfile::kApi) { |
2456 | 238k | RemoveApiOnlyShape(scenario); |
2457 | 238k | } |
2458 | 278k | if (profile != TargetProfile::kMulti) { |
2459 | 242k | RemoveMultiOnlyShape(scenario); |
2460 | 242k | } |
2461 | 278k | if (profile == TargetProfile::kDeepHttp) { |
2462 | 43.5k | CanonicalizeDeepHttpSelectors(scenario); |
2463 | 43.5k | } |
2464 | 278k | if (profile == TargetProfile::kApi && scenario->has_api_plan()) { |
2465 | 15.9k | CanonicalizeApiDriveMode(scenario->mutable_api_plan()); |
2466 | 15.9k | } |
2467 | 278k | PruneAndBoundScenarioShape(scenario, profile, prune_conditional_eligibility); |
2468 | | |
2469 | 278k | switch (profile) { |
2470 | 0 | case TargetProfile::kCompatibility: |
2471 | 0 | return; |
2472 | 0 | case TargetProfile::kFastHttp: |
2473 | | // Handled before the general bounds so discarded deep shapes are never |
2474 | | // traversed on the fast path. |
2475 | 0 | return; |
2476 | | |
2477 | 43.5k | case TargetProfile::kDeepHttp: |
2478 | 43.5k | if (scenario->proxy_socket_option_mode() != curl::fuzzer::proto::PROXY_SOCKET_OPTION_DEFAULT) { |
2479 | | // A scenario describes one owned route. Prefer the closed socket-option |
2480 | | // profile when a mutation selects both independent fields. |
2481 | 11.7k | scenario->clear_http_transport_mode(); |
2482 | 11.7k | CanonicalizeProxySocketOptionAuthority(scenario); |
2483 | | // Alt-Svc or HSTS can replace this mode's fixed plaintext authority |
2484 | | // before its option path runs. Keep the focused route authoritative. |
2485 | 11.7k | scenario->clear_altsvc_file(); |
2486 | 11.7k | scenario->clear_hsts_file(); |
2487 | 31.8k | } else if (scenario->http_transport_mode() != curl::fuzzer::proto::HTTP_TRANSPORT_DIRECT) { |
2488 | 4.56k | CanonicalizeHttpTransportAuthority(scenario); |
2489 | | // The selected transport owns the route. Alt-Svc and HSTS can rewrite |
2490 | | // its fixed plaintext authority into a different proxy or TLS path, |
2491 | | // defeating the mode the scenario is meant to exercise. |
2492 | 4.56k | scenario->clear_altsvc_file(); |
2493 | 4.56k | scenario->clear_hsts_file(); |
2494 | 27.2k | } else if (!scenario->altsvc_file().empty()) { |
2495 | 1.85k | CanonicalizeAltSvcAuthority(scenario); |
2496 | 1.85k | } |
2497 | 43.5k | if (scenario->http_transport_mode() == curl::fuzzer::proto::HTTP_TRANSPORT_CONNECT_PROXY && |
2498 | 2.77k | scenario->haproxy_protocol()) { |
2499 | | // This closed combination makes the pending HAProxy setup state |
2500 | | // reachable after CONNECT. A large checked-in request fills the |
2501 | | // tightened socket, while bounded peer drains and repeated public |
2502 | | // multi polling expose the filter's write-only pollset. |
2503 | 1.21k | auto* backpressure = scenario->mutable_connection()->mutable_backpressure(); |
2504 | 1.21k | backpressure->set_recv_buf_bytes(kHaproxyConnectBufferBytes); |
2505 | 1.21k | backpressure->set_drain_limit(kHaproxyConnectDrainBytes); |
2506 | 1.21k | for (auto& connection : *scenario->mutable_subsequent_connections()) { |
2507 | 1.20k | connection.clear_backpressure(); |
2508 | 1.20k | } |
2509 | 42.3k | } else { |
2510 | 42.3k | scenario->clear_haproxy_protocol(); |
2511 | 42.3k | ClearAllBackpressure(scenario); |
2512 | 42.3k | } |
2513 | 43.5k | if (scenario->http_transport_mode() != curl::fuzzer::proto::HTTP_TRANSPORT_CONNECT_PROXY) { |
2514 | 40.7k | scenario->clear_probe_multi_pollset(); |
2515 | 40.7k | } |
2516 | 43.5k | return; |
2517 | | |
2518 | 39.9k | case TargetProfile::kApi: |
2519 | 39.9k | ClearAllBackpressure(scenario); |
2520 | 39.9k | if (scenario->host_path().size() > scenario_limits::kMaxApiStringBytes) { |
2521 | 1 | scenario->mutable_host_path()->resize(scenario_limits::kMaxApiStringBytes); |
2522 | 1 | } |
2523 | 39.9k | if (scenario->has_api_plan()) { |
2524 | 15.9k | BoundApiPlanShape(scenario->mutable_api_plan()); |
2525 | 15.9k | CanonicalizeApiMimeRepeat(scenario); |
2526 | 15.9k | } |
2527 | 39.9k | return; |
2528 | | |
2529 | 36.4k | case TargetProfile::kMulti: { |
2530 | 36.4k | ClearAllBackpressure(scenario); |
2531 | 36.4k | CanonicalizeMultiAuthority(scenario); |
2532 | | // The multi runner is HTTP-only (it drives every handle through one |
2533 | | // plaintext HTTP peer), so pin the scheme instead of letting a mutation |
2534 | | // select a protocol the runner cannot service. |
2535 | 36.4k | scenario->set_scheme(curl::fuzzer::proto::SCHEME_HTTP); |
2536 | 36.4k | auto* plan = scenario->mutable_multi_plan(); |
2537 | 36.4k | BoundMultiPlanShape(plan); |
2538 | 36.4k | TrimRepeated(scenario->mutable_subsequent_connections(), plan->transfer_count() - 1U); |
2539 | 36.4k | return; |
2540 | 0 | } |
2541 | | |
2542 | 81.3k | case TargetProfile::kFastHttps: |
2543 | 81.3k | ClearAllBackpressure(scenario); |
2544 | 81.3k | CanonicalizeTlsAuthority(scenario); |
2545 | 81.3k | CanonicalizeTlsCertificateChain(scenario); |
2546 | 81.3k | CanonicalizeTlsClientCredentialProfile(scenario); |
2547 | 81.3k | CanonicalizeTlsHandshakeProfile(scenario); |
2548 | 81.3k | return; |
2549 | | |
2550 | 0 | case TargetProfile::kHttpsH2: |
2551 | | // Handled by the raw HTTP/2 protocol-specific early path above. |
2552 | 0 | return; |
2553 | | |
2554 | 0 | case TargetProfile::kFastHttp2: |
2555 | | // Handled by the plaintext HTTP/2 protocol-specific early path above. |
2556 | 0 | return; |
2557 | | |
2558 | 0 | case TargetProfile::kFastHttp3: |
2559 | | // Handled before generic connection bounding because Http3Plan replaces |
2560 | | // the stream-socket response script. |
2561 | 0 | return; |
2562 | | |
2563 | 0 | case TargetProfile::kH2Proxy: |
2564 | | // Handled by the protocol-specific early path above. |
2565 | 0 | return; |
2566 | | |
2567 | 0 | case TargetProfile::kProxyTransport: |
2568 | | // Handled by the protocol-specific early path above. |
2569 | 0 | return; |
2570 | | |
2571 | 0 | case TargetProfile::kResolver: |
2572 | | // Handled by the resolver-specific early path above. |
2573 | 0 | return; |
2574 | | |
2575 | 23.7k | case TargetProfile::kFastWebSocket: |
2576 | 23.7k | ClearAllBackpressure(scenario); |
2577 | 23.7k | RemoveIgnoredWebSocketShape(scenario); |
2578 | 23.7k | return; |
2579 | | |
2580 | 19.7k | case TargetProfile::kFastSecureWebSocket: |
2581 | 19.7k | ClearAllBackpressure(scenario); |
2582 | 19.7k | RemoveIgnoredWebSocketShape(scenario); |
2583 | 19.7k | CanonicalizeTlsAuthority(scenario); |
2584 | 19.7k | CanonicalizeTlsCertificateChain(scenario); |
2585 | 19.7k | return; |
2586 | | |
2587 | 0 | case TargetProfile::kFastTelnet: |
2588 | | // Handled before the general bounds so its protocol-specific limits are |
2589 | | // selected from the start. |
2590 | 0 | return; |
2591 | | |
2592 | 0 | case TargetProfile::kFastFtp: |
2593 | 0 | case TargetProfile::kFastTftp: |
2594 | 0 | case TargetProfile::kFastSmtp: |
2595 | 0 | case TargetProfile::kFastImap: |
2596 | 0 | case TargetProfile::kFastPop3: |
2597 | 0 | case TargetProfile::kFastMqtt: |
2598 | 0 | case TargetProfile::kFastDict: |
2599 | 0 | case TargetProfile::kFastGopher: |
2600 | 0 | case TargetProfile::kFastFile: |
2601 | 0 | case TargetProfile::kFastLdap: |
2602 | 0 | case TargetProfile::kFastRtsp: |
2603 | 0 | case TargetProfile::kFastIpfs: |
2604 | | // Their peers consume narrower raw-script shapes, pruned before general |
2605 | | // bounds so ignored fields never tax these fast paths. |
2606 | 0 | return; |
2607 | | |
2608 | 33.9k | case TargetProfile::kTiming: { |
2609 | 33.9k | if (scenario->scheme() == curl::fuzzer::proto::SCHEME_WS) { |
2610 | 6.44k | RemoveIgnoredWebSocketShape(scenario); |
2611 | 6.44k | } |
2612 | 33.9k | auto* backpressure = scenario->mutable_connection()->mutable_backpressure(); |
2613 | 33.9k | if (backpressure->recv_buf_bytes() == 0) { |
2614 | | // A drain limit alone cannot fill the default AF_UNIX buffer with the |
2615 | | // harness's bounded upload. Always tighten the socket so this lane |
2616 | | // represents real pressure, not merely selection of the timed loop. |
2617 | 490 | backpressure->set_recv_buf_bytes(kDefaultBackpressureBufferBytes); |
2618 | 33.4k | } else { |
2619 | 33.4k | backpressure->set_recv_buf_bytes(CanonicalizeNonZero(backpressure->recv_buf_bytes(), |
2620 | 33.4k | kMinBackpressureBufferBytes, kMaxBackpressureBufferBytes)); |
2621 | 33.4k | } |
2622 | 33.9k | backpressure->set_drain_limit(CanonicalizeNonZero(backpressure->drain_limit(), 1, kMaxDrainBytesPerIteration)); |
2623 | 33.9k | for (auto& connection : *scenario->mutable_subsequent_connections()) { |
2624 | 19.6k | CanonicalizeOptionalBackpressure(&connection); |
2625 | 19.6k | } |
2626 | 33.9k | return; |
2627 | 0 | } |
2628 | 278k | } |
2629 | 278k | } |
2630 | | |
2631 | | } // namespace |
2632 | | |
2633 | | /// Apply execution-only allocation-failure safety rules. Fixed target |
2634 | | /// postprocessors call this while serializing mutations; the shared runtime |
2635 | | /// repeats it so the compatibility target keeps its persistent wire format |
2636 | | /// while executing the same bounded, safe plan. |
2637 | | /// @param scenario Parsed scenario to canonicalize in place. |
2638 | 956k | void NormalizeScenarioForExecution(curl::fuzzer::proto::Scenario* scenario) { |
2639 | 956k | if (scenario == nullptr) { |
2640 | 0 | return; |
2641 | 0 | } |
2642 | 956k | CanonicalizeAllocationFailures(scenario); |
2643 | 956k | CanonicalizeAllocationFailureDrive(scenario); |
2644 | 956k | CanonicalizeLocalPortRange(scenario); |
2645 | 956k | } |
2646 | | |
2647 | | /// Complete normalization for a loaded or mutated fixed-target Scenario. |
2648 | | /// Besides dispatch and timing controls, fixed lanes trim repeated-field and |
2649 | | /// metadata suffixes that the runtime cannot consume. WebSocket lanes also |
2650 | | /// remove follow-on sockets and MIME bodies their single-upgrade driver cannot |
2651 | | /// use; all remaining observable bytes, options, frames, and probes stay |
2652 | | /// fuzz-controlled. Option oneofs are canonicalized before final string bounds, |
2653 | | /// so repeated normalization preserves the same serialized message. The |
2654 | | /// compatibility profile leaves the entire input unchanged. |
2655 | | /// @param scenario Scenario to canonicalize in place. |
2656 | | /// @param profile Target lane whose invariants must be restored. |
2657 | | /// @param prune_conditional_eligibility Generated profile callback, or nullptr |
2658 | | /// when the caller has no conditional eligibility to apply. |
2659 | | void NormalizeScenarioForTarget(curl::fuzzer::proto::Scenario* scenario, TargetProfile profile, |
2660 | 623k | ConditionalEligibilityPruner prune_conditional_eligibility) { |
2661 | | // Compatibility has no LPM postprocessor. Preserve the complete wire input, |
2662 | | // including mismatched option oneofs and newly added, otherwise inert fields. |
2663 | 623k | if (scenario == nullptr || profile == TargetProfile::kCompatibility) { |
2664 | 0 | return; |
2665 | 0 | } |
2666 | | |
2667 | 623k | ApplyLanePolicy(scenario, profile, prune_conditional_eligibility); |
2668 | 623k | NormalizeScenarioForExecution(scenario); |
2669 | 623k | CanonicalizeOptionValueCases(scenario); |
2670 | | // Canonicalization can materialize string values or prepend pin syntax. |
2671 | | // Charge the final representation so normalization remains a fixed point. |
2672 | 1.75M | for (auto& option : *scenario->mutable_options()) { |
2673 | 1.75M | if (option.value_case() == curl::fuzzer::proto::SetOption::kStringValue) { |
2674 | 774k | TrimMetadata(option.mutable_string_value()); |
2675 | 774k | } |
2676 | 1.75M | } |
2677 | 623k | } |
2678 | | |
2679 | | } // namespace proto_fuzzer |