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