journal-file: do not trigger assertion on removed or corrupted journal file

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.
This commit is contained in:
Yu Watanabe
2026-01-18 21:25:20 +09:00
parent 103f7d2303
commit 112cbc3790
+3 -4
View 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)