]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
journal: Improve handling of corruption during upwards entry iteration 22442/head
authorDaan De Meyer <daan.j.demeyer@gmail.com>
Mon, 7 Feb 2022 20:19:29 +0000 (20:19 +0000)
committerDaan De Meyer <daan.j.demeyer@gmail.com>
Mon, 7 Feb 2022 20:40:30 +0000 (20:40 +0000)
If we're going upwards in the journal file during entry iteration and we
can't reach the current entry due to corruption, start iterating upwards
from the last reachable entry array. This is equivalent to skipping
all entries in the array that can't be reached anymore.

Fixes #22431

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

index a2226da47bee5869a4cb2900abc0c6bbbdb1b405..ac8ad145eda04e422dd17900f23d263d0ec3d4c4 100644 (file)
@@ -2224,6 +2224,24 @@ static int generic_array_get(
 
         while (a > 0) {
                 r = journal_file_move_to_object(f, OBJECT_ENTRY_ARRAY, a, &o);
+                if (IN_SET(r, -EBADMSG, -EADDRNOTAVAIL)) {
+                        /* If there's corruption and we're going downwards, let's pretend we reached the
+                         * final entry in the entry array chain. */
+
+                        if (direction == DIRECTION_DOWN)
+                                return 0;
+
+                        /* If there's corruption and we're going upwards, move back to the previous entry
+                         * array and start iterating entries from there. */
+
+                        r = bump_entry_array(f, NULL, a, first, DIRECTION_UP, &a);
+                        if (r < 0)
+                                return r;
+
+                        i = UINT64_MAX;
+
+                        break;
+                }
                 if (r < 0)
                         return r;