]> git.ipfire.org Git - thirdparty/systemd.git/blob - src/fuzz/fuzz-main.c
tree-wide: beautify remaining copyright statements
[thirdparty/systemd.git] / src / fuzz / fuzz-main.c
1 /* SPDX-License-Identifier: LGPL-2.1+ */
2 /***
3 Copyright © 2018 Jonathan Rudenberg
4 ***/
5
6 #include "alloc-util.h"
7 #include "log.h"
8 #include "fileio.h"
9 #include "fuzz.h"
10
11 /* This is a test driver for the systemd fuzzers that provides main function
12 * for regression testing outside of oss-fuzz (https://github.com/google/oss-fuzz)
13 *
14 * It reads files named on the command line and passes them one by one into the
15 * fuzzer that it is compiled into. */
16
17 int main(int argc, char **argv) {
18 int i, r;
19 size_t size;
20 char *name;
21
22 log_set_max_level(LOG_DEBUG);
23 log_parse_environment();
24 log_open();
25
26 for (i = 1; i < argc; i++) {
27 _cleanup_free_ char *buf = NULL;
28
29 name = argv[i];
30 r = read_full_file(name, &buf, &size);
31 if (r < 0) {
32 log_error_errno(r, "Failed to open '%s': %m", name);
33 return EXIT_FAILURE;
34 }
35 printf("%s... ", name);
36 fflush(stdout);
37 (void) LLVMFuzzerTestOneInput((uint8_t*)buf, size);
38 printf("ok\n");
39 }
40
41 return EXIT_SUCCESS;
42 }