]>
git.ipfire.org Git - thirdparty/systemd.git/blob - src/fuzz/fuzz-journal-remote.c
1 /* SPDX-License-Identifier: LGPL-2.1+ */
7 #include "sd-journal.h"
13 #include "journal-remote.h"
14 #include "logs-show.h"
15 #include "memfd-util.h"
18 int LLVMFuzzerTestOneInput(const uint8_t *data
, size_t size
) {
19 _cleanup_fclose_
FILE *dev_null
= NULL
;
21 char name
[] = "/tmp/fuzz-journal-remote.XXXXXX.journal";
23 int fdin
; /* will be closed by journal_remote handler after EOF */
24 _cleanup_close_
int fdout
= -1;
32 if (!getenv("SYSTEMD_LOG_LEVEL"))
33 log_set_max_level(LOG_CRIT
);
35 assert_se((fdin
= memfd_new_and_map("fuzz-journal-remote", size
, &mem
)) >= 0);
36 memcpy(mem
, data
, size
);
37 assert_se(munmap(mem
, size
) == 0);
39 fdout
= mkostemps(name
, STRLEN(".journal"), O_CLOEXEC
);
40 assert_se(fdout
>= 0);
44 assert_se(journal_remote_server_init(&s
, name
, JOURNAL_WRITE_SPLIT_NONE
, false, false) >= 0);
46 assert_se(journal_remote_add_source(&s
, fdin
, (char*) "fuzz-data", false) > 0);
49 r
= journal_remote_handle_raw_source(NULL
, fdin
, 0, &s
);
53 journal_remote_server_destroy(&s
);
54 assert_se(close(fdin
) < 0 && errno
== EBADF
); /* Check that the fd is closed already */
58 r
= sd_journal_open_files(&j
, (const char**) STRV_MAKE(name
), 0);
61 if (getenv_bool("SYSTEMD_FUZZ_OUTPUT") <= 0)
62 assert_se(dev_null
= fopen("/dev/null", "we"));
64 for (mode
= 0; mode
< _OUTPUT_MODE_MAX
; mode
++) {
66 log_info("/* %s */", output_mode_to_string(mode
));
67 r
= show_journal(dev_null
?: stdout
, j
, mode
, 0, 0, -1, 0, NULL
);
70 r
= sd_journal_seek_head(j
);