1
1
mirror of https://github.com/systemd/systemd-stable.git synced 2024-12-22 13:33:56 +03:00

tests: add a fuzzer for journald streams

This commit is contained in:
Evgeny Vereshchagin 2018-11-20 01:20:32 +01:00
parent 2a44bf5099
commit 9541f5ff5c
6 changed files with 60 additions and 5 deletions

View File

@ -0,0 +1,35 @@
/* SPDX-License-Identifier: LGPL-2.1+ */
#include <linux/sockios.h>
#include "fd-util.h"
#include "fuzz.h"
#include "fuzz-journald.h"
#include "journald-stream.h"
static int stream_fds[2] = { -1, -1 };
int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
Server s;
StdoutStream *stream;
int v;
if (size == 0)
return 0;
if (!getenv("SYSTEMD_LOG_LEVEL"))
log_set_max_level(LOG_CRIT);
assert_se(socketpair(AF_UNIX, SOCK_STREAM|SOCK_CLOEXEC|SOCK_NONBLOCK, 0, stream_fds) >= 0);
dummy_server_init(&s, NULL, 0);
assert_se(stdout_stream_install(&s, stream_fds[0], &stream) >= 0);
assert_se(write(stream_fds[1], data, size) == (ssize_t) size);
while (ioctl(stream_fds[0], SIOCINQ, &v) == 0 && v)
sd_event_run(s.event, (uint64_t) -1);
if (s.n_stdout_streams)
stdout_stream_destroy(stream);
server_done(&s);
stream_fds[1] = safe_close(stream_fds[1]);
return 0;
}

View File

@ -15,11 +15,15 @@ void dummy_server_init(Server *s, const uint8_t *buffer, size_t size) {
.hostname_fd = -1,
.notify_fd = -1,
.storage = STORAGE_NONE,
.line_max = 64,
};
assert_se(sd_event_default(&s->event) >= 0);
s->buffer = memdup_suffix0(buffer, size);
assert_se(s->buffer);
s->buffer_size = size + 1;
if (buffer) {
s->buffer = memdup_suffix0(buffer, size);
assert_se(s->buffer);
s->buffer_size = size + 1;
}
}
void fuzz_journald_processing_function(

View File

@ -69,6 +69,12 @@ fuzzers += [
libshared],
[libselinux]],
[['src/fuzz/fuzz-journald-stream.c',
'src/fuzz/fuzz-journald.c'],
[libjournal_core,
libshared],
[libselinux]],
[['src/fuzz/fuzz-journald-syslog.c',
'src/fuzz/fuzz-journald.c'],
[libjournal_core,

View File

@ -125,7 +125,7 @@ void stdout_stream_free(StdoutStream *s) {
DEFINE_TRIVIAL_CLEANUP_FUNC(StdoutStream*, stdout_stream_free);
static void stdout_stream_destroy(StdoutStream *s) {
void stdout_stream_destroy(StdoutStream *s) {
if (!s)
return;
@ -534,7 +534,7 @@ terminate:
return 0;
}
static int stdout_stream_install(Server *s, int fd, StdoutStream **ret) {
int stdout_stream_install(Server *s, int fd, StdoutStream **ret) {
_cleanup_(stdout_stream_freep) StdoutStream *stream = NULL;
sd_id128_t id;
int r;

View File

@ -10,4 +10,6 @@ int server_open_stdout_socket(Server *s);
int server_restore_streams(Server *s, FDSet *fds);
void stdout_stream_free(StdoutStream *s);
int stdout_stream_install(Server *s, int fd, StdoutStream **ret);
void stdout_stream_destroy(StdoutStream *s);
void stdout_stream_send_notify(StdoutStream *s);

View File

@ -0,0 +1,8 @@
6
1
0
0
0
hey