From f19f640513cf3ededdf1f5cc6f00efca27efc61f Mon Sep 17 00:00:00 2001 From: Yu Watanabe Date: Sat, 28 Dec 2024 14:09:22 +0900 Subject: [PATCH 1/2] logs-show: skip journal entry with an invalid timestamp Follow-up for 275e6be052e690adcad5d2a557acb9dcb5bedbc6. Fixes oss-fuzz#385221809 (https://issues.oss-fuzz.com/issues/385221809). Fixes #35737. --- src/shared/logs-show.c | 9 +++++---- .../fuzz/fuzz-journal-remote/oss-fuzz-385221809 | Bin 0 -> 10595 bytes 2 files changed, 5 insertions(+), 4 deletions(-) create mode 100644 test/fuzz/fuzz-journal-remote/oss-fuzz-385221809 diff --git a/src/shared/logs-show.c b/src/shared/logs-show.c index 4e7ed0be6fa..41a3a5adc57 100644 --- a/src/shared/logs-show.c +++ b/src/shared/logs-show.c @@ -335,7 +335,7 @@ static int output_timestamp_monotonic( assert(previous_boot_id); if (!VALID_MONOTONIC(display_ts->monotonic)) - return log_error_errno(SYNTHETIC_ERRNO(EINVAL), "No valid monotonic timestamp available"); + return log_debug_errno(SYNTHETIC_ERRNO(EINVAL), "No valid monotonic timestamp available, skipping showing journal entry."); written_chars += fprintf(f, "[%5"PRI_USEC".%06"PRI_USEC, display_ts->monotonic / USEC_PER_SEC, display_ts->monotonic % USEC_PER_SEC); @@ -375,15 +375,14 @@ static int output_timestamp_realtime( assert(j); if (!VALID_REALTIME(usec)) - return log_error_errno(SYNTHETIC_ERRNO(EINVAL), "No valid realtime timestamp available."); + return log_debug_errno(SYNTHETIC_ERRNO(EINVAL), "No valid realtime timestamp available, skipping showing journal entry."); switch (mode) { case OUTPUT_SHORT_FULL: case OUTPUT_WITH_UNIT: { if (!format_timestamp_style(buf, sizeof(buf), usec, flags & OUTPUT_UTC ? TIMESTAMP_UTC : TIMESTAMP_PRETTY)) - return log_error_errno(SYNTHETIC_ERRNO(EINVAL), - "Failed to format timestamp: %" PRIu64, usec); + return log_debug_errno(SYNTHETIC_ERRNO(EINVAL), "Failed to format timestamp (%"PRIu64"), skipping showing journal entry.", usec); break; } @@ -623,6 +622,8 @@ static int output_short( parse_display_realtime(j, realtime, monotonic, &usec); r = output_timestamp_realtime(f, j, mode, flags, usec); } + if (r == -EINVAL) + return 0; if (r < 0) return r; n += r; diff --git a/test/fuzz/fuzz-journal-remote/oss-fuzz-385221809 b/test/fuzz/fuzz-journal-remote/oss-fuzz-385221809 new file mode 100644 index 0000000000000000000000000000000000000000..8bb473ac56adb97962da8894c0ca5bf70cd8c437 GIT binary patch literal 10595 zcmeI2KTg9i6o)hW0G#8+P8@rPP$?0rM4PG&NT5mN{xcfY1HcnDtV2gPJigzU=tOoXy^k`M`0ML-mxDG zE*LNhQg9cfypChfmEwjv%!{w2O^ANfI6ND5gQB90=LzS85e zR|3d7_rttymM+jmuHvY`ODkN-2`kmk%oMpF6gg_<-ba?t$0$RQoH>=uqiM?m2XMx++)8$WUI|m{=Z`XIqxK+D0mcy4WlqZ${2Q On~$^UbE+yXT*xm`B8HU! literal 0 HcmV?d00001 From 27c992dd9fa7f69779adc85607523a1e52296af0 Mon Sep 17 00:00:00 2001 From: Yu Watanabe Date: Sat, 28 Dec 2024 14:17:47 +0900 Subject: [PATCH 2/2] fuzz-journal-remote: use ASSERT_OK() and friends --- src/journal-remote/fuzz-journal-remote.c | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/src/journal-remote/fuzz-journal-remote.c b/src/journal-remote/fuzz-journal-remote.c index 3e874f19b71..3c44945cd45 100644 --- a/src/journal-remote/fuzz-journal-remote.c +++ b/src/journal-remote/fuzz-journal-remote.c @@ -16,6 +16,7 @@ #include "path-util.h" #include "rm-rf.h" #include "strv.h" +#include "tests.h" #include "tmpfile-util.h" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) { @@ -50,14 +51,11 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) { return r; } - r = journal_remote_add_source(&s, fdin, (char*) "fuzz-data", false); - if (r < 0) - return r; + ASSERT_OK_POSITIVE(journal_remote_add_source(&s, fdin, (char*) "fuzz-data", false)); TAKE_FD(fdin_close); - assert(r > 0); while (s.active) - assert_se(journal_remote_handle_raw_source(NULL, fdin, 0, &s) >= 0); + ASSERT_OK(journal_remote_handle_raw_source(NULL, fdin, 0, &s)); assert_se(close(fdin) < 0 && errno == EBADF); /* Check that the fd is closed already */ @@ -80,11 +78,8 @@ int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) { for (OutputMode mode = 0; mode < _OUTPUT_MODE_MAX; mode++) { 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); - assert_se(r >= 0); + ASSERT_OK(show_journal(dev_null ?: stdout, j, mode, 0, 0, -1, 0, NULL)); + ASSERT_OK(sd_journal_seek_head(j)); } return 0;