From 6dbef3053dcb11a58ead99bee0790ad1f4c40522 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Mon, 21 May 2018 14:42:42 +0200 Subject: [PATCH] fuzz-journal-remote: write to /dev/null not stdout This makes the fuzzing much more efficient. Optionally provide output is $SYSTEMD_FUZZ_OUTPUT is set, which makes debugging of any failures much easier. The case from 056129deb73df17ece4212db39d2ca0842d9a49c is still detected properly. --- src/fuzz/fuzz-journal-remote.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/fuzz/fuzz-journal-remote.c b/src/fuzz/fuzz-journal-remote.c index 915e88c283d..432c687bc08 100644 --- a/src/fuzz/fuzz-journal-remote.c +++ b/src/fuzz/fuzz-journal-remote.c @@ -6,6 +6,7 @@ #include "sd-journal.h" +#include "env-util.h" #include "fd-util.h" #include "fileio.h" #include "fs-util.h" @@ -15,6 +16,7 @@ #include "strv.h" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) { + _cleanup_fclose_ FILE *dev_null = NULL; RemoteServer s = {}; char name[] = "/tmp/fuzz-journal-remote.XXXXXX.journal"; void *mem; @@ -53,8 +55,13 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) { r = sd_journal_open_files(&j, (const char**) STRV_MAKE(name), 0); assert_se(r >= 0); + if (getenv_bool("SYSTEMD_FUZZ_OUTPUT") <= 0) + assert_se(dev_null = fopen("/dev/null", "we")); + for (mode = 0; mode < _OUTPUT_MODE_MAX; mode++) { - r = show_journal(stdout, j, mode, 0, 0, -1, 0, NULL); + if (!dev_null) + log_info("/* %s */", output_mode_to_string(mode)); + r = show_journal(dev_null ?: stdout, j, mode, 0, 0, -1, 0, NULL); assert_se(r >= 0); r = sd_journal_seek_head(j); -- 2.47.3