| 1 |
/* SPDX-License-Identifier: LGPL-2.1-or-later */ |
| 2 |
|
| 3 |
#include <linux/sockios.h> |
| 4 |
#include <sys/ioctl.h> |
| 5 |
#include <unistd.h> |
| 6 |
|
| 7 |
#include "sd-event.h" |
| 8 |
|
| 9 |
#include "fd-util.h" |
| 10 |
#include "fuzz.h" |
| 11 |
#include "fuzz-journald-util.h" |
| 12 |
#include "journald-stream.h" |
| 13 |
|
| 14 |
int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) { |
| 15 |
_cleanup_close_pair_ int stream_fds[2] = EBADF_PAIR; |
| 16 |
_cleanup_(manager_freep) Manager *m = NULL; |
| 17 |
StdoutStream *stream; |
| 18 |
int v, fd0; |
| 19 |
|
| 20 |
if (outside_size_range(size, 1, 65536)) |
| 21 |
return 0; |
| 22 |
|
| 23 |
fuzz_setup_logging(); |
| 24 |
|
| 25 |
assert_se(socketpair(AF_UNIX, SOCK_STREAM|SOCK_CLOEXEC|SOCK_NONBLOCK, 0, stream_fds) >= 0); |
| 26 |
dummy_manager_new(&m, NULL, 0); |
| 27 |
|
| 28 |
assert_se(stdout_stream_install(m, stream_fds[0], &stream) >= 0); |
| 29 |
fd0 = TAKE_FD(stream_fds[0]); /* avoid double close */ |
| 30 |
|
| 31 |
assert_se(write(stream_fds[1], data, size) == (ssize_t) size); |
| 32 |
while (ioctl(fd0, SIOCINQ, &v) == 0 && v) |
| 33 |
sd_event_run(m->event, UINT64_MAX); |
| 34 |
|
| 35 |
if (m->n_stdout_streams > 0) |
| 36 |
stdout_stream_terminate(stream); |
| 37 |
|
| 38 |
return 0; |
| 39 |
} |