|
|
ddca0b |
From b276c85200786add6c86b6c1fedc888c71ffe5db Mon Sep 17 00:00:00 2001
|
|
|
ddca0b |
From: Evgeny Vereshchagin <evvers@ya.ru>
|
|
|
ddca0b |
Date: Sat, 17 Nov 2018 13:01:09 +0100
|
|
|
ddca0b |
Subject: [PATCH] tests: introduce dummy_server_init and use it in all journald
|
|
|
ddca0b |
fuzzers
|
|
|
ddca0b |
|
|
|
ddca0b |
(cherry picked from commit ed62712dc6fb236845c489a7f386c7aff0ec31d6)
|
|
|
ddca0b |
|
|
|
ddca0b |
Resolves: #1764560
|
|
|
ddca0b |
---
|
|
|
ddca0b |
src/fuzz/fuzz-journald-audit.c | 18 +++---------------
|
|
|
ddca0b |
src/fuzz/fuzz-journald-kmsg.c | 20 ++++----------------
|
|
|
ddca0b |
src/fuzz/fuzz-journald.c | 26 +++++++++++++++++++-------
|
|
|
ddca0b |
src/fuzz/fuzz-journald.h | 2 ++
|
|
|
ddca0b |
src/fuzz/meson.build | 6 ++++--
|
|
|
ddca0b |
5 files changed, 32 insertions(+), 40 deletions(-)
|
|
|
ddca0b |
|
|
|
ddca0b |
diff --git a/src/fuzz/fuzz-journald-audit.c b/src/fuzz/fuzz-journald-audit.c
|
|
|
ddca0b |
index fe401c0d98..3f3ce7e8ee 100644
|
|
|
ddca0b |
--- a/src/fuzz/fuzz-journald-audit.c
|
|
|
ddca0b |
+++ b/src/fuzz/fuzz-journald-audit.c
|
|
|
ddca0b |
@@ -1,26 +1,14 @@
|
|
|
ddca0b |
/* SPDX-License-Identifier: LGPL-2.1+ */
|
|
|
ddca0b |
|
|
|
ddca0b |
#include "fuzz.h"
|
|
|
ddca0b |
+#include "fuzz-journald.h"
|
|
|
ddca0b |
#include "journald-audit.h"
|
|
|
ddca0b |
|
|
|
ddca0b |
int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
|
|
|
ddca0b |
Server s;
|
|
|
ddca0b |
- _cleanup_free_ char *buffer = NULL;
|
|
|
ddca0b |
|
|
|
ddca0b |
- s = (Server) {
|
|
|
ddca0b |
- .syslog_fd = -1,
|
|
|
ddca0b |
- .native_fd = -1,
|
|
|
ddca0b |
- .stdout_fd = -1,
|
|
|
ddca0b |
- .dev_kmsg_fd = -1,
|
|
|
ddca0b |
- .audit_fd = -1,
|
|
|
ddca0b |
- .hostname_fd = -1,
|
|
|
ddca0b |
- .notify_fd = -1,
|
|
|
ddca0b |
- .storage = STORAGE_NONE,
|
|
|
ddca0b |
- };
|
|
|
ddca0b |
- assert_se(sd_event_default(&s.event) >= 0);
|
|
|
ddca0b |
- buffer = memdup_suffix0(data, size);
|
|
|
ddca0b |
- assert_se(buffer);
|
|
|
ddca0b |
- process_audit_string(&s, 0, buffer, size);
|
|
|
ddca0b |
+ dummy_server_init(&s, data, size);
|
|
|
ddca0b |
+ process_audit_string(&s, 0, s.buffer, size);
|
|
|
ddca0b |
server_done(&s);
|
|
|
ddca0b |
|
|
|
ddca0b |
return 0;
|
|
|
ddca0b |
diff --git a/src/fuzz/fuzz-journald-kmsg.c b/src/fuzz/fuzz-journald-kmsg.c
|
|
|
ddca0b |
index e2611c6d45..f7426c8400 100644
|
|
|
ddca0b |
--- a/src/fuzz/fuzz-journald-kmsg.c
|
|
|
ddca0b |
+++ b/src/fuzz/fuzz-journald-kmsg.c
|
|
|
ddca0b |
@@ -1,29 +1,17 @@
|
|
|
ddca0b |
/* SPDX-License-Identifier: LGPL-2.1+ */
|
|
|
ddca0b |
|
|
|
ddca0b |
#include "fuzz.h"
|
|
|
ddca0b |
+#include "fuzz-journald.h"
|
|
|
ddca0b |
#include "journald-kmsg.h"
|
|
|
ddca0b |
|
|
|
ddca0b |
int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
|
|
|
ddca0b |
- Server s = {};
|
|
|
ddca0b |
- _cleanup_free_ char *buffer = NULL;
|
|
|
ddca0b |
+ Server s;
|
|
|
ddca0b |
|
|
|
ddca0b |
if (size == 0)
|
|
|
ddca0b |
return 0;
|
|
|
ddca0b |
|
|
|
ddca0b |
- s = (Server) {
|
|
|
ddca0b |
- .syslog_fd = -1,
|
|
|
ddca0b |
- .native_fd = -1,
|
|
|
ddca0b |
- .stdout_fd = -1,
|
|
|
ddca0b |
- .dev_kmsg_fd = -1,
|
|
|
ddca0b |
- .audit_fd = -1,
|
|
|
ddca0b |
- .hostname_fd = -1,
|
|
|
ddca0b |
- .notify_fd = -1,
|
|
|
ddca0b |
- .storage = STORAGE_NONE,
|
|
|
ddca0b |
- };
|
|
|
ddca0b |
- assert_se(sd_event_default(&s.event) >= 0);
|
|
|
ddca0b |
- buffer = memdup(data, size);
|
|
|
ddca0b |
- assert_se(buffer);
|
|
|
ddca0b |
- dev_kmsg_record(&s, buffer, size);
|
|
|
ddca0b |
+ dummy_server_init(&s, data, size);
|
|
|
ddca0b |
+ dev_kmsg_record(&s, s.buffer, size);
|
|
|
ddca0b |
server_done(&s);
|
|
|
ddca0b |
|
|
|
ddca0b |
return 0;
|
|
|
ddca0b |
diff --git a/src/fuzz/fuzz-journald.c b/src/fuzz/fuzz-journald.c
|
|
|
ddca0b |
index f271d7f2fe..0659b92ba3 100644
|
|
|
ddca0b |
--- a/src/fuzz/fuzz-journald.c
|
|
|
ddca0b |
+++ b/src/fuzz/fuzz-journald.c
|
|
|
ddca0b |
@@ -5,12 +5,29 @@
|
|
|
ddca0b |
#include "journald-server.h"
|
|
|
ddca0b |
#include "sd-event.h"
|
|
|
ddca0b |
|
|
|
ddca0b |
+void dummy_server_init(Server *s, const uint8_t *buffer, size_t size) {
|
|
|
ddca0b |
+ *s = (Server) {
|
|
|
ddca0b |
+ .syslog_fd = -1,
|
|
|
ddca0b |
+ .native_fd = -1,
|
|
|
ddca0b |
+ .stdout_fd = -1,
|
|
|
ddca0b |
+ .dev_kmsg_fd = -1,
|
|
|
ddca0b |
+ .audit_fd = -1,
|
|
|
ddca0b |
+ .hostname_fd = -1,
|
|
|
ddca0b |
+ .notify_fd = -1,
|
|
|
ddca0b |
+ .storage = STORAGE_NONE,
|
|
|
ddca0b |
+ };
|
|
|
ddca0b |
+ assert_se(sd_event_default(&s->event) >= 0);
|
|
|
ddca0b |
+ s->buffer = memdup_suffix0(buffer, size);
|
|
|
ddca0b |
+ assert_se(s->buffer);
|
|
|
ddca0b |
+ s->buffer_size = size + 1;
|
|
|
ddca0b |
+}
|
|
|
ddca0b |
+
|
|
|
ddca0b |
void fuzz_journald_processing_function(
|
|
|
ddca0b |
const uint8_t *data,
|
|
|
ddca0b |
size_t size,
|
|
|
ddca0b |
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)
|
|
|
ddca0b |
) {
|
|
|
ddca0b |
- Server s = {};
|
|
|
ddca0b |
+ Server s;
|
|
|
ddca0b |
char *label = NULL;
|
|
|
ddca0b |
size_t label_len = 0;
|
|
|
ddca0b |
struct ucred *ucred = NULL;
|
|
|
ddca0b |
@@ -19,12 +36,7 @@ void fuzz_journald_processing_function(
|
|
|
ddca0b |
if (size == 0)
|
|
|
ddca0b |
return;
|
|
|
ddca0b |
|
|
|
ddca0b |
- assert_se(sd_event_default(&s.event) >= 0);
|
|
|
ddca0b |
- s.syslog_fd = s.native_fd = s.stdout_fd = s.dev_kmsg_fd = s.audit_fd = s.hostname_fd = s.notify_fd = -1;
|
|
|
ddca0b |
- s.buffer = memdup_suffix0(data, size);
|
|
|
ddca0b |
- assert_se(s.buffer);
|
|
|
ddca0b |
- s.buffer_size = size + 1;
|
|
|
ddca0b |
- s.storage = STORAGE_NONE;
|
|
|
ddca0b |
+ dummy_server_init(&s, data, size);
|
|
|
ddca0b |
(*f)(&s, s.buffer, size, ucred, tv, label, label_len);
|
|
|
ddca0b |
server_done(&s);
|
|
|
ddca0b |
}
|
|
|
ddca0b |
diff --git a/src/fuzz/fuzz-journald.h b/src/fuzz/fuzz-journald.h
|
|
|
ddca0b |
index e9d32a74aa..77e3b0c064 100644
|
|
|
ddca0b |
--- a/src/fuzz/fuzz-journald.h
|
|
|
ddca0b |
+++ b/src/fuzz/fuzz-journald.h
|
|
|
ddca0b |
@@ -3,6 +3,8 @@
|
|
|
ddca0b |
|
|
|
ddca0b |
#include "journald-server.h"
|
|
|
ddca0b |
|
|
|
ddca0b |
+void dummy_server_init(Server *s, const uint8_t *buffer, size_t size);
|
|
|
ddca0b |
+
|
|
|
ddca0b |
void fuzz_journald_processing_function(
|
|
|
ddca0b |
const uint8_t *data,
|
|
|
ddca0b |
size_t size,
|
|
|
ddca0b |
diff --git a/src/fuzz/meson.build b/src/fuzz/meson.build
|
|
|
ddca0b |
index 5548da3822..897c02e4ae 100644
|
|
|
ddca0b |
--- a/src/fuzz/meson.build
|
|
|
ddca0b |
+++ b/src/fuzz/meson.build
|
|
|
ddca0b |
@@ -33,12 +33,14 @@ fuzzers += [
|
|
|
ddca0b |
libshared],
|
|
|
ddca0b |
[libmount]],
|
|
|
ddca0b |
|
|
|
ddca0b |
- [['src/fuzz/fuzz-journald-audit.c'],
|
|
|
ddca0b |
+ [['src/fuzz/fuzz-journald-audit.c',
|
|
|
ddca0b |
+ 'src/fuzz/fuzz-journald.c'],
|
|
|
ddca0b |
[libjournal_core,
|
|
|
ddca0b |
libshared],
|
|
|
ddca0b |
[libselinux]],
|
|
|
ddca0b |
|
|
|
ddca0b |
- [['src/fuzz/fuzz-journald-kmsg.c'],
|
|
|
ddca0b |
+ [['src/fuzz/fuzz-journald-kmsg.c',
|
|
|
ddca0b |
+ 'src/fuzz/fuzz-journald.c'],
|
|
|
ddca0b |
[libjournal_core,
|
|
|
ddca0b |
libshared],
|
|
|
ddca0b |
[libselinux]],
|