ryantimwilson / rpms / systemd

Forked from rpms/systemd a month ago
Clone
4bff0a
From 86cf4118a04afbc67d0231f8b53cf3629258032a Mon Sep 17 00:00:00 2001
4bff0a
From: Evgeny Vereshchagin <evvers@ya.ru>
4bff0a
Date: Mon, 3 Sep 2018 06:18:26 +0300
4bff0a
Subject: [PATCH] tests: add a rudimentary fuzzer for
4bff0a
 server_process_syslog_message (#9979)
4bff0a
4bff0a
(cherry picked from commit a70f343cacf03ac51cdefb0d2e7651b04fd2e23a)
4bff0a
4bff0a
Resolves: #1696224
4bff0a
---
4bff0a
 src/fuzz/fuzz-journald-syslog.c | 29 +++++++++++++++++++++++++++++
4bff0a
 src/fuzz/meson.build            |  5 +++++
4bff0a
 2 files changed, 34 insertions(+)
4bff0a
 create mode 100644 src/fuzz/fuzz-journald-syslog.c
4bff0a
4bff0a
diff --git a/src/fuzz/fuzz-journald-syslog.c b/src/fuzz/fuzz-journald-syslog.c
4bff0a
new file mode 100644
4bff0a
index 0000000000..7730f60875
4bff0a
--- /dev/null
4bff0a
+++ b/src/fuzz/fuzz-journald-syslog.c
4bff0a
@@ -0,0 +1,29 @@
4bff0a
+/* SPDX-License-Identifier: LGPL-2.1+ */
4bff0a
+
4bff0a
+#include "alloc-util.h"
4bff0a
+#include "fuzz.h"
4bff0a
+#include "journald-server.h"
4bff0a
+#include "journald-syslog.h"
4bff0a
+#include "sd-event.h"
4bff0a
+
4bff0a
+int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
4bff0a
+        Server s = {};
4bff0a
+        char *label = NULL;
4bff0a
+        size_t label_len = 0;
4bff0a
+        struct ucred *ucred = NULL;
4bff0a
+        struct timeval *tv = NULL;
4bff0a
+
4bff0a
+        if (size == 0)
4bff0a
+                return 0;
4bff0a
+
4bff0a
+        assert_se(sd_event_default(&s.event) >= 0);
4bff0a
+        s.syslog_fd = s.native_fd = s.stdout_fd = s.dev_kmsg_fd = s.audit_fd = s.hostname_fd = s.notify_fd = -1;
4bff0a
+        s.buffer = memdup_suffix0(data, size);
4bff0a
+        assert_se(s.buffer);
4bff0a
+        s.buffer_size = size + 1;
4bff0a
+        s.storage = STORAGE_NONE;
4bff0a
+        server_process_syslog_message(&s, s.buffer, size, ucred, tv, label, label_len);
4bff0a
+        server_done(&s);
4bff0a
+
4bff0a
+        return 0;
4bff0a
+}
4bff0a
diff --git a/src/fuzz/meson.build b/src/fuzz/meson.build
4bff0a
index ad44778889..28770b68b8 100644
4bff0a
--- a/src/fuzz/meson.build
4bff0a
+++ b/src/fuzz/meson.build
4bff0a
@@ -19,6 +19,11 @@ fuzzers += [
4bff0a
           libshared],
4bff0a
          [libmount]],
4bff0a
 
4bff0a
+        [['src/fuzz/fuzz-journald-syslog.c'],
4bff0a
+         [libjournal_core,
4bff0a
+          libshared],
4bff0a
+         [libselinux]],
4bff0a
+
4bff0a
         [['src/fuzz/fuzz-journal-remote.c'],
4bff0a
          [libsystemd_journal_remote,
4bff0a
           libshared],