/src/wget/fuzz/wget_html_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 <dirent.h> // opendir, readdir |
24 | | #include <stdint.h> // uint8_t |
25 | | #include <stdio.h> // fmemopen |
26 | | #include <string.h> // strncmp |
27 | | #include <stdlib.h> // free |
28 | | #include <fcntl.h> // open flags |
29 | | #include <unistd.h> // close |
30 | | #include <setjmp.h> // longjmp, setjmp |
31 | | |
32 | | #include "wget.h" |
33 | | #undef fopen_wgetrc |
34 | | |
35 | | #ifdef __cplusplus |
36 | | extern "C" { |
37 | | #endif |
38 | | #include "utils.h" |
39 | | #include "html-url.h" |
40 | | #include "css-url.h" |
41 | | |
42 | | // declarations for wget internal functions |
43 | | int main_wget(int argc, const char **argv); |
44 | | void cleanup(void); |
45 | | FILE *fopen_wget(const char *pathname, const char *mode); |
46 | | FILE *fopen_wgetrc(const char *pathname, const char *mode); |
47 | | void exit_wget(int status); |
48 | | #ifdef __cplusplus |
49 | | } |
50 | | #endif |
51 | | |
52 | | #include "fuzzer.h" |
53 | | |
54 | | static const uint8_t *g_data; |
55 | | static size_t g_size; |
56 | | |
57 | | FILE *fopen_wget(const char *pathname, const char *mode) |
58 | 0 | { |
59 | 0 | return fopen("/dev/null", mode); |
60 | 0 | } |
61 | | |
62 | | FILE *fopen_wgetrc(const char *pathname, const char *mode) |
63 | 0 | { |
64 | 0 | #ifdef HAVE_FMEMOPEN |
65 | 0 | return fmemopen((void *) g_data, g_size, mode); |
66 | | #else |
67 | | return NULL; |
68 | | #endif |
69 | 0 | } |
70 | | |
71 | | #ifdef FUZZING |
72 | | void exit_wget(int status) |
73 | 0 | { |
74 | 0 | } |
75 | | #endif |
76 | | |
77 | | int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) |
78 | 11.8k | { |
79 | 11.8k | struct urlpos *urls; |
80 | 11.8k | struct file_memory fm; |
81 | | |
82 | 11.8k | if (size > 4096) // same as max_len = ... in .options file |
83 | 32 | return 0; |
84 | | |
85 | 11.8k | CLOSE_STDERR |
86 | | |
87 | 11.8k | fm.content = (char *) data; |
88 | 11.8k | fm.length = size; |
89 | 11.8k | fm.mmap_p = 0; |
90 | | |
91 | 11.8k | urls = get_urls_html_fm("xxx", &fm, "https://x.y", NULL, NULL); |
92 | 11.8k | free_urlpos(urls); |
93 | | |
94 | 11.8k | RESTORE_STDERR |
95 | | |
96 | 11.8k | return 0; |
97 | 11.8k | } |