]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
sd-journal: validate monotonic timestamp before returning it
authorLennart Poettering <lennart@poettering.net>
Thu, 19 Jan 2023 19:28:34 +0000 (20:28 +0100)
committerLennart Poettering <lennart@poettering.net>
Sat, 21 Jan 2023 09:46:02 +0000 (10:46 +0100)
src/libsystemd/sd-journal/sd-journal.c

index 035d7ccef8214c0a96aa7f494c49e25bbfe5271e..523e23925de46ad4adcbb573f90c2347266eb4f5 100644 (file)
@@ -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;
 }