]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
sd-journal: verify monotonic timestamp before assigning result
authorYu Watanabe <watanabe.yu+github@gmail.com>
Tue, 30 Apr 2024 18:31:25 +0000 (03:31 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Wed, 1 May 2024 21:34:01 +0000 (06:34 +0900)
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

index 713cdcc0ec6323625fbde916131ba03f473089c5..0aa37260b6b8990b8224490acd72d66fc9cc8155 100644 (file)
@@ -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;
 }