]> git.ipfire.org Git - thirdparty/systemd.git/blobdiff - src/fuzz/fuzz-main.c
tests: add a fuzzer for the udev rules parser (#10929)
[thirdparty/systemd.git] / src / fuzz / fuzz-main.c
index cace47ba22e9cc2248c687c6e9f6f7e8b3aadf3e..d5c998498971a88c16fa35a2a3545ad1a6f8d22f 100644 (file)
@@ -1,25 +1,10 @@
 /* SPDX-License-Identifier: LGPL-2.1+ */
-/***
-  Copyright 2018 Jonathan Rudenberg
-
-  systemd is free software; you can redistribute it and/or modify it
-  under the terms of the GNU Lesser General Public License as published by
-  the Free Software Foundation; either version 2.1 of the License, or
-  (at your option) any later version.
-
-  systemd is distributed in the hope that it will be useful, but
-  WITHOUT ANY WARRANTY; without even the implied warranty of
-  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-  Lesser General Public License for more details.
-
-  You should have received a copy of the GNU Lesser General Public License
-  along with systemd; If not, see <http://www.gnu.org/licenses/>.
-***/
 
 #include "alloc-util.h"
 #include "log.h"
 #include "fileio.h"
 #include "fuzz.h"
+#include "tests.h"
 
 /* This is a test driver for the systemd fuzzers that provides main function
  * for regression testing outside of oss-fuzz (https://github.com/google/oss-fuzz)
  * It reads files named on the command line and passes them one by one into the
  * fuzzer that it is compiled into. */
 
+/* This one was borrowed from
+ * https://github.com/google/oss-fuzz/blob/646fca1b506b056db3a60d32c4a1a7398f171c94/infra/base-images/base-runner/bad_build_check#L19
+ */
+#define MIN_NUMBER_OF_RUNS 4
+
 int main(int argc, char **argv) {
         int i, r;
         size_t size;
         char *name;
 
-        log_set_max_level(LOG_DEBUG);
-        log_parse_environment();
-        log_open();
+        test_setup_logging(LOG_DEBUG);
 
         for (i = 1; i < argc; i++) {
                 _cleanup_free_ char *buf = NULL;
@@ -47,7 +35,9 @@ int main(int argc, char **argv) {
                 }
                 printf("%s... ", name);
                 fflush(stdout);
-                (void) LLVMFuzzerTestOneInput((uint8_t*)buf, size);
+                for (int j = 0; j < MIN_NUMBER_OF_RUNS; j++)
+                        if (LLVMFuzzerTestOneInput((uint8_t*)buf, size) == EXIT_TEST_SKIP)
+                                return EXIT_TEST_SKIP;
                 printf("ok\n");
         }