]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
fuzz: add a fuzzer for calendarspec
authorFrantisek Sumsal <frantisek@sumsal.cz>
Mon, 11 Mar 2019 18:56:34 +0000 (19:56 +0100)
committerFrantisek Sumsal <frantisek@sumsal.cz>
Tue, 12 Mar 2019 10:57:09 +0000 (11:57 +0100)
src/fuzz/fuzz-calendarspec.c [new file with mode: 0644]
src/fuzz/meson.build

diff --git a/src/fuzz/fuzz-calendarspec.c b/src/fuzz/fuzz-calendarspec.c
new file mode 100644 (file)
index 0000000..55d8613
--- /dev/null
@@ -0,0 +1,24 @@
+/* SPDX-License-Identifier: LGPL-2.1+ */
+
+#include "alloc-util.h"
+#include "calendarspec.h"
+#include "fd-util.h"
+#include "fuzz.h"
+
+int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
+        _cleanup_(calendar_spec_freep) CalendarSpec *cspec = NULL;
+        _cleanup_free_ char *str = NULL, *p = NULL;
+
+        if (!getenv("SYSTEMD_LOG_LEVEL"))
+                log_set_max_level(LOG_CRIT);
+
+        str = memdup_suffix0(data, size);
+
+        if (calendar_spec_from_string(str, &cspec) > 0) {
+                (void) calendar_spec_valid(cspec);
+                (void) calendar_spec_normalize(cspec);
+                (void) calendar_spec_to_string(cspec, &p);
+        }
+
+        return 0;
+}
index 4a242f8a6ce17917c2e656612ce6ca8a7ea50e75..99d7e06debca9aa67f1078fcd253fa5f504bbe3f 100644 (file)
@@ -129,4 +129,8 @@ fuzzers += [
          [libshared,
           libnspawn_core],
          []],
+
+        [['src/fuzz/fuzz-calendarspec.c'],
+         [libshared],
+         []],
 ]