]> git.ipfire.org Git - thirdparty/systemd.git/blob - src/fuzz/fuzz-main.c
Merge pull request #7042 from vcaputo/iteratedcache
[thirdparty/systemd.git] / src / fuzz / fuzz-main.c
1 /* SPDX-License-Identifier: LGPL-2.1+ */
2 /***
3 Copyright 2018 Jonathan Rudenberg
4
5 systemd is free software; you can redistribute it and/or modify it
6 under the terms of the GNU Lesser General Public License as published by
7 the Free Software Foundation; either version 2.1 of the License, or
8 (at your option) any later version.
9
10 systemd is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General Public License
16 along with systemd; If not, see <http://www.gnu.org/licenses/>.
17 ***/
18
19 #include "alloc-util.h"
20 #include "log.h"
21 #include "fileio.h"
22 #include "fuzz.h"
23
24 /* This is a test driver for the systemd fuzzers that provides main function
25 * for regression testing outside of oss-fuzz (https://github.com/google/oss-fuzz)
26 *
27 * It reads files named on the command line and passes them one by one into the
28 * fuzzer that it is compiled into. */
29
30 int main(int argc, char **argv) {
31 int i, r;
32 size_t size;
33 char *name;
34
35 log_set_max_level(LOG_DEBUG);
36 for (i = 1; i < argc; i++) {
37 _cleanup_free_ char *buf = NULL;
38
39 name = argv[i];
40 r = read_full_file(name, &buf, &size);
41 if (r < 0) {
42 log_error_errno(r, "Failed to open '%s': %m", name);
43 return EXIT_FAILURE;
44 }
45 printf("%s... ", name);
46 fflush(stdout);
47 (void) LLVMFuzzerTestOneInput((uint8_t*)buf, size);
48 printf("ok\n");
49 }
50 return EXIT_SUCCESS;
51 }