teknoraver / rpms / systemd

Forked from rpms/systemd 3 months ago
Clone

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

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