mirror of
https://github.com/systemd/systemd.git
synced 2024-11-02 02:21:44 +03:00
Merge pull request #10847 from evverx/journald-stream-fuzzer
tests: add a fuzzer for journald streams
This commit is contained in:
commit
278939be7a
35
src/fuzz/fuzz-journald-stream.c
Normal file
35
src/fuzz/fuzz-journald-stream.c
Normal 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;
|
||||
}
|
@ -15,12 +15,16 @@ 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);
|
||||
|
||||
if (buffer) {
|
||||
s->buffer = memdup_suffix0(buffer, size);
|
||||
assert_se(s->buffer);
|
||||
s->buffer_size = size + 1;
|
||||
}
|
||||
}
|
||||
|
||||
void fuzz_journald_processing_function(
|
||||
const uint8_t *data,
|
||||
|
@ -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,
|
||||
|
@ -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;
|
||||
|
@ -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);
|
||||
|
8
test/fuzz/fuzz-journald-stream/basic
Normal file
8
test/fuzz/fuzz-journald-stream/basic
Normal file
@ -0,0 +1,8 @@
|
||||
|
||||
|
||||
6
|
||||
1
|
||||
0
|
||||
0
|
||||
0
|
||||
hey
|
Loading…
Reference in New Issue
Block a user