From: Lennart Poettering Date: Thu, 19 Jan 2023 19:28:34 +0000 (+0100) Subject: sd-journal: validate monotonic timestamp before returning it X-Git-Tag: v253-rc1~43 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=404803e6caad2de2d8e74caab0b79ec3f030f801;p=thirdparty%2Fsystemd.git sd-journal: validate monotonic timestamp before returning it --- diff --git a/src/libsystemd/sd-journal/sd-journal.c b/src/libsystemd/sd-journal/sd-journal.c index 035d7ccef82..523e23925de 100644 --- a/src/libsystemd/sd-journal/sd-journal.c +++ b/src/libsystemd/sd-journal/sd-journal.c @@ -2190,8 +2190,8 @@ _public_ int sd_journal_get_realtime_usec(sd_journal *j, uint64_t *ret) { } _public_ int sd_journal_get_monotonic_usec(sd_journal *j, uint64_t *ret, sd_id128_t *ret_boot_id) { - Object *o; JournalFile *f; + Object *o; int r; assert_return(j, -EINVAL); @@ -2200,7 +2200,6 @@ _public_ int sd_journal_get_monotonic_usec(sd_journal *j, uint64_t *ret, sd_id12 f = j->current_file; if (!f) return -EADDRNOTAVAIL; - if (f->current_offset <= 0) return -EADDRNOTAVAIL; @@ -2221,8 +2220,12 @@ _public_ int sd_journal_get_monotonic_usec(sd_journal *j, uint64_t *ret, sd_id12 return -ESTALE; } + uint64_t t = le64toh(o->entry.monotonic); + if (!VALID_MONOTONIC(t)) + return -EBADMSG; + if (ret) - *ret = le64toh(o->entry.monotonic); + *ret = t; return 0; }