teknoraver / rpms / systemd

Forked from rpms/systemd 3 months ago
Clone

Blame SOURCES/0252-tests-put-fuzz_journald_processing_function-in-a-.c-.patch

4fbe94
From 18a45cf91dbdd075fb55d752f959e84d36f3ab3b Mon Sep 17 00:00:00 2001
4fbe94
From: Evgeny Vereshchagin <evvers@ya.ru>
4fbe94
Date: Fri, 7 Sep 2018 06:13:17 +0000
4fbe94
Subject: [PATCH] tests: put fuzz_journald_processing_function in a .c file
4fbe94
4fbe94
(cherry picked from commit 231dca5579cfba6175d19eee5347d693893fb5aa)
4fbe94
4fbe94
Resolves: #1764560
4fbe94
---
4fbe94
 src/fuzz/fuzz-journald.c | 30 ++++++++++++++++++++++++++++++
4fbe94
 src/fuzz/fuzz-journald.h | 24 ++----------------------
4fbe94
 src/fuzz/meson.build     |  6 ++++--
4fbe94
 3 files changed, 36 insertions(+), 24 deletions(-)
4fbe94
 create mode 100644 src/fuzz/fuzz-journald.c
4fbe94
4fbe94
diff --git a/src/fuzz/fuzz-journald.c b/src/fuzz/fuzz-journald.c
4fbe94
new file mode 100644
4fbe94
index 0000000000..f271d7f2fe
4fbe94
--- /dev/null
4fbe94
+++ b/src/fuzz/fuzz-journald.c
4fbe94
@@ -0,0 +1,30 @@
4fbe94
+/* SPDX-License-Identifier: LGPL-2.1+ */
4fbe94
+
4fbe94
+#include "alloc-util.h"
4fbe94
+#include "fuzz-journald.h"
4fbe94
+#include "journald-server.h"
4fbe94
+#include "sd-event.h"
4fbe94
+
4fbe94
+void fuzz_journald_processing_function(
4fbe94
+                const uint8_t *data,
4fbe94
+                size_t size,
4fbe94
+                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)
4fbe94
+        ) {
4fbe94
+        Server s = {};
4fbe94
+        char *label = NULL;
4fbe94
+        size_t label_len = 0;
4fbe94
+        struct ucred *ucred = NULL;
4fbe94
+        struct timeval *tv = NULL;
4fbe94
+
4fbe94
+        if (size == 0)
4fbe94
+                return;
4fbe94
+
4fbe94
+        assert_se(sd_event_default(&s.event) >= 0);
4fbe94
+        s.syslog_fd = s.native_fd = s.stdout_fd = s.dev_kmsg_fd = s.audit_fd = s.hostname_fd = s.notify_fd = -1;
4fbe94
+        s.buffer = memdup_suffix0(data, size);
4fbe94
+        assert_se(s.buffer);
4fbe94
+        s.buffer_size = size + 1;
4fbe94
+        s.storage = STORAGE_NONE;
4fbe94
+        (*f)(&s, s.buffer, size, ucred, tv, label, label_len);
4fbe94
+        server_done(&s);
4fbe94
+}
4fbe94
diff --git a/src/fuzz/fuzz-journald.h b/src/fuzz/fuzz-journald.h
4fbe94
index e66ef54c9b..e9d32a74aa 100644
4fbe94
--- a/src/fuzz/fuzz-journald.h
4fbe94
+++ b/src/fuzz/fuzz-journald.h
4fbe94
@@ -1,30 +1,10 @@
4fbe94
 /* SPDX-License-Identifier: LGPL-2.1+ */
4fbe94
 #pragma once
4fbe94
 
4fbe94
-#include "alloc-util.h"
4fbe94
 #include "journald-server.h"
4fbe94
-#include "sd-event.h"
4fbe94
 
4fbe94
-static void fuzz_journald_processing_function(
4fbe94
+void fuzz_journald_processing_function(
4fbe94
                 const uint8_t *data,
4fbe94
                 size_t size,
4fbe94
                 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)
4fbe94
-        ) {
4fbe94
-        Server s = {};
4fbe94
-        char *label = NULL;
4fbe94
-        size_t label_len = 0;
4fbe94
-        struct ucred *ucred = NULL;
4fbe94
-        struct timeval *tv = NULL;
4fbe94
-
4fbe94
-        if (size == 0)
4fbe94
-                return;
4fbe94
-
4fbe94
-        assert_se(sd_event_default(&s.event) >= 0);
4fbe94
-        s.syslog_fd = s.native_fd = s.stdout_fd = s.dev_kmsg_fd = s.audit_fd = s.hostname_fd = s.notify_fd = -1;
4fbe94
-        s.buffer = memdup_suffix0(data, size);
4fbe94
-        assert_se(s.buffer);
4fbe94
-        s.buffer_size = size + 1;
4fbe94
-        s.storage = STORAGE_NONE;
4fbe94
-        (*f)(&s, s.buffer, size, ucred, tv, label, label_len);
4fbe94
-        server_done(&s);
4fbe94
-}
4fbe94
+);
4fbe94
diff --git a/src/fuzz/meson.build b/src/fuzz/meson.build
4fbe94
index 483a952421..1f8631bcc0 100644
4fbe94
--- a/src/fuzz/meson.build
4fbe94
+++ b/src/fuzz/meson.build
4fbe94
@@ -33,12 +33,14 @@ fuzzers += [
4fbe94
           libshared],
4fbe94
          [libmount]],
4fbe94
 
4fbe94
-        [['src/fuzz/fuzz-journald-native.c'],
4fbe94
+        [['src/fuzz/fuzz-journald-native.c',
4fbe94
+          'src/fuzz/fuzz-journald.c'],
4fbe94
          [libjournal_core,
4fbe94
           libshared],
4fbe94
          [libselinux]],
4fbe94
 
4fbe94
-        [['src/fuzz/fuzz-journald-syslog.c'],
4fbe94
+        [['src/fuzz/fuzz-journald-syslog.c',
4fbe94
+          'src/fuzz/fuzz-journald.c'],
4fbe94
          [libjournal_core,
4fbe94
           libshared],
4fbe94
          [libselinux]],