s3: smbd: Cleanup. smb2_file_rename_information() can never have a @GMT path in the...
[Samba.git] / lib / fuzzing / afl-fuzz-main.c
blobe0a1d264fc4f9bfcc79a9afb215803bcb5903d24
1 /*
2 Unix SMB/CIFS implementation.
4 Fuzz driver (AFL style)
6 Copyright (C) Andrew Bartlett 2019
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.
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.
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/>.
22 #include "includes.h"
23 #include "lib/util/samba_util.h"
24 #include "fuzzing.h"
26 int main(int argc, char *argv[]) {
27 int ret;
28 size_t size = 0;
29 int i;
31 ret = LLVMFuzzerInitialize(&argc, &argv);
32 if (ret != 0) {
33 printf("LLVMFuzzerInitialize returned %d\n", ret);
34 return ret;
38 #ifdef __AFL_LOOP
39 while (__AFL_LOOP(1000))
40 #else
41 for (i = 1; i < argc; i++) {
42 uint8_t *buf = (uint8_t *)file_load(argv[i],
43 &size,
45 NULL);
46 ret = LLVMFuzzerTestOneInput(buf, size);
47 TALLOC_FREE(buf);
48 if (ret != 0) {
49 printf("LLVMFuzzerTestOneInput returned %d on argument %d\n",
50 ret, i);
51 return ret;
54 if (i == 1)
55 #endif
57 uint8_t *buf = (uint8_t *)fd_load(0, &size, 0, NULL);
58 if (buf == NULL) {
59 exit(1);
62 ret = LLVMFuzzerTestOneInput(buf, size);
63 TALLOC_FREE(buf);
65 return ret;