Coverage Report

Created: 2023-03-26 06:11

/src/curl_fuzzer/fuzz_url.cc
Line
Count
Source
1
/***************************************************************************
2
 *                                  _   _ ____  _
3
 *  Project                     ___| | | |  _ \| |
4
 *                             / __| | | | |_) | |
5
 *                            | (__| |_| |  _ <| |___
6
 *                             \___|\___/|_| \_\_____|
7
 *
8
 * Copyright (C) 2017 - 2022, 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 <stdlib.h>
25
#include <string.h>
26
#include <curl/curl.h>
27
#include "curl_fuzzer.h"
28
29
/**
30
 * Fuzzing entry point. This function is passed a buffer containing a test
31
 * case.  This test case should drive the CURL URL API.
32
 */
33
extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
34
1.85k
{
35
1.85k
  CURLU *uh;
36
1.85k
  char *newp;
37
38
1.85k
  uh = curl_url();
39
40
  /* it works on a null-terminated string */
41
1.85k
  if(size) {
42
1.85k
    newp = (char *)malloc(size + 1);
43
1.85k
    if(newp) {
44
1.85k
      memcpy(newp, data, size);
45
      /* make sure it is zero terminated */
46
1.85k
      newp[size] = 0;
47
1.85k
      curl_url_set(uh, CURLUPART_URL, newp, CURLU_GUESS_SCHEME);
48
1.85k
      free(newp);
49
1.85k
    }
50
1.85k
  }
51
1.85k
  curl_url_cleanup(uh);
52
53
  /* This function must always return 0. Non-zero codes are reserved. */
54
1.85k
  return 0;
55
1.85k
}
56