/src/wget/fuzz/wget_url_fuzzer.c
Line | Count | Source (jump to first uncovered line) |
1 | | /* |
2 | | * Copyright (c) 2017-2024 Free Software Foundation, Inc. |
3 | | * |
4 | | * This file is part of GNU Wget. |
5 | | * |
6 | | * GNU Wget is free software; you can redistribute it and/or modify |
7 | | * it under the terms of the GNU General Public License as published by |
8 | | * the Free Software Foundation; either version 3 of the License, or |
9 | | * (at your option) any later version. |
10 | | * |
11 | | * GNU Wget is distributed in the hope that it will be useful, |
12 | | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 | | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
14 | | * GNU General Public License for more details. |
15 | | * |
16 | | * You should have received a copy of the GNU General Public License |
17 | | * along with Wget. If not, see <https://www.gnu.org/licenses/>. |
18 | | */ |
19 | | |
20 | | #include <config.h> |
21 | | |
22 | | #include <sys/types.h> |
23 | | #include <stdint.h> // uint8_t |
24 | | #include <stdio.h> // fmemopen |
25 | | #include <string.h> // strncmp |
26 | | #include <stdlib.h> // free |
27 | | #include <unistd.h> // close |
28 | | #include <fcntl.h> // open flags |
29 | | #include <unistd.h> // close |
30 | | |
31 | | #include "wget.h" |
32 | | #undef fopen_wgetrc |
33 | | |
34 | | #ifdef __cplusplus |
35 | | extern "C" { |
36 | | #endif |
37 | | #include "url.h" |
38 | | |
39 | | // declarations for wget internal functions |
40 | | int main_wget(int argc, const char **argv); |
41 | | void cleanup(void); |
42 | | FILE *fopen_wget(const char *pathname, const char *mode); |
43 | | FILE *fopen_wgetrc(const char *pathname, const char *mode); |
44 | | void exit_wget(int status); |
45 | | #ifdef __cplusplus |
46 | | } |
47 | | #endif |
48 | | |
49 | | #include "fuzzer.h" |
50 | | |
51 | | FILE *fopen_wget(const char *pathname, const char *mode) |
52 | 0 | { |
53 | 0 | return fopen("/dev/null", mode); |
54 | 0 | } |
55 | | |
56 | | FILE *fopen_wgetrc(const char *pathname, const char *mode) |
57 | 0 | { |
58 | 0 | return NULL; |
59 | 0 | } |
60 | | |
61 | | #ifdef FUZZING |
62 | | void exit_wget(int status) |
63 | 0 | { |
64 | 0 | } |
65 | | #endif |
66 | | |
67 | | int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) |
68 | 11.8k | { |
69 | 11.8k | struct url *url; |
70 | 11.8k | struct iri iri; |
71 | 11.8k | char *in; |
72 | | |
73 | 11.8k | if (size > 4096) // same as max_len = ... in .options file |
74 | 32 | return 0; |
75 | | |
76 | 11.8k | CLOSE_STDERR |
77 | | |
78 | 11.8k | in = (char *) malloc(size + 1); |
79 | 11.8k | memcpy(in, data, size); |
80 | 11.8k | in[size] = 0; |
81 | | |
82 | 11.8k | iri.uri_encoding = (char *) "iso-8859-1"; |
83 | 11.8k | iri.orig_url = NULL; |
84 | | |
85 | 11.8k | iri.utf8_encode = 0; |
86 | 11.8k | url = url_parse(in, NULL, &iri, 0); |
87 | 11.8k | url_free(url); |
88 | | |
89 | 11.8k | url = url_parse(in, NULL, &iri, 1); |
90 | 11.8k | url_free(url); |
91 | | |
92 | 11.8k | iri.utf8_encode = 1; |
93 | 11.8k | url = url_parse(in, NULL, &iri, 0); |
94 | 11.8k | url_free(url); |
95 | | |
96 | 11.8k | url = url_parse(in, NULL, &iri, 1); |
97 | 11.8k | url_free(url); |
98 | | |
99 | 11.8k | free(iri.orig_url); |
100 | 11.8k | free(in); |
101 | | |
102 | 11.8k | RESTORE_STDERR |
103 | | |
104 | 11.8k | return 0; |
105 | 11.8k | } |