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