]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
journal-file: do not trigger assertion on removed or corrupted journal file
authorYu Watanabe <watanabe.yu+github@gmail.com>
Sun, 18 Jan 2026 10:15:31 +0000 (19:15 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Sun, 18 Jan 2026 12:25:20 +0000 (21:25 +0900)
When a journal file is removed or corrupted, then the value `p`, which is
read from Object.data.entry_offset, may be zero.

Note, journal_file_move_to_object() checks the passed offset and return
-EBADMSG if it is invalid.

Fixes the issue reported at
https://github.com/systemd/systemd/pull/40372#issuecomment-3762907261.

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

index b3fa41ffbf7f341ab565666f7d575c08b137caa5..8dcd599bbdae4c4ad1c1be5f7426361021644655 100644 (file)
@@ -3318,7 +3318,9 @@ use_extra:
 
 static int test_object_offset(JournalFile *f, uint64_t p, uint64_t needle) {
         assert(f);
-        assert(p > 0);
+
+        if (p <= 0)
+                return -EBADMSG;
 
         if (p == needle)
                 return TEST_FOUND;
@@ -3354,7 +3356,6 @@ static int test_object_seqnum(JournalFile *f, uint64_t p, uint64_t needle) {
         int r;
 
         assert(f);
-        assert(p > 0);
 
         r = journal_file_move_to_object(f, OBJECT_ENTRY, p, &o);
         if (r < 0)
@@ -3395,7 +3396,6 @@ static int test_object_realtime(JournalFile *f, uint64_t p, uint64_t needle) {
         int r;
 
         assert(f);
-        assert(p > 0);
 
         r = journal_file_move_to_object(f, OBJECT_ENTRY, p, &o);
         if (r < 0)
@@ -3436,7 +3436,6 @@ static int test_object_monotonic(JournalFile *f, uint64_t p, uint64_t needle) {
         int r;
 
         assert(f);
-        assert(p > 0);
 
         r = journal_file_move_to_object(f, OBJECT_ENTRY, p, &o);
         if (r < 0)