/src/curl_fuzzer/curl_fuzzer.cc
Line | Count | Source |
1 | | /*************************************************************************** |
2 | | * _ _ ____ _ |
3 | | * Project ___| | | | _ \| | |
4 | | * / __| | | | |_) | | |
5 | | * | (__| |_| | _ <| |___ |
6 | | * \___|\___/|_| \_\_____| |
7 | | * |
8 | | * Copyright (C) Max Dymond, <cmeister2@gmail.com>, et al. |
9 | | * |
10 | | * This software is licensed as described in the file COPYING, which |
11 | | * you should have received as part of this distribution. The terms |
12 | | * are also available at https://curl.se/docs/copyright.html. |
13 | | * |
14 | | * You may opt to use, copy, modify, merge, publish, distribute and/or sell |
15 | | * copies of the Software, and permit persons to whom the Software is |
16 | | * furnished to do so, under the terms of the COPYING file. |
17 | | * |
18 | | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY |
19 | | * KIND, either express or implied. |
20 | | * |
21 | | ***************************************************************************/ |
22 | | |
23 | | #include <stdlib.h> |
24 | | #include <signal.h> |
25 | | #include <string.h> |
26 | | #include <unistd.h> |
27 | | #include <curl/curl.h> |
28 | | #include "curl_fuzzer.h" |
29 | | |
30 | | /** |
31 | | * Fuzzing entry point. This function is passed a buffer containing a test |
32 | | * case. This test case should drive the CURL API into making a request. |
33 | | */ |
34 | | extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) |
35 | 220k | { |
36 | 220k | int rc = 0; |
37 | 220k | int tlv_rc; |
38 | 220k | FUZZ_DATA fuzz; |
39 | 220k | TLV tlv; |
40 | | |
41 | | /* Ignore SIGPIPE errors. We'll handle the errors ourselves. */ |
42 | 220k | signal(SIGPIPE, SIG_IGN); |
43 | | |
44 | | /* Have to set all fields to zero before getting to the terminate function */ |
45 | 220k | memset(&fuzz, 0, sizeof(FUZZ_DATA)); |
46 | | |
47 | 220k | if(size < sizeof(TLV_RAW)) { |
48 | | /* Not enough data for a single TLV - don't continue */ |
49 | 64 | goto EXIT_LABEL; |
50 | 64 | } |
51 | | |
52 | | /* Try to initialize the fuzz data */ |
53 | 220k | FTRY(fuzz_initialize_fuzz_data(&fuzz, data, size)); |
54 | | |
55 | 220k | for(tlv_rc = fuzz_get_first_tlv(&fuzz, &tlv); |
56 | 3.45M | tlv_rc == 0; |
57 | 3.26M | tlv_rc = fuzz_get_next_tlv(&fuzz, &tlv)) { |
58 | | |
59 | | /* Have the TLV in hand. Parse the TLV. */ |
60 | 3.26M | rc = fuzz_parse_tlv(&fuzz, &tlv); |
61 | | |
62 | 3.26M | if(rc != 0) { |
63 | | /* Failed to parse the TLV. Can't continue. */ |
64 | 24.8k | goto EXIT_LABEL; |
65 | 24.8k | } |
66 | 3.26M | } |
67 | | |
68 | 195k | if(tlv_rc != TLV_RC_NO_MORE_TLVS) { |
69 | | /* A TLV call failed. Can't continue. */ |
70 | 3.43k | goto EXIT_LABEL; |
71 | 3.43k | } |
72 | | |
73 | | /* Set up the standard easy options. */ |
74 | 192k | FTRY(fuzz_set_easy_options(&fuzz)); |
75 | | |
76 | | /** |
77 | | * Add in more curl options that have been accumulated over possibly |
78 | | * multiple TLVs. |
79 | | */ |
80 | 182k | if(fuzz.header_list != NULL) { |
81 | 9.93k | curl_easy_setopt(fuzz.easy, CURLOPT_HTTPHEADER, fuzz.header_list); |
82 | 9.93k | } |
83 | | |
84 | 182k | if(fuzz.mail_recipients_list != NULL) { |
85 | 1.16k | curl_easy_setopt(fuzz.easy, CURLOPT_MAIL_RCPT, fuzz.mail_recipients_list); |
86 | 1.16k | } |
87 | | |
88 | 182k | if(fuzz.mime != NULL) { |
89 | 4.57k | curl_easy_setopt(fuzz.easy, CURLOPT_MIMEPOST, fuzz.mime); |
90 | 4.57k | } |
91 | | |
92 | 182k | if (fuzz.httppost != NULL) { |
93 | 1.05k | curl_easy_setopt(fuzz.easy, CURLOPT_HTTPPOST, fuzz.httppost); |
94 | 1.05k | } |
95 | | |
96 | | /* Run the transfer. */ |
97 | 182k | fuzz_handle_transfer(&fuzz); |
98 | | |
99 | 220k | EXIT_LABEL: |
100 | | |
101 | 220k | fuzz_terminate_fuzz_data(&fuzz); |
102 | | |
103 | | /* This function must always return 0. Non-zero codes are reserved. */ |
104 | 220k | return 0; |
105 | 182k | } |
106 | | |
107 | | /** |
108 | | * Utility function to convert 4 bytes to a u32 predictably. |
109 | | */ |
110 | | uint32_t to_u32(const uint8_t b[4]) |
111 | 3.44M | { |
112 | 3.44M | uint32_t u; |
113 | 3.44M | u = (b[0] << 24) + (b[1] << 16) + (b[2] << 8) + b[3]; |
114 | 3.44M | return u; |
115 | 3.44M | } |
116 | | |
117 | | /** |
118 | | * Utility function to convert 2 bytes to a u16 predictably. |
119 | | */ |
120 | | uint16_t to_u16(const uint8_t b[2]) |
121 | 3.33M | { |
122 | 3.33M | uint16_t u; |
123 | 3.33M | u = (b[0] << 8) + b[1]; |
124 | 3.33M | return u; |
125 | 3.33M | } |
126 | | |
127 | | /** |
128 | | * Initialize the local fuzz data structure. |
129 | | */ |
130 | | int fuzz_initialize_fuzz_data(FUZZ_DATA *fuzz, |
131 | | const uint8_t *data, |
132 | | size_t data_len) |
133 | 220k | { |
134 | 220k | int rc = 0; |
135 | 220k | int ii; |
136 | | |
137 | | /* Initialize the fuzz data. */ |
138 | 220k | memset(fuzz, 0, sizeof(FUZZ_DATA)); |
139 | | |
140 | | /* Create an easy handle. This will have all of the settings configured on |
141 | | it. */ |
142 | 220k | fuzz->easy = curl_easy_init(); |
143 | 220k | FCHECK(fuzz->easy != NULL); |
144 | | |
145 | | /* Set up the state parser */ |
146 | 220k | fuzz->state.data = data; |
147 | 220k | fuzz->state.data_len = data_len; |
148 | | |
149 | | /* Set up the state of the server sockets. */ |
150 | 660k | for(ii = 0; ii < FUZZ_NUM_CONNECTIONS; ii++) { |
151 | 440k | fuzz->sockman[ii].index = ii; |
152 | 440k | fuzz->sockman[ii].fd_state = FUZZ_SOCK_CLOSED; |
153 | 440k | } |
154 | | |
155 | | /* Check for verbose mode. */ |
156 | 220k | fuzz->verbose = (getenv("FUZZ_VERBOSE") != NULL); |
157 | | |
158 | 220k | FCHECK(setenv("CURL_HSTS_HTTP", "1", 0) == 0); |
159 | 220k | FCHECK(setenv("CURL_ALTSVC_HTTP", "1", 0) == 0); |
160 | | |
161 | 220k | EXIT_LABEL: |
162 | | |
163 | 220k | return rc; |
164 | 220k | } |
165 | | |
166 | | /** |
167 | | * Set standard options on the curl easy. |
168 | | */ |
169 | | int fuzz_set_easy_options(FUZZ_DATA *fuzz) |
170 | 192k | { |
171 | 192k | int rc = 0; |
172 | | |
173 | | /* Set some standard options on the CURL easy handle. We need to override the |
174 | | socket function so that we create our own sockets to present to CURL. */ |
175 | 192k | FTRY(curl_easy_setopt(fuzz->easy, |
176 | 192k | CURLOPT_OPENSOCKETFUNCTION, |
177 | 192k | fuzz_open_socket)); |
178 | 192k | FTRY(curl_easy_setopt(fuzz->easy, CURLOPT_OPENSOCKETDATA, fuzz)); |
179 | | |
180 | | /* In case something tries to set a socket option, intercept this. */ |
181 | 192k | FTRY(curl_easy_setopt(fuzz->easy, |
182 | 192k | CURLOPT_SOCKOPTFUNCTION, |
183 | 192k | fuzz_sockopt_callback)); |
184 | | |
185 | | /* Set the standard read function callback. */ |
186 | 192k | FTRY(curl_easy_setopt(fuzz->easy, |
187 | 192k | CURLOPT_READFUNCTION, |
188 | 192k | fuzz_read_callback)); |
189 | 192k | FTRY(curl_easy_setopt(fuzz->easy, CURLOPT_READDATA, fuzz)); |
190 | | |
191 | | /* Set the standard write function callback. */ |
192 | 192k | FTRY(curl_easy_setopt(fuzz->easy, |
193 | 192k | CURLOPT_WRITEFUNCTION, |
194 | 192k | fuzz_write_callback)); |
195 | 192k | FTRY(curl_easy_setopt(fuzz->easy, CURLOPT_WRITEDATA, fuzz)); |
196 | | |
197 | | /* Set the writable cookie jar path so cookies are tested. */ |
198 | 192k | FTRY(curl_easy_setopt(fuzz->easy, CURLOPT_COOKIEJAR, FUZZ_COOKIE_JAR_PATH)); |
199 | | |
200 | | /* Set the RO cookie file path so cookies are tested. */ |
201 | 192k | FTRY(curl_easy_setopt(fuzz->easy, CURLOPT_COOKIEFILE, FUZZ_RO_COOKIE_FILE_PATH)); |
202 | | |
203 | | /* Set altsvc header cache filepath so that it can be fuzzed. */ |
204 | 192k | FTRY(curl_easy_setopt(fuzz->easy, CURLOPT_ALTSVC, FUZZ_ALT_SVC_HEADER_CACHE_PATH)); |
205 | | |
206 | | /* Set the hsts header cache filepath so that it can be fuzzed. */ |
207 | 192k | FTRY(curl_easy_setopt(fuzz->easy, CURLOPT_HSTS, FUZZ_HSTS_HEADER_CACHE_PATH)); |
208 | | |
209 | | /* Set the Certificate Revocation List file path so it can be fuzzed */ |
210 | 192k | FTRY(curl_easy_setopt(fuzz->easy, CURLOPT_CRLFILE, FUZZ_CRL_FILE_PATH)); |
211 | | |
212 | | /* Set the .netrc file path so it can be fuzzed */ |
213 | 192k | FTRY(curl_easy_setopt(fuzz->easy, CURLOPT_NETRC_FILE, FUZZ_NETRC_FILE_PATH)); |
214 | | |
215 | | /* Time out requests quickly. */ |
216 | 192k | FTRY(curl_easy_setopt(fuzz->easy, CURLOPT_TIMEOUT_MS, 200L)); |
217 | 192k | FTRY(curl_easy_setopt(fuzz->easy, CURLOPT_SERVER_RESPONSE_TIMEOUT, 1L)); |
218 | | |
219 | | /* Can enable verbose mode by having the environment variable FUZZ_VERBOSE. */ |
220 | 192k | if(fuzz->verbose) { |
221 | 0 | FTRY(curl_easy_setopt(fuzz->easy, CURLOPT_VERBOSE, 1L)); |
222 | 0 | } |
223 | | |
224 | | /* Force resolution of all addresses to a specific IP address. */ |
225 | 192k | fuzz->connect_to_list = curl_slist_append(NULL, "::127.0.1.127:"); |
226 | 192k | FTRY(curl_easy_setopt(fuzz->easy, CURLOPT_CONNECT_TO, fuzz->connect_to_list)); |
227 | | |
228 | | /* Limit the protocols in use by this fuzzer. */ |
229 | 192k | FTRY(fuzz_set_allowed_protocols(fuzz)); |
230 | | |
231 | 192k | EXIT_LABEL: |
232 | | |
233 | 192k | return rc; |
234 | 182k | } |
235 | | |
236 | | /** |
237 | | * Terminate the fuzz data structure, including freeing any allocated memory. |
238 | | */ |
239 | | void fuzz_terminate_fuzz_data(FUZZ_DATA *fuzz) |
240 | 220k | { |
241 | 220k | int ii; |
242 | | |
243 | 220k | fuzz_free((void **)&fuzz->postfields); |
244 | | |
245 | 661k | for(ii = 0; ii < FUZZ_NUM_CONNECTIONS; ii++) { |
246 | 440k | if(fuzz->sockman[ii].fd_state != FUZZ_SOCK_CLOSED) { |
247 | 105k | close(fuzz->sockman[ii].fd); |
248 | 105k | fuzz->sockman[ii].fd_state = FUZZ_SOCK_CLOSED; |
249 | 105k | } |
250 | 440k | } |
251 | | |
252 | 220k | if(fuzz->connect_to_list != NULL) { |
253 | 192k | curl_slist_free_all(fuzz->connect_to_list); |
254 | 192k | fuzz->connect_to_list = NULL; |
255 | 192k | } |
256 | | |
257 | 220k | if(fuzz->header_list != NULL) { |
258 | 10.0k | curl_slist_free_all(fuzz->header_list); |
259 | 10.0k | fuzz->header_list = NULL; |
260 | 10.0k | } |
261 | | |
262 | 220k | if(fuzz->mail_recipients_list != NULL) { |
263 | 1.29k | curl_slist_free_all(fuzz->mail_recipients_list); |
264 | 1.29k | fuzz->mail_recipients_list = NULL; |
265 | 1.29k | } |
266 | | |
267 | 220k | if(fuzz->mime != NULL) { |
268 | 5.27k | curl_mime_free(fuzz->mime); |
269 | 5.27k | fuzz->mime = NULL; |
270 | 5.27k | } |
271 | | |
272 | 220k | if(fuzz->easy != NULL) { |
273 | 220k | curl_easy_cleanup(fuzz->easy); |
274 | 220k | fuzz->easy = NULL; |
275 | 220k | } |
276 | | |
277 | | /* When you have passed the struct curl_httppost pointer to curl_easy_setopt |
278 | | * (using the CURLOPT_HTTPPOST option), you must not free the list until after |
279 | | * you have called curl_easy_cleanup for the curl handle. |
280 | | * https://curl.se/libcurl/c/curl_formadd.html */ |
281 | 220k | if (fuzz->httppost != NULL) { |
282 | 1.12k | curl_formfree(fuzz->httppost); |
283 | 1.12k | fuzz->httppost = NULL; |
284 | 1.12k | } |
285 | | |
286 | | // free after httppost and last_post_part. |
287 | 220k | if (fuzz->post_body != NULL) { |
288 | 1.12k | fuzz_free((void **)&fuzz->post_body); |
289 | 1.12k | } |
290 | 220k | } |
291 | | |
292 | | /** |
293 | | * If a pointer has been allocated, free that pointer. |
294 | | */ |
295 | | void fuzz_free(void **ptr) |
296 | 3.49M | { |
297 | 3.49M | if(*ptr != NULL) { |
298 | 726k | free(*ptr); |
299 | 726k | *ptr = NULL; |
300 | 726k | } |
301 | 3.49M | } |
302 | | |
303 | | /** |
304 | | * Function for handling the fuzz transfer, including sending responses to |
305 | | * requests. |
306 | | */ |
307 | | int fuzz_handle_transfer(FUZZ_DATA *fuzz) |
308 | 182k | { |
309 | 182k | int rc = 0; |
310 | 182k | CURLM *multi_handle; |
311 | 182k | int still_running; /* keep number of running handles */ |
312 | 182k | CURLMsg *msg; /* for picking up messages with the transfer status */ |
313 | 182k | int msgs_left; /* how many messages are left */ |
314 | 182k | int double_timeout = 0; |
315 | 182k | fd_set fdread; |
316 | 182k | fd_set fdwrite; |
317 | 182k | fd_set fdexcep; |
318 | 182k | struct timeval timeout; |
319 | 182k | int select_rc; |
320 | 182k | CURLMcode mc; |
321 | 182k | int maxfd = -1; |
322 | 182k | long curl_timeo = -1; |
323 | 182k | int ii; |
324 | 182k | FUZZ_SOCKET_MANAGER *sman[FUZZ_NUM_CONNECTIONS]; |
325 | | |
326 | 547k | for(ii = 0; ii < FUZZ_NUM_CONNECTIONS; ii++) { |
327 | 365k | sman[ii] = &fuzz->sockman[ii]; |
328 | | |
329 | | /* Set up the starting index for responses. */ |
330 | 365k | sman[ii]->response_index = 1; |
331 | 365k | } |
332 | | |
333 | | /* init a multi stack */ |
334 | 182k | multi_handle = curl_multi_init(); |
335 | | |
336 | | /* add the individual transfers */ |
337 | 182k | curl_multi_add_handle(multi_handle, fuzz->easy); |
338 | | |
339 | | /* Do an initial process. This might end the transfer immediately. */ |
340 | 182k | curl_multi_perform(multi_handle, &still_running); |
341 | 182k | FV_PRINTF(fuzz, |
342 | 182k | "FUZZ: Initial perform; still running? %d \n", |
343 | 182k | still_running); |
344 | | |
345 | 220k | while(still_running) { |
346 | | /* Reset the sets of file descriptors. */ |
347 | 44.8k | FD_ZERO(&fdread); |
348 | 44.8k | FD_ZERO(&fdwrite); |
349 | 44.8k | FD_ZERO(&fdexcep); |
350 | | |
351 | | /* Set a timeout of 10ms. This is lower than recommended by the multi guide |
352 | | but we're not going to any remote servers, so everything should complete |
353 | | very quickly. */ |
354 | 44.8k | timeout.tv_sec = 0; |
355 | 44.8k | timeout.tv_usec = 10000; |
356 | | |
357 | | /* get file descriptors from the transfers */ |
358 | 44.8k | mc = curl_multi_fdset(multi_handle, &fdread, &fdwrite, &fdexcep, &maxfd); |
359 | 44.8k | if(mc != CURLM_OK) { |
360 | 0 | fprintf(stderr, "curl_multi_fdset() failed, code %d.\n", mc); |
361 | 0 | rc = -1; |
362 | 0 | break; |
363 | 0 | } |
364 | | |
365 | 134k | for(ii = 0; ii < FUZZ_NUM_CONNECTIONS; ii++) { |
366 | | /* Add the socket FD into the readable set if connected. */ |
367 | 89.6k | if(sman[ii]->fd_state == FUZZ_SOCK_OPEN) { |
368 | 30.5k | FD_SET(sman[ii]->fd, &fdread); |
369 | | |
370 | | /* Work out the maximum FD between the cURL file descriptors and the |
371 | | server FD. */ |
372 | 30.5k | maxfd = FUZZ_MAX(sman[ii]->fd, maxfd); |
373 | 30.5k | } |
374 | 89.6k | } |
375 | | |
376 | | /* Work out what file descriptors need work. */ |
377 | 44.8k | rc = fuzz_select(maxfd + 1, &fdread, &fdwrite, &fdexcep, &timeout); |
378 | | |
379 | 44.8k | if(rc == -1) { |
380 | | /* Had an issue while selecting a file descriptor. Let's just exit. */ |
381 | 1 | FV_PRINTF(fuzz, "FUZZ: select failed, exiting \n"); |
382 | 1 | break; |
383 | 1 | } |
384 | | |
385 | | /* Check to see if a server file descriptor is readable. If it is, |
386 | | then send the next response from the fuzzing data. */ |
387 | 44.8k | int server_data_sent = 0; |
388 | 134k | for(ii = 0; ii < FUZZ_NUM_CONNECTIONS; ii++) { |
389 | 89.5k | if(sman[ii]->fd_state == FUZZ_SOCK_OPEN && |
390 | 89.5k | FD_ISSET(sman[ii]->fd, &fdread)) { |
391 | 27.7k | rc = fuzz_send_next_response(fuzz, sman[ii]); |
392 | 27.7k | if(rc != 0) { |
393 | | /* Failed to send a response. Break out here. */ |
394 | 92 | break; |
395 | 92 | } |
396 | 27.6k | server_data_sent = 1; |
397 | 27.6k | } |
398 | 89.5k | } |
399 | | |
400 | | /* Stall detection: exit after two consecutive iterations where no new |
401 | | data was provided to curl. This handles both select() timeouts and |
402 | | cases where curl registers a writable fd but cannot make progress |
403 | | (e.g. HTTP/2 egress stuck with no real peer to drain to). */ |
404 | 44.8k | if(!server_data_sent) { |
405 | 17.1k | FV_PRINTF(fuzz, "FUZZ: No data sent; stall count %d \n", double_timeout); |
406 | 17.1k | if(double_timeout == 1) { |
407 | 6.42k | break; |
408 | 6.42k | } |
409 | 10.7k | double_timeout = 1; |
410 | 10.7k | } |
411 | 27.6k | else { |
412 | 27.6k | double_timeout = 0; |
413 | 27.6k | } |
414 | | |
415 | 38.4k | curl_multi_perform(multi_handle, &still_running); |
416 | 38.4k | } |
417 | | |
418 | | /* Remove the easy handle from the multi stack. */ |
419 | 182k | curl_multi_remove_handle(multi_handle, fuzz->easy); |
420 | | |
421 | | /* Clean up the multi handle - the top level function will handle the easy |
422 | | handle. */ |
423 | 182k | curl_multi_cleanup(multi_handle); |
424 | | |
425 | 182k | return rc; |
426 | 182k | } |
427 | | |
428 | | /** |
429 | | * Sends the next fuzzing response to the server file descriptor. |
430 | | */ |
431 | | int fuzz_send_next_response(FUZZ_DATA *fuzz, FUZZ_SOCKET_MANAGER *sman) |
432 | 27.7k | { |
433 | 27.7k | int rc = 0; |
434 | 27.7k | ssize_t ret_in; |
435 | 27.7k | ssize_t ret_out; |
436 | 27.7k | char buffer[8192]; |
437 | 27.7k | const uint8_t *data; |
438 | 27.7k | size_t data_len; |
439 | | |
440 | | /* Need to read all data sent by the client so the file descriptor becomes |
441 | | unreadable. Because the file descriptor is non-blocking we won't just |
442 | | hang here. */ |
443 | 66.1k | do { |
444 | 66.1k | ret_in = read(sman->fd, buffer, sizeof(buffer)); |
445 | 66.1k | if(fuzz->verbose && ret_in > 0) { |
446 | 0 | printf("FUZZ[%d]: Received %zu bytes \n==>\n", sman->index, ret_in); |
447 | 0 | fwrite(buffer, ret_in, 1, stdout); |
448 | 0 | printf("\n<==\n"); |
449 | 0 | } |
450 | 66.1k | } while (ret_in > 0); |
451 | | |
452 | | /* Now send a response to the request that the client just made. */ |
453 | 27.7k | FV_PRINTF(fuzz, |
454 | 27.7k | "FUZZ[%d]: Sending next response: %d \n", |
455 | 27.7k | sman->index, |
456 | 27.7k | sman->response_index); |
457 | 27.7k | data = sman->responses[sman->response_index].data; |
458 | 27.7k | data_len = sman->responses[sman->response_index].data_len; |
459 | | |
460 | 27.7k | if(data != NULL) { |
461 | 27.7k | if(write(sman->fd, data, data_len) != (ssize_t)data_len) { |
462 | | /* Failed to write the data back to the client. Prevent any further |
463 | | testing. */ |
464 | 92 | rc = -1; |
465 | 92 | } |
466 | 27.7k | } |
467 | | |
468 | | /* Work out if there are any more responses. If not, then shut down the |
469 | | server. */ |
470 | 27.7k | sman->response_index++; |
471 | | |
472 | 27.7k | if(sman->response_index >= TLV_MAX_NUM_RESPONSES || |
473 | 27.7k | sman->responses[sman->response_index].data == NULL) { |
474 | 21.9k | FV_PRINTF(fuzz, |
475 | 21.9k | "FUZZ[%d]: Shutting down server socket: %d \n", |
476 | 21.9k | sman->index, |
477 | 21.9k | sman->fd); |
478 | 21.9k | shutdown(sman->fd, SHUT_WR); |
479 | 21.9k | sman->fd_state = FUZZ_SOCK_SHUTDOWN; |
480 | 21.9k | } |
481 | | |
482 | 27.7k | return rc; |
483 | 27.7k | } |
484 | | |
485 | | /** |
486 | | * Wrapper for select() so profiling can track it. |
487 | | */ |
488 | | int fuzz_select(int nfds, |
489 | | fd_set *readfds, |
490 | | fd_set *writefds, |
491 | | fd_set *exceptfds, |
492 | 44.8k | struct timeval *timeout) { |
493 | 44.8k | return select(nfds, readfds, writefds, exceptfds, timeout); |
494 | 44.8k | } |
495 | | |
496 | | /** |
497 | | * Set allowed protocols based on the compile options. |
498 | | * |
499 | | * Note that it can only use ONE of the FUZZ_PROTOCOLS_* defines. |
500 | | */ |
501 | | int fuzz_set_allowed_protocols(FUZZ_DATA *fuzz) |
502 | 192k | { |
503 | 192k | int rc = 0; |
504 | 192k | const char *allowed_protocols = ""; |
505 | | |
506 | | #ifdef FUZZ_PROTOCOLS_ALL |
507 | | /* Do not allow telnet currently as it accepts input from stdin. */ |
508 | | allowed_protocols = |
509 | | "dict,file,ftp,ftps,gopher,gophers,http,https,imap,imaps," |
510 | | "mqtt,pop3,pop3s," |
511 | | "ldap,ldaps," |
512 | | "rtmp,rtmpe,rtmps,rtmpt,rtmpte,rtmpts," |
513 | | "scp," |
514 | | "sftp," |
515 | | "rtsp,smb,smbs,smtp,smtps,tftp," |
516 | | "ws,wss"; |
517 | | #endif |
518 | | #ifdef FUZZ_PROTOCOLS_DICT |
519 | | allowed_protocols = "dict"; |
520 | | #endif |
521 | | #ifdef FUZZ_PROTOCOLS_FILE |
522 | | allowed_protocols = "file"; |
523 | | #endif |
524 | | #ifdef FUZZ_PROTOCOLS_FTP |
525 | | allowed_protocols = "ftp,ftps"; |
526 | | #endif |
527 | | #ifdef FUZZ_PROTOCOLS_GOPHER |
528 | | allowed_protocols = "gopher,gophers"; |
529 | | #endif |
530 | | #ifdef FUZZ_PROTOCOLS_HTTP |
531 | | allowed_protocols = "http"; |
532 | | #endif |
533 | | #ifdef FUZZ_PROTOCOLS_HTTPS |
534 | | allowed_protocols = "https"; |
535 | | #endif |
536 | | #ifdef FUZZ_PROTOCOLS_IMAP |
537 | | allowed_protocols = "imap,imaps"; |
538 | | #endif |
539 | | #ifdef FUZZ_PROTOCOLS_LDAP |
540 | | allowed_protocols = "ldap,ldaps"; |
541 | | #endif |
542 | | #ifdef FUZZ_PROTOCOLS_MQTT |
543 | | allowed_protocols = "mqtt"; |
544 | | #endif |
545 | | #ifdef FUZZ_PROTOCOLS_POP3 |
546 | | allowed_protocols = "pop3,pop3s"; |
547 | | #endif |
548 | | #ifdef FUZZ_PROTOCOLS_RTMP |
549 | | allowed_protocols = "rtmp,rtmpe,rtmps,rtmpt,rtmpte,rtmpts"; |
550 | | #endif |
551 | | #ifdef FUZZ_PROTOCOLS_RTSP |
552 | | allowed_protocols = "rtsp"; |
553 | | #endif |
554 | | #ifdef FUZZ_PROTOCOLS_SCP |
555 | | allowed_protocols = "scp"; |
556 | | #endif |
557 | | #ifdef FUZZ_PROTOCOLS_SFTP |
558 | | allowed_protocols = "sftp"; |
559 | | #endif |
560 | | #ifdef FUZZ_PROTOCOLS_SMB |
561 | | allowed_protocols = "smb,smbs"; |
562 | | #endif |
563 | | #ifdef FUZZ_PROTOCOLS_SMTP |
564 | | allowed_protocols = "smtp,smtps"; |
565 | | #endif |
566 | | #ifdef FUZZ_PROTOCOLS_TFTP |
567 | | allowed_protocols = "tftp"; |
568 | | #endif |
569 | | #ifdef FUZZ_PROTOCOLS_WS |
570 | | // http is required by websockets |
571 | | allowed_protocols = "http,ws,wss"; |
572 | 18.0k | FTRY(curl_easy_setopt(fuzz->easy, CURLOPT_CONNECT_ONLY, 2L)); |
573 | 18.0k | #endif |
574 | | |
575 | 192k | FTRY(curl_easy_setopt(fuzz->easy, CURLOPT_PROTOCOLS_STR, allowed_protocols)); |
576 | | |
577 | 192k | EXIT_LABEL: |
578 | | |
579 | 192k | return rc; |
580 | 182k | } fuzz_set_allowed_protocols(fuzz_data*) Line | Count | Source | 502 | 174k | { | 503 | 174k | int rc = 0; | 504 | 174k | const char *allowed_protocols = ""; | 505 | | | 506 | | #ifdef FUZZ_PROTOCOLS_ALL | 507 | | /* Do not allow telnet currently as it accepts input from stdin. */ | 508 | | allowed_protocols = | 509 | | "dict,file,ftp,ftps,gopher,gophers,http,https,imap,imaps," | 510 | | "mqtt,pop3,pop3s," | 511 | | "ldap,ldaps," | 512 | | "rtmp,rtmpe,rtmps,rtmpt,rtmpte,rtmpts," | 513 | | "scp," | 514 | | "sftp," | 515 | | "rtsp,smb,smbs,smtp,smtps,tftp," | 516 | | "ws,wss"; | 517 | | #endif | 518 | | #ifdef FUZZ_PROTOCOLS_DICT | 519 | | allowed_protocols = "dict"; | 520 | | #endif | 521 | | #ifdef FUZZ_PROTOCOLS_FILE | 522 | | allowed_protocols = "file"; | 523 | | #endif | 524 | | #ifdef FUZZ_PROTOCOLS_FTP | 525 | | allowed_protocols = "ftp,ftps"; | 526 | | #endif | 527 | | #ifdef FUZZ_PROTOCOLS_GOPHER | 528 | | allowed_protocols = "gopher,gophers"; | 529 | | #endif | 530 | | #ifdef FUZZ_PROTOCOLS_HTTP | 531 | | allowed_protocols = "http"; | 532 | | #endif | 533 | | #ifdef FUZZ_PROTOCOLS_HTTPS | 534 | | allowed_protocols = "https"; | 535 | | #endif | 536 | | #ifdef FUZZ_PROTOCOLS_IMAP | 537 | | allowed_protocols = "imap,imaps"; | 538 | | #endif | 539 | 174k | #ifdef FUZZ_PROTOCOLS_LDAP | 540 | 174k | allowed_protocols = "ldap,ldaps"; | 541 | 174k | #endif | 542 | | #ifdef FUZZ_PROTOCOLS_MQTT | 543 | | allowed_protocols = "mqtt"; | 544 | | #endif | 545 | | #ifdef FUZZ_PROTOCOLS_POP3 | 546 | | allowed_protocols = "pop3,pop3s"; | 547 | | #endif | 548 | | #ifdef FUZZ_PROTOCOLS_RTMP | 549 | | allowed_protocols = "rtmp,rtmpe,rtmps,rtmpt,rtmpte,rtmpts"; | 550 | | #endif | 551 | | #ifdef FUZZ_PROTOCOLS_RTSP | 552 | | allowed_protocols = "rtsp"; | 553 | | #endif | 554 | | #ifdef FUZZ_PROTOCOLS_SCP | 555 | | allowed_protocols = "scp"; | 556 | | #endif | 557 | | #ifdef FUZZ_PROTOCOLS_SFTP | 558 | | allowed_protocols = "sftp"; | 559 | | #endif | 560 | | #ifdef FUZZ_PROTOCOLS_SMB | 561 | | allowed_protocols = "smb,smbs"; | 562 | | #endif | 563 | | #ifdef FUZZ_PROTOCOLS_SMTP | 564 | | allowed_protocols = "smtp,smtps"; | 565 | | #endif | 566 | | #ifdef FUZZ_PROTOCOLS_TFTP | 567 | | allowed_protocols = "tftp"; | 568 | | #endif | 569 | | #ifdef FUZZ_PROTOCOLS_WS | 570 | | // http is required by websockets | 571 | | allowed_protocols = "http,ws,wss"; | 572 | | FTRY(curl_easy_setopt(fuzz->easy, CURLOPT_CONNECT_ONLY, 2L)); | 573 | | #endif | 574 | | | 575 | 174k | FTRY(curl_easy_setopt(fuzz->easy, CURLOPT_PROTOCOLS_STR, allowed_protocols)); | 576 | | | 577 | 174k | EXIT_LABEL: | 578 | | | 579 | 174k | return rc; | 580 | 164k | } |
fuzz_set_allowed_protocols(fuzz_data*) Line | Count | Source | 502 | 18.0k | { | 503 | 18.0k | int rc = 0; | 504 | 18.0k | const char *allowed_protocols = ""; | 505 | | | 506 | | #ifdef FUZZ_PROTOCOLS_ALL | 507 | | /* Do not allow telnet currently as it accepts input from stdin. */ | 508 | | allowed_protocols = | 509 | | "dict,file,ftp,ftps,gopher,gophers,http,https,imap,imaps," | 510 | | "mqtt,pop3,pop3s," | 511 | | "ldap,ldaps," | 512 | | "rtmp,rtmpe,rtmps,rtmpt,rtmpte,rtmpts," | 513 | | "scp," | 514 | | "sftp," | 515 | | "rtsp,smb,smbs,smtp,smtps,tftp," | 516 | | "ws,wss"; | 517 | | #endif | 518 | | #ifdef FUZZ_PROTOCOLS_DICT | 519 | | allowed_protocols = "dict"; | 520 | | #endif | 521 | | #ifdef FUZZ_PROTOCOLS_FILE | 522 | | allowed_protocols = "file"; | 523 | | #endif | 524 | | #ifdef FUZZ_PROTOCOLS_FTP | 525 | | allowed_protocols = "ftp,ftps"; | 526 | | #endif | 527 | | #ifdef FUZZ_PROTOCOLS_GOPHER | 528 | | allowed_protocols = "gopher,gophers"; | 529 | | #endif | 530 | | #ifdef FUZZ_PROTOCOLS_HTTP | 531 | | allowed_protocols = "http"; | 532 | | #endif | 533 | | #ifdef FUZZ_PROTOCOLS_HTTPS | 534 | | allowed_protocols = "https"; | 535 | | #endif | 536 | | #ifdef FUZZ_PROTOCOLS_IMAP | 537 | | allowed_protocols = "imap,imaps"; | 538 | | #endif | 539 | | #ifdef FUZZ_PROTOCOLS_LDAP | 540 | | allowed_protocols = "ldap,ldaps"; | 541 | | #endif | 542 | | #ifdef FUZZ_PROTOCOLS_MQTT | 543 | | allowed_protocols = "mqtt"; | 544 | | #endif | 545 | | #ifdef FUZZ_PROTOCOLS_POP3 | 546 | | allowed_protocols = "pop3,pop3s"; | 547 | | #endif | 548 | | #ifdef FUZZ_PROTOCOLS_RTMP | 549 | | allowed_protocols = "rtmp,rtmpe,rtmps,rtmpt,rtmpte,rtmpts"; | 550 | | #endif | 551 | | #ifdef FUZZ_PROTOCOLS_RTSP | 552 | | allowed_protocols = "rtsp"; | 553 | | #endif | 554 | | #ifdef FUZZ_PROTOCOLS_SCP | 555 | | allowed_protocols = "scp"; | 556 | | #endif | 557 | | #ifdef FUZZ_PROTOCOLS_SFTP | 558 | | allowed_protocols = "sftp"; | 559 | | #endif | 560 | | #ifdef FUZZ_PROTOCOLS_SMB | 561 | | allowed_protocols = "smb,smbs"; | 562 | | #endif | 563 | | #ifdef FUZZ_PROTOCOLS_SMTP | 564 | | allowed_protocols = "smtp,smtps"; | 565 | | #endif | 566 | | #ifdef FUZZ_PROTOCOLS_TFTP | 567 | | allowed_protocols = "tftp"; | 568 | | #endif | 569 | 18.0k | #ifdef FUZZ_PROTOCOLS_WS | 570 | | // http is required by websockets | 571 | 18.0k | allowed_protocols = "http,ws,wss"; | 572 | 18.0k | FTRY(curl_easy_setopt(fuzz->easy, CURLOPT_CONNECT_ONLY, 2L)); | 573 | 18.0k | #endif | 574 | | | 575 | 18.0k | FTRY(curl_easy_setopt(fuzz->easy, CURLOPT_PROTOCOLS_STR, allowed_protocols)); | 576 | | | 577 | 18.0k | EXIT_LABEL: | 578 | | | 579 | 18.0k | return rc; | 580 | 18.0k | } |
|