/src/httrack/fuzz/fuzz-unescape.c
Line | Count | Source |
1 | | /* ------------------------------------------------------------ */ |
2 | | /* |
3 | | HTTrack Website Copier, Offline Browser for Windows and Unix |
4 | | Copyright (C) 1998 Xavier Roche and other contributors |
5 | | |
6 | | SPDX-License-Identifier: GPL-3.0-or-later |
7 | | |
8 | | This program is free software: you can redistribute it and/or modify |
9 | | it under the terms of the GNU General Public License as published by |
10 | | the Free Software Foundation, either version 3 of the License, or |
11 | | (at your option) any later version. |
12 | | |
13 | | This program is distributed in the hope that it will be useful, |
14 | | but WITHOUT ANY WARRANTY; without even the implied warranty of |
15 | | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16 | | GNU General Public License for more details. |
17 | | |
18 | | You should have received a copy of the GNU General Public License |
19 | | along with this program. If not, see <http://www.gnu.org/licenses/>. |
20 | | |
21 | | Ethical use: we kindly ask that you NOT use this software to harvest email |
22 | | addresses or to collect any other private information about people. Doing so |
23 | | would dishonor our work and waste the many hours we have spent on it. |
24 | | |
25 | | Please visit our Website: http://www.httrack.com |
26 | | */ |
27 | | |
28 | | /* Fuzz the URL percent-decoders (htslib.c). First input byte picks the |
29 | | output buffer size, so the bounded-copy contract is exercised. */ |
30 | | #include "fuzz.h" |
31 | | #include "httrack-library.h" |
32 | | |
33 | 28.8k | int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) { |
34 | 28.8k | static const size_t bsizes[] = {1, 2, 16, 256, 8192}; |
35 | 28.8k | size_t bsize; |
36 | 28.8k | char *s, *catbuff; |
37 | | |
38 | 28.8k | if (size == 0) |
39 | 0 | return 0; |
40 | 28.8k | bsize = bsizes[data[0] % (sizeof(bsizes) / sizeof(bsizes[0]))]; |
41 | 28.8k | data++, size--; |
42 | 28.8k | s = fuzz_strdup(data, size); |
43 | 28.8k | catbuff = malloct(bsize); |
44 | | |
45 | 28.8k | (void) unescape_http(catbuff, bsize, s); |
46 | 28.8k | (void) unescape_http_unharm(catbuff, bsize, s, 0); |
47 | 28.8k | (void) unescape_http_unharm(catbuff, bsize, s, 1); |
48 | 28.8k | unescape_amp(s); |
49 | | |
50 | 28.8k | freet(catbuff); |
51 | | freet(s); |
52 | 28.8k | return 0; |
53 | 28.8k | } |