]>
git.proxmox.com Git - systemd.git/blob - src/fuzz/fuzz-journald-stream.c
1 /* SPDX-License-Identifier: LGPL-2.1+ */
3 #include <linux/sockios.h>
9 #include "fuzz-journald.h"
10 #include "journald-stream.h"
12 static int stream_fds
[2] = { -1, -1 };
14 int LLVMFuzzerTestOneInput(const uint8_t *data
, size_t size
) {
19 if (size
== 0 || size
> 65536)
22 if (!getenv("SYSTEMD_LOG_LEVEL"))
23 log_set_max_level(LOG_CRIT
);
25 assert_se(socketpair(AF_UNIX
, SOCK_STREAM
|SOCK_CLOEXEC
|SOCK_NONBLOCK
, 0, stream_fds
) >= 0);
26 dummy_server_init(&s
, NULL
, 0);
27 assert_se(stdout_stream_install(&s
, stream_fds
[0], &stream
) >= 0);
28 assert_se(write(stream_fds
[1], data
, size
) == (ssize_t
) size
);
29 while (ioctl(stream_fds
[0], SIOCINQ
, &v
) == 0 && v
)
30 sd_event_run(s
.event
, (uint64_t) -1);
31 if (s
.n_stdout_streams
)
32 stdout_stream_destroy(stream
);
34 stream_fds
[1] = safe_close(stream_fds
[1]);