summaryrefslogtreecommitdiff
path: root/src/fuzz
diff options
context:
space:
mode:
authorEvgeny Vereshchagin <evvers@ya.ru>2018-11-15 17:52:57 +0100
committerEvgeny Vereshchagin <evvers@ya.ru>2018-11-16 08:44:35 +0100
commit8857fb9beb9dcb95a6ce1be14dc94c4dc4cd3ea3 (patch)
tree090d8fef7040e79605301eee0eba7d7a012c3711 /src/fuzz
parenta6da77b71bd3a86f4b24d535b58f57ba83f5669d (diff)
downloadsystemd-8857fb9beb9dcb95a6ce1be14dc94c4dc4cd3ea3.tar.gz
systemd-8857fb9beb9dcb95a6ce1be14dc94c4dc4cd3ea3.tar.bz2
systemd-8857fb9beb9dcb95a6ce1be14dc94c4dc4cd3ea3.zip
tests: add a fuzzer for dev_kmsg_record
Diffstat (limited to 'src/fuzz')
-rw-r--r--src/fuzz/fuzz-journald-kmsg.c29
-rw-r--r--src/fuzz/meson.build5
2 files changed, 34 insertions, 0 deletions
diff --git a/src/fuzz/fuzz-journald-kmsg.c b/src/fuzz/fuzz-journald-kmsg.c
new file mode 100644
index 0000000000..5d99d244b5
--- /dev/null
+++ b/src/fuzz/fuzz-journald-kmsg.c
@@ -0,0 +1,29 @@
+/* SPDX-License-Identifier: LGPL-2.1+ */
+
+#include "fuzz.h"
+#include "journald-kmsg.h"
+
+int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
+ Server s = {};
+ _cleanup_free_ char *buffer = NULL;
+
+ if (size == 0)
+ return 0;
+
+ s = (Server) {
+ .native_fd = -1,
+ .stdout_fd = -1,
+ .dev_kmsg_fd = -1,
+ .audit_fd = -1,
+ .hostname_fd = -1,
+ .notify_fd = -1,
+ .storage = STORAGE_NONE,
+ };
+ assert_se(sd_event_default(&s.event) >= 0);
+ buffer = memdup(data, size);
+ assert_se(buffer);
+ dev_kmsg_record(&s, buffer, size);
+ server_done(&s);
+
+ return 0;
+}
diff --git a/src/fuzz/meson.build b/src/fuzz/meson.build
index f1f1db2181..5fd3093f07 100644
--- a/src/fuzz/meson.build
+++ b/src/fuzz/meson.build
@@ -51,6 +51,11 @@ fuzzers += [
libshared],
[libmount]],
+ [['src/fuzz/fuzz-journald-kmsg.c'],
+ [libjournal_core,
+ libshared],
+ [libselinux]],
+
[['src/fuzz/fuzz-journald-native.c',
'src/fuzz/fuzz-journald.c'],
[libjournal_core,