Coverage Report

Created: 2026-07-30 07:26

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/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
224k
{
36
224k
  int rc = 0;
37
224k
  int tlv_rc;
38
224k
  FUZZ_DATA fuzz;
39
224k
  TLV tlv;
40
41
  /* Ignore SIGPIPE errors. We'll handle the errors ourselves. */
42
224k
  signal(SIGPIPE, SIG_IGN);
43
44
  /* Have to set all fields to zero before getting to the terminate function */
45
224k
  memset(&fuzz, 0, sizeof(FUZZ_DATA));
46
47
224k
  if(size < sizeof(TLV_RAW)) {
48
    /* Not enough data for a single TLV - don't continue */
49
60
    goto EXIT_LABEL;
50
60
  }
51
52
  /* Try to initialize the fuzz data */
53
224k
  FTRY(fuzz_initialize_fuzz_data(&fuzz, data, size));
54
55
224k
  for(tlv_rc = fuzz_get_first_tlv(&fuzz, &tlv);
56
3.93M
      tlv_rc == 0;
57
3.73M
      tlv_rc = fuzz_get_next_tlv(&fuzz, &tlv)) {
58
59
    /* Have the TLV in hand. Parse the TLV. */
60
3.73M
    rc = fuzz_parse_tlv(&fuzz, &tlv);
61
62
3.73M
    if(rc != 0) {
63
      /* Failed to parse the TLV. Can't continue. */
64
24.5k
      goto EXIT_LABEL;
65
24.5k
    }
66
3.73M
  }
67
68
199k
  if(tlv_rc != TLV_RC_NO_MORE_TLVS) {
69
    /* A TLV call failed. Can't continue. */
70
3.14k
    goto EXIT_LABEL;
71
3.14k
  }
72
73
  /* Set up the standard easy options. */
74
196k
  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
186k
  if(fuzz.header_list != NULL) {
81
10.3k
    curl_easy_setopt(fuzz.easy, CURLOPT_HTTPHEADER, fuzz.header_list);
82
10.3k
  }
83
84
186k
  if(fuzz.mail_recipients_list != NULL) {
85
1.26k
    curl_easy_setopt(fuzz.easy, CURLOPT_MAIL_RCPT, fuzz.mail_recipients_list);
86
1.26k
  }
87
88
186k
  if(fuzz.mime != NULL) {
89
4.81k
    curl_easy_setopt(fuzz.easy, CURLOPT_MIMEPOST, fuzz.mime);
90
4.81k
  }
91
92
186k
  if (fuzz.httppost != NULL) {
93
1.02k
    curl_easy_setopt(fuzz.easy, CURLOPT_HTTPPOST, fuzz.httppost);
94
1.02k
  }
95
96
  /* Run the transfer. */
97
186k
  fuzz_handle_transfer(&fuzz);
98
99
224k
EXIT_LABEL:
100
101
224k
  fuzz_terminate_fuzz_data(&fuzz);
102
103
  /* This function must always return 0. Non-zero codes are reserved. */
104
224k
  return 0;
105
186k
}
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.92M
{
112
3.92M
  uint32_t u;
113
3.92M
  u = (b[0] << 24) + (b[1] << 16) + (b[2] << 8) + b[3];
114
3.92M
  return u;
115
3.92M
}
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.81M
{
122
3.81M
  uint16_t u;
123
3.81M
  u = (b[0] << 8) + b[1];
124
3.81M
  return u;
125
3.81M
}
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
224k
{
134
224k
  int rc = 0;
135
224k
  int ii;
136
137
  /* Initialize the fuzz data. */
138
224k
  memset(fuzz, 0, sizeof(FUZZ_DATA));
139
140
  /* Create an easy handle. This will have all of the settings configured on
141
     it. */
142
224k
  fuzz->easy = curl_easy_init();
143
224k
  FCHECK(fuzz->easy != NULL);
144
145
  /* Set up the state parser */
146
224k
  fuzz->state.data = data;
147
224k
  fuzz->state.data_len = data_len;
148
149
  /* Set up the state of the server sockets. */
150
672k
  for(ii = 0; ii < FUZZ_NUM_CONNECTIONS; ii++) {
151
448k
    fuzz->sockman[ii].index = ii;
152
448k
    fuzz->sockman[ii].fd_state = FUZZ_SOCK_CLOSED;
153
448k
  }
154
155
  /* Check for verbose mode. */
156
224k
  fuzz->verbose = (getenv("FUZZ_VERBOSE") != NULL);
157
158
224k
  FCHECK(setenv("CURL_HSTS_HTTP", "1", 0) == 0);
159
224k
  FCHECK(setenv("CURL_ALTSVC_HTTP", "1", 0) == 0);
160
161
224k
EXIT_LABEL:
162
163
224k
  return rc;
164
224k
}
165
166
/**
167
 * Set standard options on the curl easy.
168
 */
169
int fuzz_set_easy_options(FUZZ_DATA *fuzz)
170
196k
{
171
196k
  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
196k
  FTRY(curl_easy_setopt(fuzz->easy,
176
196k
                        CURLOPT_OPENSOCKETFUNCTION,
177
196k
                        fuzz_open_socket));
178
196k
  FTRY(curl_easy_setopt(fuzz->easy, CURLOPT_OPENSOCKETDATA, fuzz));
179
180
  /* In case something tries to set a socket option, intercept this. */
181
196k
  FTRY(curl_easy_setopt(fuzz->easy,
182
196k
                        CURLOPT_SOCKOPTFUNCTION,
183
196k
                        fuzz_sockopt_callback));
184
185
  /* Set the standard read function callback. */
186
196k
  FTRY(curl_easy_setopt(fuzz->easy,
187
196k
                        CURLOPT_READFUNCTION,
188
196k
                        fuzz_read_callback));
189
196k
  FTRY(curl_easy_setopt(fuzz->easy, CURLOPT_READDATA, fuzz));
190
191
  /* Set the standard write function callback. */
192
196k
  FTRY(curl_easy_setopt(fuzz->easy,
193
196k
                        CURLOPT_WRITEFUNCTION,
194
196k
                        fuzz_write_callback));
195
196k
  FTRY(curl_easy_setopt(fuzz->easy, CURLOPT_WRITEDATA, fuzz));
196
197
  /* Set the writable cookie jar path so cookies are tested. */
198
196k
  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
196k
  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
196k
  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
196k
  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
196k
  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
196k
  FTRY(curl_easy_setopt(fuzz->easy, CURLOPT_NETRC_FILE, FUZZ_NETRC_FILE_PATH));
214
215
  /* Time out requests quickly. */
216
196k
  FTRY(curl_easy_setopt(fuzz->easy, CURLOPT_TIMEOUT_MS, 200L));
217
196k
  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
196k
  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
196k
  fuzz->connect_to_list = curl_slist_append(NULL, "::127.0.1.127:");
226
196k
  FTRY(curl_easy_setopt(fuzz->easy, CURLOPT_CONNECT_TO, fuzz->connect_to_list));
227
228
  /* Limit the protocols in use by this fuzzer. */
229
196k
  FTRY(fuzz_set_allowed_protocols(fuzz));
230
231
196k
EXIT_LABEL:
232
233
196k
  return rc;
234
186k
}
235
236
/**
237
 * Terminate the fuzz data structure, including freeing any allocated memory.
238
 */
239
void fuzz_terminate_fuzz_data(FUZZ_DATA *fuzz)
240
224k
{
241
224k
  int ii;
242
243
224k
  fuzz_free((void **)&fuzz->postfields);
244
245
672k
  for(ii = 0; ii < FUZZ_NUM_CONNECTIONS; ii++) {
246
448k
    if(fuzz->sockman[ii].fd_state != FUZZ_SOCK_CLOSED) {
247
110k
      close(fuzz->sockman[ii].fd);
248
110k
      fuzz->sockman[ii].fd_state = FUZZ_SOCK_CLOSED;
249
110k
    }
250
448k
  }
251
252
224k
  if(fuzz->connect_to_list != NULL) {
253
196k
    curl_slist_free_all(fuzz->connect_to_list);
254
196k
    fuzz->connect_to_list = NULL;
255
196k
  }
256
257
224k
  if(fuzz->header_list != NULL) {
258
10.5k
    curl_slist_free_all(fuzz->header_list);
259
10.5k
    fuzz->header_list = NULL;
260
10.5k
  }
261
262
224k
  if(fuzz->mail_recipients_list != NULL) {
263
1.39k
    curl_slist_free_all(fuzz->mail_recipients_list);
264
1.39k
    fuzz->mail_recipients_list = NULL;
265
1.39k
  }
266
267
224k
  if(fuzz->mime != NULL) {
268
5.55k
    curl_mime_free(fuzz->mime);
269
5.55k
    fuzz->mime = NULL;
270
5.55k
  }
271
272
224k
  if(fuzz->easy != NULL) {
273
224k
    curl_easy_cleanup(fuzz->easy);
274
224k
    fuzz->easy = NULL;
275
224k
  }
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
224k
  if (fuzz->httppost != NULL) {
282
1.17k
    curl_formfree(fuzz->httppost);
283
1.17k
    fuzz->httppost = NULL;
284
1.17k
  }
285
286
  // free after httppost and last_post_part.
287
224k
  if (fuzz->post_body != NULL) {
288
1.17k
    fuzz_free((void **)&fuzz->post_body);
289
1.17k
  }
290
224k
}
291
292
/**
293
 * If a pointer has been allocated, free that pointer.
294
 */
295
void fuzz_free(void **ptr)
296
3.97M
{
297
3.97M
  if(*ptr != NULL) {
298
736k
    free(*ptr);
299
736k
    *ptr = NULL;
300
736k
  }
301
3.97M
}
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
186k
{
309
186k
  int rc = 0;
310
186k
  CURLM *multi_handle;
311
186k
  int still_running; /* keep number of running handles */
312
186k
  CURLMsg *msg; /* for picking up messages with the transfer status */
313
186k
  int msgs_left; /* how many messages are left */
314
186k
  int double_timeout = 0;
315
186k
  fd_set fdread;
316
186k
  fd_set fdwrite;
317
186k
  fd_set fdexcep;
318
186k
  struct timeval timeout;
319
186k
  int select_rc;
320
186k
  CURLMcode mc;
321
186k
  int maxfd = -1;
322
186k
  long curl_timeo = -1;
323
186k
  int ii;
324
186k
  FUZZ_SOCKET_MANAGER *sman[FUZZ_NUM_CONNECTIONS];
325
326
558k
  for(ii = 0; ii < FUZZ_NUM_CONNECTIONS; ii++) {
327
372k
    sman[ii] = &fuzz->sockman[ii];
328
329
    /* Set up the starting index for responses. */
330
372k
    sman[ii]->response_index = 1;
331
372k
  }
332
333
  /* init a multi stack */
334
186k
  multi_handle = curl_multi_init();
335
336
  /* add the individual transfers */
337
186k
  curl_multi_add_handle(multi_handle, fuzz->easy);
338
339
  /* Do an initial process. This might end the transfer immediately. */
340
186k
  curl_multi_perform(multi_handle, &still_running);
341
186k
  FV_PRINTF(fuzz,
342
186k
            "FUZZ: Initial perform; still running? %d \n",
343
186k
            still_running);
344
345
227k
  while(still_running) {
346
    /* Reset the sets of file descriptors. */
347
47.9k
    FD_ZERO(&fdread);
348
47.9k
    FD_ZERO(&fdwrite);
349
47.9k
    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
47.9k
    timeout.tv_sec = 0;
355
47.9k
    timeout.tv_usec = 10000;
356
357
    /* get file descriptors from the transfers */
358
47.9k
    mc = curl_multi_fdset(multi_handle, &fdread, &fdwrite, &fdexcep, &maxfd);
359
47.9k
    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
143k
    for(ii = 0; ii < FUZZ_NUM_CONNECTIONS; ii++) {
366
      /* Add the socket FD into the readable set if connected. */
367
95.9k
      if(sman[ii]->fd_state == FUZZ_SOCK_OPEN) {
368
31.4k
        FD_SET(sman[ii]->fd, &fdread);
369
370
        /* Work out the maximum FD between the cURL file descriptors and the
371
           server FD. */
372
31.4k
        maxfd = FUZZ_MAX(sman[ii]->fd, maxfd);
373
31.4k
      }
374
95.9k
    }
375
376
    /* Work out what file descriptors need work. */
377
47.9k
    rc = fuzz_select(maxfd + 1, &fdread, &fdwrite, &fdexcep, &timeout);
378
379
47.9k
    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
47.9k
    int server_data_sent = 0;
388
143k
    for(ii = 0; ii < FUZZ_NUM_CONNECTIONS; ii++) {
389
95.8k
      if(sman[ii]->fd_state == FUZZ_SOCK_OPEN &&
390
95.8k
         FD_ISSET(sman[ii]->fd, &fdread)) {
391
28.4k
        rc = fuzz_send_next_response(fuzz, sman[ii]);
392
28.4k
        if(rc != 0) {
393
          /* Failed to send a response. Break out here. */
394
83
          break;
395
83
        }
396
28.3k
        server_data_sent = 1;
397
28.3k
      }
398
95.8k
    }
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
47.9k
    if(!server_data_sent) {
405
19.5k
      FV_PRINTF(fuzz, "FUZZ: No data sent; stall count %d \n", double_timeout);
406
19.5k
      if(double_timeout == 1) {
407
6.82k
        break;
408
6.82k
      }
409
12.7k
      double_timeout = 1;
410
12.7k
    }
411
28.3k
    else {
412
28.3k
      double_timeout = 0;
413
28.3k
    }
414
415
41.1k
    curl_multi_perform(multi_handle, &still_running);
416
41.1k
  }
417
418
  /* Remove the easy handle from the multi stack. */
419
186k
  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
186k
  curl_multi_cleanup(multi_handle);
424
425
186k
  return rc;
426
186k
}
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
28.4k
{
433
28.4k
  int rc = 0;
434
28.4k
  ssize_t ret_in;
435
28.4k
  ssize_t ret_out;
436
28.4k
  char buffer[8192];
437
28.4k
  const uint8_t *data;
438
28.4k
  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
68.3k
  do {
444
68.3k
    ret_in = read(sman->fd, buffer, sizeof(buffer));
445
68.3k
    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
68.3k
  } while (ret_in > 0);
451
452
  /* Now send a response to the request that the client just made. */
453
28.4k
  FV_PRINTF(fuzz,
454
28.4k
            "FUZZ[%d]: Sending next response: %d \n",
455
28.4k
            sman->index,
456
28.4k
            sman->response_index);
457
28.4k
  data = sman->responses[sman->response_index].data;
458
28.4k
  data_len = sman->responses[sman->response_index].data_len;
459
460
28.4k
  if(data != NULL) {
461
28.4k
    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
83
      rc = -1;
465
83
    }
466
28.4k
  }
467
468
  /* Work out if there are any more responses. If not, then shut down the
469
     server. */
470
28.4k
  sman->response_index++;
471
472
28.4k
  if(sman->response_index >= TLV_MAX_NUM_RESPONSES ||
473
28.4k
     sman->responses[sman->response_index].data == NULL) {
474
23.2k
    FV_PRINTF(fuzz,
475
23.2k
              "FUZZ[%d]: Shutting down server socket: %d \n",
476
23.2k
              sman->index,
477
23.2k
              sman->fd);
478
23.2k
    shutdown(sman->fd, SHUT_WR);
479
23.2k
    sman->fd_state = FUZZ_SOCK_SHUTDOWN;
480
23.2k
  }
481
482
28.4k
  return rc;
483
28.4k
}
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
47.9k
                struct timeval *timeout) {
493
47.9k
  return select(nfds, readfds, writefds, exceptfds, timeout);
494
47.9k
}
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
196k
{
503
196k
  int rc = 0;
504
196k
  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
20.1k
  FTRY(curl_easy_setopt(fuzz->easy, CURLOPT_CONNECT_ONLY, 2L));
573
20.1k
#endif
574
575
196k
  FTRY(curl_easy_setopt(fuzz->easy, CURLOPT_PROTOCOLS_STR, allowed_protocols));
576
577
196k
EXIT_LABEL:
578
579
196k
  return rc;
580
186k
}
fuzz_set_allowed_protocols(fuzz_data*)
Line
Count
Source
502
176k
{
503
176k
  int rc = 0;
504
176k
  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
176k
#ifdef FUZZ_PROTOCOLS_LDAP
540
176k
  allowed_protocols = "ldap,ldaps";
541
176k
#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
176k
  FTRY(curl_easy_setopt(fuzz->easy, CURLOPT_PROTOCOLS_STR, allowed_protocols));
576
577
176k
EXIT_LABEL:
578
579
176k
  return rc;
580
166k
}
fuzz_set_allowed_protocols(fuzz_data*)
Line
Count
Source
502
20.1k
{
503
20.1k
  int rc = 0;
504
20.1k
  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
20.1k
#ifdef FUZZ_PROTOCOLS_WS
570
  // http is required by websockets
571
20.1k
  allowed_protocols = "http,ws,wss";
572
20.1k
  FTRY(curl_easy_setopt(fuzz->easy, CURLOPT_CONNECT_ONLY, 2L));
573
20.1k
#endif
574
575
20.1k
  FTRY(curl_easy_setopt(fuzz->easy, CURLOPT_PROTOCOLS_STR, allowed_protocols));
576
577
20.1k
EXIT_LABEL:
578
579
20.1k
  return rc;
580
20.1k
}