/src/curl_fuzzer/fuzz_private.cc
Line | Count | Source |
1 | | /* |
2 | | * Copyright (C) Max Dymond, <cmeister2@gmail.com>, et al. |
3 | | * |
4 | | * SPDX-License-Identifier: curl |
5 | | */ |
6 | | |
7 | | // Input-driven fuzzing for small curl-private containers, hostname matching, |
8 | | // debug wrappers, and the callback surface of an unconnected Happy Eyeballs |
9 | | // filter. The first byte selects a lane; every action after it comes from the |
10 | | // input. All per-input allocations, descriptors, peers, and filters are |
11 | | // released before return. |
12 | | |
13 | | #include "fuzz_private.h" |
14 | | |
15 | | #include <algorithm> |
16 | | #include <array> |
17 | | #include <cassert> |
18 | | #include <cstdio> |
19 | | #include <memory> |
20 | | #include <string> |
21 | | #include <vector> |
22 | | |
23 | | #ifdef _WIN32 |
24 | | #include <fcntl.h> |
25 | | #include <io.h> |
26 | | #else |
27 | | #include <fcntl.h> |
28 | | #include <sys/socket.h> |
29 | | #include <unistd.h> |
30 | | #endif |
31 | | |
32 | | extern "C" { |
33 | | #include "curl_setup.h" |
34 | | #include "cf-ip-happy.h" |
35 | | #include "cfilters.h" |
36 | | #include "dynhds.h" |
37 | | #include "peer.h" |
38 | | #include "protocol.h" |
39 | | #include "ptrarray.h" |
40 | | #include "uint-spbset.h" |
41 | | #include "urldata.h" |
42 | | #if defined(USE_OPENSSL) || defined(USE_SCHANNEL) |
43 | | #include "vtls/hostcheck.h" |
44 | | #endif |
45 | | |
46 | | void ptrarray_clear(struct ptrarray *pa); |
47 | | uint32_t ptrarray_count(struct ptrarray *pa); |
48 | | void *ptrarray_get(struct ptrarray *pa, uint32_t idx); |
49 | | |
50 | | bool dynhds_contains(struct dynhds *dynhds, const char *name, |
51 | | size_t namelen); |
52 | | bool dynhds_ccontains(struct dynhds *dynhds, const char *name); |
53 | | size_t dynhds_count_name(struct dynhds *dynhds, const char *name, |
54 | | size_t namelen); |
55 | | size_t dynhds_ccount_name(struct dynhds *dynhds, const char *name); |
56 | | size_t dynhds_remove(struct dynhds *dynhds, const char *name, |
57 | | size_t namelen); |
58 | | CURLcode dynhds_set(struct dynhds *dynhds, const char *name, |
59 | | size_t namelen, const char *value, size_t valuelen); |
60 | | size_t dynhds_cremove(struct dynhds *dynhds, const char *name); |
61 | | |
62 | | void uint32_spbset_clear(struct uint32_spbset *bset); |
63 | | } |
64 | | |
65 | | namespace private_fuzzer { |
66 | | namespace { |
67 | | |
68 | | constexpr std::size_t kMaxOperations = 256; |
69 | | constexpr std::size_t kMaxPointers = 256; |
70 | | constexpr std::size_t kMaxHeaderFieldLength = 31; |
71 | | #if defined(USE_OPENSSL) || defined(USE_SCHANNEL) |
72 | | constexpr std::size_t kMaxHostcheckInputBytes = 4096; |
73 | | constexpr std::size_t kMaxHostcheckNameLength = 255; |
74 | | constexpr std::size_t kMaxHostcheckRecords = 32; |
75 | | #endif |
76 | | |
77 | | class InputCursor { |
78 | | public: |
79 | | InputCursor(const std::uint8_t *data, std::size_t size) |
80 | 2.77k | : data_(data), size_(size), offset_(0) {} |
81 | | |
82 | 270k | bool empty() const { return offset_ >= size_; } |
83 | 71.7k | std::size_t remaining() const { return size_ - offset_; } |
84 | | |
85 | 202k | std::uint8_t TakeByte() { |
86 | 202k | return empty() ? 0 : data_[offset_++]; |
87 | 202k | } |
88 | | |
89 | 21.5k | std::uint32_t TakeU32() { |
90 | 21.5k | std::uint32_t value = 0; |
91 | 107k | for (int index = 0; index < 4; ++index) |
92 | 86.2k | value = (value << 8) | TakeByte(); |
93 | 21.5k | return value; |
94 | 21.5k | } |
95 | | |
96 | 34.9k | std::string TakeBytes(std::size_t length) { |
97 | 34.9k | length = length < remaining() ? length : remaining(); |
98 | 34.9k | const char *begin = reinterpret_cast<const char *>(data_ + offset_); |
99 | 34.9k | offset_ += length; |
100 | 34.9k | return std::string(begin, length); |
101 | 34.9k | } |
102 | | |
103 | | private: |
104 | | const std::uint8_t *data_; |
105 | | std::size_t size_; |
106 | | std::size_t offset_; |
107 | | }; |
108 | | |
109 | 202 | void FuzzPointerArray(InputCursor input) { |
110 | 202 | struct ptrarray pointers; |
111 | 202 | std::array<std::uint8_t, kMaxPointers> tokens = {}; |
112 | 202 | std::vector<void *> expected; |
113 | 202 | Curl_ptrarray_init(&pointers); |
114 | | |
115 | 202 | for (std::size_t operation = 0; |
116 | 12.0k | operation < kMaxOperations && !input.empty(); ++operation) { |
117 | 11.8k | switch (input.TakeByte()) { |
118 | 5.88k | case '+': { |
119 | 5.88k | const std::size_t token = input.TakeByte(); |
120 | 5.88k | if (expected.size() < kMaxPointers && |
121 | 5.88k | Curl_ptrarray_add(&pointers, &tokens[token]) == CURLE_OK) |
122 | 5.88k | expected.push_back(&tokens[token]); |
123 | 5.88k | break; |
124 | 0 | } |
125 | 205 | case '0': { |
126 | 205 | const CURLcode result = Curl_ptrarray_add(&pointers, nullptr); |
127 | 205 | assert(result == CURLE_BAD_FUNCTION_ARGUMENT); |
128 | 205 | break; |
129 | 205 | } |
130 | 1.59k | case '?': { |
131 | 1.59k | const std::size_t span = expected.size() + 2; |
132 | 1.59k | const std::size_t index = input.TakeByte() % span; |
133 | 1.59k | void *want = index < expected.size() ? expected[index] : nullptr; |
134 | 1.59k | void *actual = |
135 | 1.59k | ptrarray_get(&pointers, static_cast<uint32_t>(index)); |
136 | 1.59k | assert(actual == want); |
137 | 1.59k | break; |
138 | 1.59k | } |
139 | 1.59k | case '#': { |
140 | 453 | const uint32_t count = ptrarray_count(&pointers); |
141 | 453 | assert(count == expected.size()); |
142 | 453 | break; |
143 | 453 | } |
144 | 1.26k | case '-': { |
145 | 1.26k | const std::size_t span = expected.size() + 2; |
146 | 1.26k | const std::size_t index = input.TakeByte() % span; |
147 | 1.26k | void *want = index < expected.size() ? expected[index] : nullptr; |
148 | 1.26k | void *actual = Curl_ptrarray_remove( |
149 | 1.26k | &pointers, static_cast<uint32_t>(index)); |
150 | 1.26k | assert(actual == want); |
151 | 1.26k | if (index < expected.size()) |
152 | 593 | expected.erase(expected.begin() + static_cast<std::ptrdiff_t>(index)); |
153 | 1.26k | break; |
154 | 1.26k | } |
155 | 1.13k | case 'C': |
156 | 1.13k | ptrarray_clear(&pointers); |
157 | 1.13k | expected.clear(); |
158 | 1.13k | break; |
159 | 1.28k | default: |
160 | 1.28k | break; |
161 | 11.8k | } |
162 | 11.8k | assert(CURL_PTRARRAY_COUNT(&pointers) == expected.size()); |
163 | 11.8k | } |
164 | | |
165 | 202 | ptrarray_clear(&pointers); |
166 | 202 | } |
167 | | |
168 | 701 | void FuzzDynamicHeaders(InputCursor input) { |
169 | 701 | const std::uint8_t config = input.TakeByte(); |
170 | 701 | const std::size_t max_entries = 1 + (config & 31U); |
171 | 701 | const std::size_t max_string_bytes = 16 + input.TakeByte(); |
172 | 701 | struct dynhds headers; |
173 | 701 | Curl_dynhds_init(&headers, max_entries, max_string_bytes); |
174 | 701 | if (config & 0x20U) |
175 | 297 | Curl_dynhds_set_opts(&headers, DYNHDS_OPT_LOWERCASE); |
176 | | |
177 | 701 | for (std::size_t operation = 0; |
178 | 17.8k | operation < kMaxOperations && !input.empty(); ++operation) { |
179 | 17.2k | const char opcode = static_cast<char>(input.TakeByte()); |
180 | 17.2k | if (input.remaining() < 2) |
181 | 37 | break; |
182 | 17.1k | const std::size_t name_length = |
183 | 17.1k | input.TakeByte() & kMaxHeaderFieldLength; |
184 | 17.1k | const std::size_t value_length = |
185 | 17.1k | input.TakeByte() & kMaxHeaderFieldLength; |
186 | 17.1k | if (input.remaining() < name_length + value_length) |
187 | 35 | break; |
188 | 17.1k | const std::string name = input.TakeBytes(name_length); |
189 | 17.1k | const std::string value = input.TakeBytes(value_length); |
190 | 17.1k | const bool valid_name = !name.empty() && name.front() != '\0'; |
191 | | |
192 | 17.1k | switch (opcode) { |
193 | 2.39k | case 'A': |
194 | 2.39k | if (valid_name) |
195 | 1.93k | (void)Curl_dynhds_add(&headers, name.data(), name.size(), |
196 | 1.93k | value.data(), value.size()); |
197 | 2.39k | break; |
198 | 2.80k | case 'a': |
199 | 2.80k | if (valid_name) |
200 | 2.26k | (void)Curl_dynhds_cadd(&headers, name.c_str(), value.c_str()); |
201 | 2.80k | break; |
202 | 1.03k | case '?': |
203 | 1.03k | (void)dynhds_contains(&headers, name.data(), name.size()); |
204 | 1.03k | break; |
205 | 1.07k | case 'C': |
206 | 1.07k | (void)dynhds_ccontains(&headers, name.c_str()); |
207 | 1.07k | break; |
208 | 1.03k | case 'N': |
209 | 1.03k | (void)dynhds_count_name(&headers, name.data(), name.size()); |
210 | 1.03k | break; |
211 | 981 | case 'n': |
212 | 981 | (void)dynhds_ccount_name(&headers, name.c_str()); |
213 | 981 | break; |
214 | 1.56k | case 'S': |
215 | 1.56k | if (valid_name) |
216 | 1.36k | (void)dynhds_set(&headers, name.data(), name.size(), value.data(), |
217 | 1.36k | value.size()); |
218 | 1.56k | break; |
219 | 467 | case 'R': |
220 | 467 | (void)dynhds_remove(&headers, name.data(), name.size()); |
221 | 467 | break; |
222 | 672 | case 'r': |
223 | 672 | (void)dynhds_cremove(&headers, name.c_str()); |
224 | 672 | break; |
225 | 535 | case 'X': |
226 | 535 | Curl_dynhds_reset(&headers); |
227 | 535 | break; |
228 | 4.58k | default: |
229 | 4.58k | break; |
230 | 17.1k | } |
231 | 17.1k | assert(Curl_dynhds_count(&headers) <= max_entries); |
232 | 17.1k | } |
233 | | |
234 | 701 | Curl_dynhds_cleanup(&headers); |
235 | 701 | } |
236 | | |
237 | 1.04k | void FuzzSparseBitset(InputCursor input) { |
238 | 1.04k | struct uint32_spbset values; |
239 | 1.04k | Curl_uint32_spbset_init(&values); |
240 | | |
241 | 1.04k | for (std::size_t operation = 0; |
242 | 28.1k | operation < kMaxOperations && !input.empty(); ++operation) { |
243 | 27.0k | const char opcode = static_cast<char>(input.TakeByte()); |
244 | 27.0k | switch (opcode) { |
245 | 14.9k | case '+': |
246 | 14.9k | (void)Curl_uint32_spbset_add(&values, input.TakeU32()); |
247 | 14.9k | break; |
248 | 2.02k | case '-': |
249 | 2.02k | Curl_uint32_spbset_remove(&values, input.TakeU32()); |
250 | 2.02k | break; |
251 | 1.72k | case '?': |
252 | 1.72k | (void)Curl_uint32_spbset_contains(&values, input.TakeU32()); |
253 | 1.72k | break; |
254 | 551 | case '#': |
255 | 551 | (void)Curl_uint32_spbset_count(&values); |
256 | 551 | break; |
257 | 744 | case 'F': { |
258 | 744 | uint32_t first = 0; |
259 | 744 | (void)Curl_uint32_spbset_first(&values, &first); |
260 | 744 | break; |
261 | 0 | } |
262 | 2.85k | case 'N': { |
263 | 2.85k | uint32_t next = 0; |
264 | 2.85k | (void)Curl_uint32_spbset_next(&values, input.TakeU32(), &next); |
265 | 2.85k | break; |
266 | 0 | } |
267 | 640 | case 'C': |
268 | 640 | uint32_spbset_clear(&values); |
269 | 640 | break; |
270 | 3.59k | default: |
271 | 3.59k | break; |
272 | 27.0k | } |
273 | 27.0k | } |
274 | | |
275 | 1.04k | Curl_uint32_spbset_destroy(&values); |
276 | 1.04k | } |
277 | | |
278 | | #if defined(USE_OPENSSL) || defined(USE_SCHANNEL) |
279 | | // Interpret newline-delimited `certificate-pattern|hostname` records. Keep the |
280 | | // hostname NUL-terminated for Curl_host_is_ipnum, but copy the pattern into an |
281 | | // exact-sized allocation so hostcheck cannot rely on a courtesy terminator. |
282 | | // Invalid records are ignored rather than reinterpreted. |
283 | 636 | void FuzzHostcheck(InputCursor input) { |
284 | 636 | const std::string records = |
285 | 636 | input.TakeBytes(std::min(input.remaining(), kMaxHostcheckInputBytes)); |
286 | 636 | std::size_t record_start = 0; |
287 | 636 | for (std::size_t operation = 0; |
288 | 4.39k | operation < kMaxHostcheckRecords && record_start <= records.size(); |
289 | 4.38k | ++operation) { |
290 | 4.38k | const std::size_t record_end = records.find('\n', record_start); |
291 | 4.38k | const std::size_t bounded_end = |
292 | 4.38k | record_end == std::string::npos ? records.size() : record_end; |
293 | 4.38k | const std::size_t separator = records.find('|', record_start); |
294 | 4.38k | if (separator < bounded_end) { |
295 | 3.73k | const std::size_t pattern_length = |
296 | 3.73k | std::min(separator - record_start, kMaxHostcheckNameLength); |
297 | 3.73k | const std::size_t hostname_start = separator + 1; |
298 | 3.73k | const std::size_t hostname_length = |
299 | 3.73k | std::min(bounded_end - hostname_start, kMaxHostcheckNameLength); |
300 | 3.73k | std::unique_ptr<char[]> pattern; |
301 | 3.73k | if (pattern_length != 0) { |
302 | 3.40k | pattern = std::make_unique<char[]>(pattern_length); |
303 | 3.40k | std::copy_n(records.data() + record_start, pattern_length, |
304 | 3.40k | pattern.get()); |
305 | 3.40k | } |
306 | 3.73k | const std::string hostname = |
307 | 3.73k | records.substr(hostname_start, hostname_length); |
308 | 3.73k | (void)Curl_cert_hostcheck(pattern.get(), pattern_length, hostname.c_str(), |
309 | 3.73k | hostname.size()); |
310 | 3.73k | } |
311 | 4.38k | if (record_end == std::string::npos) |
312 | 624 | break; |
313 | 3.76k | record_start = record_end + 1; |
314 | 3.76k | } |
315 | 636 | } |
316 | | #endif |
317 | | |
318 | | #ifdef _WIN32 |
319 | | constexpr const char *kNullDevice = "NUL"; |
320 | | |
321 | | int OpenNullDevice() { return _open(kNullDevice, _O_RDWR); } |
322 | | void CloseDescriptor(int descriptor) { _close(descriptor); } |
323 | | #else |
324 | | constexpr const char *kNullDevice = "/dev/null"; |
325 | | |
326 | 548 | int OpenNullDevice() { return open(kNullDevice, O_RDWR); } |
327 | 0 | void CloseDescriptor(int descriptor) { close(descriptor); } |
328 | | #endif |
329 | | |
330 | 1.19k | const char *FileMode(std::uint8_t selector) { |
331 | 1.19k | static const char *const modes[] = {"r", "r+", "w", "a"}; |
332 | 1.19k | return modes[selector & 3U]; |
333 | 1.19k | } |
334 | | |
335 | 6.23k | const char *DebugSource(std::uint8_t flags) { |
336 | 6.23k | return flags & 0x80U ? "fuzz_private.cc" : nullptr; |
337 | 6.23k | } |
338 | | |
339 | 3.88k | void CloseSocket(curl_socket_t *socket) { |
340 | 3.88k | if (*socket != CURL_SOCKET_BAD) { |
341 | 2.18k | (void)curl_dbg_sclose(*socket, 0, nullptr); |
342 | 2.18k | *socket = CURL_SOCKET_BAD; |
343 | 2.18k | } |
344 | 3.88k | } |
345 | | |
346 | 134 | void FuzzMemoryDebug(InputCursor input) { |
347 | 134 | #ifdef CURL_MEMDEBUG |
348 | 134 | curl_socket_t sockets[2] = {CURL_SOCKET_BAD, CURL_SOCKET_BAD}; |
349 | | |
350 | 134 | for (std::size_t operation = 0; |
351 | 6.36k | operation < kMaxOperations && !input.empty(); ++operation) { |
352 | 6.23k | const char opcode = static_cast<char>(input.TakeByte()); |
353 | 6.23k | const std::uint8_t flags = input.TakeByte(); |
354 | 6.23k | const char *source = DebugSource(flags); |
355 | 6.23k | switch (opcode) { |
356 | 1.09k | case 'S': |
357 | 1.09k | #ifdef HAVE_SOCKETPAIR |
358 | 1.09k | CloseSocket(&sockets[0]); |
359 | 1.09k | CloseSocket(&sockets[1]); |
360 | 1.09k | (void)curl_dbg_socketpair(AF_UNIX, |
361 | 1.09k | (flags & 1U) ? SOCK_DGRAM : SOCK_STREAM, 0, |
362 | 1.09k | sockets, flags, source); |
363 | 1.09k | #endif |
364 | 1.09k | break; |
365 | 1.43k | case 'A': { |
366 | 1.43k | struct sockaddr_storage address = {}; |
367 | 1.43k | curl_socklen_t address_length = sizeof(address); |
368 | 1.43k | const curl_socket_t socket = |
369 | 1.43k | sockets[0] != CURL_SOCKET_BAD && !(flags & 1U) |
370 | 1.43k | ? sockets[0] |
371 | 1.43k | : CURL_SOCKET_BAD; |
372 | 1.43k | curl_socket_t accepted = |
373 | 1.43k | curl_dbg_accept(socket, (flags & 2U) ? &address : nullptr, |
374 | 1.43k | (flags & 2U) ? &address_length : nullptr, flags, |
375 | 1.43k | source); |
376 | 1.43k | CloseSocket(&accepted); |
377 | 1.43k | break; |
378 | 0 | } |
379 | 548 | case 'D': { |
380 | 548 | const int descriptor = OpenNullDevice(); |
381 | 548 | FILE *stream = |
382 | 548 | curl_dbg_fdopen(descriptor, FileMode(flags), flags, source); |
383 | 548 | if (stream) |
384 | 548 | (void)curl_dbg_fclose(stream, flags, source); |
385 | 0 | else if (descriptor >= 0) |
386 | 0 | CloseDescriptor(descriptor); |
387 | 548 | break; |
388 | 0 | } |
389 | 649 | case 'R': { |
390 | 649 | FILE *stream = curl_dbg_fopen(kNullDevice, "r+", flags, source); |
391 | 649 | if (stream) { |
392 | 649 | stream = curl_dbg_freopen(kNullDevice, FileMode(flags), stream, |
393 | 649 | flags, source); |
394 | 649 | if (stream) |
395 | 649 | (void)curl_dbg_fclose(stream, flags, source); |
396 | 649 | } |
397 | 649 | break; |
398 | 0 | } |
399 | 2.50k | default: |
400 | 2.50k | break; |
401 | 6.23k | } |
402 | 6.23k | } |
403 | | |
404 | 134 | CloseSocket(&sockets[0]); |
405 | 134 | CloseSocket(&sockets[1]); |
406 | | #else |
407 | | (void)input; |
408 | | #endif |
409 | 134 | } |
410 | | |
411 | | class CurlRuntime final { |
412 | | public: |
413 | 1 | CurlRuntime() : initialized_(curl_global_init(CURL_GLOBAL_ALL) == CURLE_OK) {} |
414 | 1 | ~CurlRuntime() { |
415 | 1 | if (initialized_) |
416 | 1 | curl_global_cleanup(); |
417 | 1 | } |
418 | | |
419 | 54 | bool initialized() const { return initialized_; } |
420 | | |
421 | | private: |
422 | | bool initialized_; |
423 | | }; |
424 | | |
425 | 54 | bool CurlRuntimeReady() { |
426 | 54 | static const CurlRuntime runtime; |
427 | 54 | return runtime.initialized(); |
428 | 54 | } |
429 | | |
430 | 54 | void FuzzHappyEyeballs(InputCursor input) { |
431 | 54 | if (!CurlRuntimeReady()) |
432 | 0 | return; |
433 | | |
434 | 54 | CURL *easy = curl_easy_init(); |
435 | 54 | if (!easy) |
436 | 0 | return; |
437 | 54 | struct Curl_easy *data = reinterpret_cast<struct Curl_easy *>(easy); |
438 | 54 | struct Curl_peer *origin = nullptr; |
439 | 54 | struct Curl_peer *alternative = nullptr; |
440 | 54 | struct Curl_peer *tunnel = nullptr; |
441 | 54 | struct connectdata connection = {}; |
442 | 54 | struct Curl_cfchain chain = {}; |
443 | 54 | struct Curl_cfilter anchor = {}; |
444 | 54 | const struct Curl_scheme *scheme = Curl_get_scheme("http"); |
445 | 54 | const std::uint8_t flags = input.TakeByte() & 7U; |
446 | 54 | const std::uint16_t port = static_cast<std::uint16_t>(1U + flags); |
447 | | |
448 | 54 | CURLcode result = scheme |
449 | 54 | ? Curl_peer_create(data, scheme, "origin.test", port, |
450 | 54 | &origin) |
451 | 54 | : CURLE_FAILED_INIT; |
452 | 54 | if (!result && (flags & 2U)) |
453 | 18 | result = Curl_peer_create(data, scheme, "peer.test", port + 1, |
454 | 18 | &alternative); |
455 | 54 | if (!result && (flags & 4U)) |
456 | 15 | result = |
457 | 15 | Curl_peer_create(data, scheme, "tunnel.test", port + 2, &tunnel); |
458 | | |
459 | 54 | const std::uint8_t transport = |
460 | 54 | (flags & 1U) && !tunnel ? TRNSPRT_UDP : TRNSPRT_TCP; |
461 | 54 | if (!result) { |
462 | 54 | Curl_cfchain_init(&chain, &connection, true); |
463 | 54 | anchor.chain = &chain; |
464 | 54 | result = Curl_cf_ip_happy_insert_after( |
465 | 54 | &anchor, data, origin, alternative ? alternative : origin, transport, |
466 | 54 | tunnel, TRNSPRT_TCP); |
467 | 54 | } |
468 | | |
469 | 54 | if (!result) { |
470 | 54 | struct Curl_cfilter *happy = anchor.next; |
471 | 54 | for (std::size_t operation = 0; |
472 | 3.42k | operation < kMaxOperations && !input.empty(); ++operation) { |
473 | 3.36k | switch (input.TakeByte()) { |
474 | 209 | case 'P': { |
475 | 209 | const bool pending = happy->cft->has_data_pending(happy, data); |
476 | 209 | assert(!pending); |
477 | 209 | break; |
478 | 209 | } |
479 | 229 | case 'Q': { |
480 | 229 | int reply_ms = -2; |
481 | 229 | const CURLcode query_result = happy->cft->query( |
482 | 229 | happy, data, CF_QUERY_CONNECT_REPLY_MS, &reply_ms, nullptr); |
483 | 229 | assert(query_result == CURLE_OK); |
484 | 229 | assert(reply_ms == -1); |
485 | 229 | break; |
486 | 229 | } |
487 | 751 | case 'S': { |
488 | 751 | bool done = false; |
489 | 751 | const CURLcode shutdown_result = |
490 | 751 | happy->cft->do_shutdown(happy, data, &done); |
491 | 751 | assert(shutdown_result == CURLE_OK); |
492 | 751 | assert(done); |
493 | 751 | break; |
494 | 751 | } |
495 | 2.17k | default: |
496 | 2.17k | break; |
497 | 3.36k | } |
498 | 3.36k | } |
499 | 54 | Curl_conn_cf_discard_chain(&anchor.next, data); |
500 | 54 | } |
501 | | |
502 | 54 | Curl_peer_unlink(&tunnel); |
503 | 54 | Curl_peer_unlink(&alternative); |
504 | 54 | Curl_peer_unlink(&origin); |
505 | 54 | curl_easy_cleanup(easy); |
506 | 54 | } |
507 | | |
508 | | } // namespace |
509 | | |
510 | 2.77k | int TestOneInput(const std::uint8_t *data, std::size_t size) { |
511 | 2.77k | if (!data || !size) |
512 | 0 | return 0; |
513 | | |
514 | 2.77k | InputCursor input(data + 1, size - 1); |
515 | 2.77k | switch (data[0]) { |
516 | 202 | case 'P': |
517 | 202 | FuzzPointerArray(input); |
518 | 202 | break; |
519 | 701 | case 'D': |
520 | 701 | FuzzDynamicHeaders(input); |
521 | 701 | break; |
522 | 1.04k | case 'U': |
523 | 1.04k | FuzzSparseBitset(input); |
524 | 1.04k | break; |
525 | 134 | case 'M': |
526 | 134 | FuzzMemoryDebug(input); |
527 | 134 | break; |
528 | 54 | case 'H': |
529 | 54 | FuzzHappyEyeballs(input); |
530 | 54 | break; |
531 | 0 | #if defined(USE_OPENSSL) || defined(USE_SCHANNEL) |
532 | 636 | case 'C': |
533 | 636 | FuzzHostcheck(input); |
534 | 636 | break; |
535 | 0 | #endif |
536 | 1 | default: |
537 | 1 | break; |
538 | 2.77k | } |
539 | 2.77k | return 0; |
540 | 2.77k | } |
541 | | |
542 | | } // namespace private_fuzzer |
543 | | |
544 | | extern "C" int LLVMFuzzerTestOneInput(const std::uint8_t *data, |
545 | 435k | std::size_t size) { |
546 | 435k | return private_fuzzer::TestOneInput(data, size); |
547 | 435k | } |