diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-06-12 03:50:40 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-06-12 03:50:40 +0000 |
commit | fc53809803cd2bc2434e312b19a18fa36776da12 (patch) | |
tree | b4b43bd6538f51965ce32856e9c053d0f90919c8 /src/journal/fuzz-journald-stream.c | |
parent | Adding upstream version 255.5. (diff) | |
download | systemd-fc53809803cd2bc2434e312b19a18fa36776da12.tar.xz systemd-fc53809803cd2bc2434e312b19a18fa36776da12.zip |
Adding upstream version 256.upstream/256
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/journal/fuzz-journald-stream.c')
-rw-r--r-- | src/journal/fuzz-journald-stream.c | 24 |
1 files changed, 13 insertions, 11 deletions
diff --git a/src/journal/fuzz-journald-stream.c b/src/journal/fuzz-journald-stream.c index 6b2055f..3ad9e20 100644 --- a/src/journal/fuzz-journald-stream.c +++ b/src/journal/fuzz-journald-stream.c @@ -9,12 +9,11 @@ #include "fuzz-journald.h" #include "journald-stream.h" -static int stream_fds[2] = EBADF_PAIR; - int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) { - Server s; + _cleanup_close_pair_ int stream_fds[2] = EBADF_PAIR; + _cleanup_(server_freep) Server *s = NULL; StdoutStream *stream; - int v; + int v, fd0; if (outside_size_range(size, 1, 65536)) return 0; @@ -22,15 +21,18 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) { fuzz_setup_logging(); 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(server_new(&s) >= 0); + dummy_server_init(s, NULL, 0); + + assert_se(stdout_stream_install(s, stream_fds[0], &stream) >= 0); + fd0 = TAKE_FD(stream_fds[0]); /* avoid double close */ + 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_MAX); - if (s.n_stdout_streams) + while (ioctl(fd0, SIOCINQ, &v) == 0 && v) + sd_event_run(s->event, UINT64_MAX); + + if (s->n_stdout_streams > 0) stdout_stream_destroy(stream); - server_done(&s); - stream_fds[1] = safe_close(stream_fds[1]); return 0; } |