]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
sd-journal: fix segfault
authorYu Watanabe <watanabe.yu+github@gmail.com>
Wed, 15 Mar 2023 06:12:41 +0000 (15:12 +0900)
committerLuca Boccassi <luca.boccassi@gmail.com>
Thu, 16 Mar 2023 00:26:22 +0000 (00:26 +0000)
Unfortunately, journal_file_next_entry() returns 0 when the next entry
not found. The commit cc938e4a0ab67707e489cc3970a8557ad89801ca adds
FIXME comment about that. We should really fix that, but the function and
its return value are used in many place, hence checking all usecases is not
easy. So, let's workaround that here, and handle the 0 return value by
the caller.

Follow-up for 34af74946e8853411f18120007ebaca6549b2a52.

Fixes #26822.

src/libsystemd/sd-journal/sd-journal.c

index 6804cf4069e7e924b4f3148d94de4bdbd58f1b69..8964140f7ae8f3d26852a4d95d0fa29afcfc8dc6 100644 (file)
@@ -2436,6 +2436,8 @@ static int journal_file_read_tail_timestamp(sd_journal *j, JournalFile *f) {
                         r = journal_file_next_entry(f, 0, DIRECTION_UP, &o, NULL);
                         if (r < 0)
                                 return r;
+                        if (r == 0)
+                                return -ENODATA;
 
                         id = o->entry.boot_id;
                         mo = le64toh(o->entry.monotonic);