1 /*
2 Unix SMB/CIFS implementation.
3
4 Fuzz driver (AFL style)
5
6 Copyright (C) Andrew Bartlett 2019
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
22 #include "includes.h"
23 #include "lib/util/samba_util.h"
24 #include "fuzzing.h"
25
main(int argc,char * argv[])26 int main(int argc, char *argv[]) {
27 int ret;
28 size_t size = 0;
29 #ifdef __AFL_LOOP
30 while (__AFL_LOOP(1000))
31 #else
32 int i;
33 for (i = 0; i < argc; i++) {
34 uint8_t *buf = (uint8_t *)file_load(argv[i],
35 &size,
36 0,
37 NULL);
38 ret = LLVMFuzzerTestOneInput(buf, size);
39 TALLOC_FREE(buf);
40 if (ret != 0) {
41 return ret;
42 }
43 }
44 if (i == 0)
45 #endif
46 {
47 uint8_t *buf = (uint8_t *)fd_load(0, &size, 0, NULL);
48 if (buf == NULL) {
49 exit(1);
50 }
51
52 ret = LLVMFuzzerTestOneInput(buf, size);
53 TALLOC_FREE(buf);
54 }
55 return ret;
56 }
57