/src/wget/fuzz/wget_progress_fuzzer.c
Line | Count | Source (jump to first uncovered line) |
1 | | /* |
2 | | * Copyright (c) 2017-2019, 2021-2023 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 | | |
34 | | #undef fopen_wgetrc |
35 | | |
36 | | #ifdef __cplusplus |
37 | | extern "C" { |
38 | | #endif |
39 | | #include "progress.h" |
40 | | |
41 | | // declarations for wget internal functions |
42 | | int main_wget(int argc, const char **argv); |
43 | | void cleanup(void); |
44 | | FILE *fopen_wget(const char *pathname, const char *mode); |
45 | | FILE *fopen_wgetrc(const char *pathname, const char *mode); |
46 | | void exit_wget(int status); |
47 | | #ifdef __cplusplus |
48 | | } |
49 | | #endif |
50 | | |
51 | | #include "fuzzer.h" |
52 | | |
53 | | FILE *fopen_wget(const char *pathname, const char *mode) |
54 | 0 | { |
55 | 0 | (void) pathname; |
56 | 0 | return fopen("/dev/null", mode); |
57 | 0 | } |
58 | | |
59 | | FILE *fopen_wgetrc(const char *pathname, const char *mode) |
60 | 0 | { |
61 | 0 | (void) pathname; |
62 | 0 | (void) mode; |
63 | 0 | return NULL; |
64 | 0 | } |
65 | | |
66 | | #ifdef FUZZING |
67 | | void exit_wget(int status) |
68 | 0 | { |
69 | 0 | (void) status; |
70 | 0 | } |
71 | | #endif |
72 | | |
73 | | |
74 | 2.49k | #define NAMEPOS (2 * sizeof(wgint) + sizeof(double)) |
75 | | int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) |
76 | 933 | { |
77 | 933 | void *progress; |
78 | | |
79 | 933 | if (size > 4096) // same as max_len = ... in .options file |
80 | 9 | return 0; |
81 | | |
82 | 924 | if (size < NAMEPOS) |
83 | 9 | return 0; |
84 | | |
85 | | // CLOSE_STDERR |
86 | | |
87 | 915 | wgint start = ((wgint *) data)[0]; |
88 | 915 | wgint end = ((wgint *) data)[1]; |
89 | 915 | double dltime = ((wgint *) data)[2]; |
90 | | |
91 | 915 | if (start < 0 || end < 0) |
92 | 129 | return 0; |
93 | | |
94 | 786 | if (start > end) { |
95 | 410 | wgint x = start; |
96 | 410 | start = end; |
97 | 410 | end = x; |
98 | 410 | } |
99 | | |
100 | | // double dltime = ((double *) (data + 2 * sizeof(wgint)))[0]; |
101 | | |
102 | 786 | char *filename = strndup((char *) (data + NAMEPOS), size - NAMEPOS); |
103 | | |
104 | | // printf("%ld %ld %lf %s\n", start, end, dltime, filename); |
105 | | |
106 | 786 | set_progress_implementation("bar:force"); // [:force][:noscroll] |
107 | | |
108 | 786 | progress = progress_create (filename, start, end); |
109 | 786 | progress_update (progress, 0, dltime); |
110 | 786 | progress_update (progress, end - start, dltime); |
111 | 786 | progress_finish (progress, dltime); |
112 | | |
113 | 786 | set_progress_implementation("dot:default");// [:default|:binary|:mega|:giga] |
114 | 786 | progress = progress_create (filename, start, end); |
115 | 786 | progress_update (progress, 0, dltime); |
116 | 786 | progress_update (progress, end - start, dltime); |
117 | 786 | progress_finish (progress, dltime); |
118 | | |
119 | 786 | set_progress_implementation("dot:binary");// [:default|:binary|:mega|:giga] |
120 | 786 | progress = progress_create (filename, start, end); |
121 | 786 | progress_update (progress, 0, dltime); |
122 | 786 | progress_update (progress, end - start, dltime); |
123 | 786 | progress_finish (progress, dltime); |
124 | | |
125 | 786 | set_progress_implementation("dot:mega");// [:default|:binary|:mega|:giga] |
126 | 786 | progress = progress_create (filename, start, end); |
127 | 786 | progress_update (progress, 0, dltime); |
128 | 786 | progress_update (progress, end - start, dltime); |
129 | 786 | progress_finish (progress, dltime); |
130 | | |
131 | 786 | set_progress_implementation("dot:giga");// [:default|:binary|:mega|:giga] |
132 | 786 | progress = progress_create (filename, start, end); |
133 | 786 | progress_update (progress, 0, dltime); |
134 | 786 | progress_update (progress, end - start, dltime); |
135 | 786 | progress_finish (progress, dltime); |
136 | | |
137 | 786 | free(filename); |
138 | | |
139 | | // RESTORE_STDERR |
140 | | |
141 | 786 | return 0; |
142 | 915 | } |