diff options
author | Evgeny Vereshchagin <evvers@ya.ru> | 2018-09-03 08:46:24 +0200 |
---|---|---|
committer | Evgeny Vereshchagin <evvers@ya.ru> | 2018-09-03 08:46:24 +0200 |
commit | b1bd453f36b9428b6bf9feba31fa0a2b36143e9c (patch) | |
tree | 33c482fe20e9b5e19120b53975253373da2652ee /src/fuzz | |
parent | importd, basic/string-util: use case-insensitive comparison for HTTP headers (diff) | |
download | systemd-b1bd453f36b9428b6bf9feba31fa0a2b36143e9c.tar.xz systemd-b1bd453f36b9428b6bf9feba31fa0a2b36143e9c.zip |
tests: rework the code fuzzing journald
This should make it easier to add a new fuzzer without a lot of
duplication.
Diffstat (limited to 'src/fuzz')
-rw-r--r-- | src/fuzz/fuzz-journald-syslog.c | 23 | ||||
-rw-r--r-- | src/fuzz/fuzz-journald.h | 30 |
2 files changed, 32 insertions, 21 deletions
diff --git a/src/fuzz/fuzz-journald-syslog.c b/src/fuzz/fuzz-journald-syslog.c index 7730f60875..100f0ce691 100644 --- a/src/fuzz/fuzz-journald-syslog.c +++ b/src/fuzz/fuzz-journald-syslog.c @@ -1,29 +1,10 @@ /* SPDX-License-Identifier: LGPL-2.1+ */ -#include "alloc-util.h" #include "fuzz.h" -#include "journald-server.h" +#include "fuzz-journald.h" #include "journald-syslog.h" -#include "sd-event.h" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) { - Server s = {}; - char *label = NULL; - size_t label_len = 0; - struct ucred *ucred = NULL; - struct timeval *tv = NULL; - - if (size == 0) - return 0; - - 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; - server_process_syslog_message(&s, s.buffer, size, ucred, tv, label, label_len); - server_done(&s); - + fuzz_journald_processing_function(data, size, server_process_syslog_message); return 0; } diff --git a/src/fuzz/fuzz-journald.h b/src/fuzz/fuzz-journald.h new file mode 100644 index 0000000000..e66ef54c9b --- /dev/null +++ b/src/fuzz/fuzz-journald.h @@ -0,0 +1,30 @@ +/* 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( + 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); +} |