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.
This commit is contained in:
Yu Watanabe
2024-05-01 03:31:25 +09:00
parent fbecb1fd8d
commit c9df471428

View 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;
}