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 | | /* Shared helpers for the libFuzzer harnesses. */ |
29 | | #ifndef FUZZ_H |
30 | | #define FUZZ_H |
31 | | |
32 | | #define HTS_INTERNAL_BYTECODE |
33 | | |
34 | | #include <stddef.h> |
35 | | #include <stdint.h> |
36 | | #include <stdio.h> |
37 | | #include <stdlib.h> |
38 | | #include <string.h> |
39 | | |
40 | | #include "htsbase.h" |
41 | | #include "htsbuf.h" |
42 | | |
43 | | /* Return the span over the SIZE input bytes at DATA. */ |
44 | | static HTS_INLINE HTS_UNUSED hts_span fuzz_span(const uint8_t *data, |
45 | 1.17k | size_t size) { |
46 | 1.17k | return hts_span_at((const char *) data, size); |
47 | 1.17k | } |
48 | | |
49 | | /* Create <$TMPDIR or /tmp>/<prefix>-XXXXXX in dir, and run cleanup at exit. |
50 | | Returns HTS_FALSE and registers nothing when mkdtemp fails. */ |
51 | | HTS_UNUSED static hts_boolean fuzz_tmpdir(hts_buf dir, const char *prefix, |
52 | 0 | void (*cleanup)(void)) { |
53 | 0 | const char *const tmp = getenv("TMPDIR"); |
54 | 0 |
|
55 | 0 | hts_buf_printf_clip(dir, "%s/%s-XXXXXX", |
56 | 0 | tmp != NULL && *tmp != '\0' ? tmp : "/tmp", prefix); |
57 | 0 | if (mkdtemp(dir.p) == NULL) |
58 | 0 | return HTS_FALSE; |
59 | 0 | atexit(cleanup); |
60 | 0 | return HTS_TRUE; |
61 | 0 | } |
62 | | |
63 | | int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size); |
64 | | |
65 | | #endif |