daandemeyer / rpms / systemd

Forked from rpms/systemd 2 years ago
Clone
Blob Blame History Raw
From 18a45cf91dbdd075fb55d752f959e84d36f3ab3b Mon Sep 17 00:00:00 2001
From: Evgeny Vereshchagin <evvers@ya.ru>
Date: Fri, 7 Sep 2018 06:13:17 +0000
Subject: [PATCH] tests: put fuzz_journald_processing_function in a .c file

(cherry picked from commit 231dca5579cfba6175d19eee5347d693893fb5aa)

Resolves: #1764560
---
 src/fuzz/fuzz-journald.c | 30 ++++++++++++++++++++++++++++++
 src/fuzz/fuzz-journald.h | 24 ++----------------------
 src/fuzz/meson.build     |  6 ++++--
 3 files changed, 36 insertions(+), 24 deletions(-)
 create mode 100644 src/fuzz/fuzz-journald.c

diff --git a/src/fuzz/fuzz-journald.c b/src/fuzz/fuzz-journald.c
new file mode 100644
index 0000000000..f271d7f2fe
--- /dev/null
+++ b/src/fuzz/fuzz-journald.c
@@ -0,0 +1,30 @@
+/* SPDX-License-Identifier: LGPL-2.1+ */
+
+#include "alloc-util.h"
+#include "fuzz-journald.h"
+#include "journald-server.h"
+#include "sd-event.h"
+
+void fuzz_journald_processing_function(
+                const uint8_t *data,
+                size_t size,
+                void (*f)(Server *s, const char *buf, size_t raw_len, const struct ucred *ucred, const struct timeval *tv, const char *label, size_t label_len)
+        ) {
+        Server s = {};
+        char *label = NULL;
+        size_t label_len = 0;
+        struct ucred *ucred = NULL;
+        struct timeval *tv = NULL;
+
+        if (size == 0)
+                return;
+
+        assert_se(sd_event_default(&s.event) >= 0);
+        s.syslog_fd = s.native_fd = s.stdout_fd = s.dev_kmsg_fd = s.audit_fd = s.hostname_fd = s.notify_fd = -1;
+        s.buffer = memdup_suffix0(data, size);
+        assert_se(s.buffer);
+        s.buffer_size = size + 1;
+        s.storage = STORAGE_NONE;
+        (*f)(&s, s.buffer, size, ucred, tv, label, label_len);
+        server_done(&s);
+}
diff --git a/src/fuzz/fuzz-journald.h b/src/fuzz/fuzz-journald.h
index e66ef54c9b..e9d32a74aa 100644
--- a/src/fuzz/fuzz-journald.h
+++ b/src/fuzz/fuzz-journald.h
@@ -1,30 +1,10 @@
 /* SPDX-License-Identifier: LGPL-2.1+ */
 #pragma once
 
-#include "alloc-util.h"
 #include "journald-server.h"
-#include "sd-event.h"
 
-static void fuzz_journald_processing_function(
+void fuzz_journald_processing_function(
                 const uint8_t *data,
                 size_t size,
                 void (*f)(Server *s, const char *buf, size_t raw_len, const struct ucred *ucred, const struct timeval *tv, const char *label, size_t label_len)
-        ) {
-        Server s = {};
-        char *label = NULL;
-        size_t label_len = 0;
-        struct ucred *ucred = NULL;
-        struct timeval *tv = NULL;
-
-        if (size == 0)
-                return;
-
-        assert_se(sd_event_default(&s.event) >= 0);
-        s.syslog_fd = s.native_fd = s.stdout_fd = s.dev_kmsg_fd = s.audit_fd = s.hostname_fd = s.notify_fd = -1;
-        s.buffer = memdup_suffix0(data, size);
-        assert_se(s.buffer);
-        s.buffer_size = size + 1;
-        s.storage = STORAGE_NONE;
-        (*f)(&s, s.buffer, size, ucred, tv, label, label_len);
-        server_done(&s);
-}
+);
diff --git a/src/fuzz/meson.build b/src/fuzz/meson.build
index 483a952421..1f8631bcc0 100644
--- a/src/fuzz/meson.build
+++ b/src/fuzz/meson.build
@@ -33,12 +33,14 @@ fuzzers += [
           libshared],
          [libmount]],
 
-        [['src/fuzz/fuzz-journald-native.c'],
+        [['src/fuzz/fuzz-journald-native.c',
+          'src/fuzz/fuzz-journald.c'],
          [libjournal_core,
           libshared],
          [libselinux]],
 
-        [['src/fuzz/fuzz-journald-syslog.c'],
+        [['src/fuzz/fuzz-journald-syslog.c',
+          'src/fuzz/fuzz-journald.c'],
          [libjournal_core,
           libshared],
          [libselinux]],