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