summaryrefslogtreecommitdiffstats
path: root/src/journal/fuzz-journald-stream.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/journal/fuzz-journald-stream.c')
-rw-r--r--src/journal/fuzz-journald-stream.c24
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;
}