dryang / rpms / systemd

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