]> git.ipfire.org Git - thirdparty/systemd.git/blame - src/fuzz/fuzz-main.c
Merge pull request #11827 from keszybz/pkgconfig-variables
[thirdparty/systemd.git] / src / fuzz / fuzz-main.c
CommitLineData
7db7d5b7 1/* SPDX-License-Identifier: LGPL-2.1+ */
7db7d5b7
JR
2
3#include "alloc-util.h"
4#include "log.h"
5#include "fileio.h"
6#include "fuzz.h"
6d7c4033 7#include "tests.h"
7db7d5b7
JR
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
a7891d20
EV
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
7db7d5b7
JR
20int main(int argc, char **argv) {
21 int i, r;
22 size_t size;
23 char *name;
24
6d7c4033 25 test_setup_logging(LOG_DEBUG);
b872843c 26
7db7d5b7
JR
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);
a7891d20 38 for (int j = 0; j < MIN_NUMBER_OF_RUNS; j++)
2e646cbe
EV
39 if (LLVMFuzzerTestOneInput((uint8_t*)buf, size) == EXIT_TEST_SKIP)
40 return EXIT_TEST_SKIP;
7db7d5b7
JR
41 printf("ok\n");
42 }
b872843c 43
7db7d5b7
JR
44 return EXIT_SUCCESS;
45}