From c9df4714286223017aff1b2f32f96058d249d8ab Mon Sep 17 00:00:00 2001 From: Yu Watanabe Date: Wed, 1 May 2024 03:31:25 +0900 Subject: [PATCH] sd-journal: verify monotonic timestamp before assigning result Previously, ret_boot_id was assigned even when the function failed due to an invalid monotonic timestamp stored for a journal entry. --- src/libsystemd/sd-journal/sd-journal.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/libsystemd/sd-journal/sd-journal.c b/src/libsystemd/sd-journal/sd-journal.c index 713cdcc0ec6..0aa37260b6b 100644 --- a/src/libsystemd/sd-journal/sd-journal.c +++ b/src/libsystemd/sd-journal/sd-journal.c @@ -2656,9 +2656,7 @@ _public_ int sd_journal_get_monotonic_usec(sd_journal *j, uint64_t *ret, sd_id12 if (r < 0) return r; - if (ret_boot_id) - *ret_boot_id = o->entry.boot_id; - else { + if (!ret_boot_id) { sd_id128_t id; r = sd_id128_get_boot(&id); @@ -2675,6 +2673,8 @@ _public_ int sd_journal_get_monotonic_usec(sd_journal *j, uint64_t *ret, sd_id12 if (ret) *ret = t; + if (ret_boot_id) + *ret_boot_id = o->entry.boot_id; return 0; } -- 2.47.3