/src/httrack/fuzz/fuzz-sitemap.c
Line | Count | Source |
1 | | /* ------------------------------------------------------------ */ |
2 | | /* |
3 | | HTTrack Website Copier, Offline Browser for Windows and Unix |
4 | | Copyright (C) 2026 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 sitemap <loc> scanner (htssitemap.c): raw XML, gzip-framed bodies |
29 | | and truncated streams all arrive here straight off the network. */ |
30 | | #include "fuzz.h" |
31 | | #include "htssitemap.h" |
32 | | |
33 | 542 | static hts_boolean sm_count(void *arg, const char *url) { |
34 | 542 | int *const n = (int *) arg; |
35 | | |
36 | 542 | (void) url; |
37 | 542 | (*n)++; |
38 | 542 | return HTS_TRUE; |
39 | 542 | } |
40 | | |
41 | 29.6k | int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) { |
42 | 29.6k | static const int caps[] = {0, 1, 16, HTS_SITEMAP_MAX_URLS_DOC}; |
43 | 29.6k | hts_boolean is_index; |
44 | 29.6k | char *body; |
45 | 29.6k | int n = 0, cap; |
46 | | |
47 | 29.6k | if (size == 0) |
48 | 0 | return 0; |
49 | 29.6k | cap = caps[data[0] % (sizeof(caps) / sizeof(caps[0]))]; |
50 | 29.6k | data++, size--; |
51 | | /* A heap copy of exactly `size` bytes: the scanner must never rely on a |
52 | | terminator, and ASan turns any overread into a report. */ |
53 | 29.6k | body = malloct(size != 0 ? size : 1); |
54 | 29.6k | memcpy(body, data, size); |
55 | | |
56 | 29.6k | (void) hts_sitemap_scan(body, size, cap, &is_index, sm_count, &n); |
57 | | |
58 | | freet(body); |
59 | 29.6k | return 0; |
60 | 29.6k | } |