From 5dca908a9a23247b1428fcfe29e7478575ddf9c4 Mon Sep 17 00:00:00 2001 From: Yu Watanabe Date: Thu, 30 Nov 2023 06:46:21 +0900 Subject: [PATCH] sd-journal: ignore failure in testing cached corrupted entry Let's consider the case that the 1st entry in an array is broken, but n-th entry is valid. Then, if generic_array_get() is called to read n-th object, the offset of the broken entry is cached by the function. If generic_array_bisect() is followed, even if the matching entry is valid, it always fail with -EBADMSG or friends, as the function test the cached entry at the beginnning. Let's ignore the failure in testing the cached entry. --- src/libsystemd/sd-journal/journal-file.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/libsystemd/sd-journal/journal-file.c b/src/libsystemd/sd-journal/journal-file.c index f72498c2e71..e402cb3b26f 100644 --- a/src/libsystemd/sd-journal/journal-file.c +++ b/src/libsystemd/sd-journal/journal-file.c @@ -3006,10 +3006,11 @@ static int generic_array_bisect( * check that first. */ r = test_object(f, ci->begin, needle); - if (r < 0) + if (IN_SET(r, -EBADMSG, -EADDRNOTAVAIL)) + log_debug_errno(r, "Cached entry is corrupted, ignoring: %m"); + else if (r < 0) return r; - - if (r == TEST_LEFT) { + else if (r == TEST_LEFT) { /* OK, what we are looking for is right of the begin of this EntryArray, so let's * jump straight to previously cached array in the chain */ -- 2.47.3